Skip to content

Commit

Permalink
ASSET-38 Fix CI
Browse files Browse the repository at this point in the history
Signed-off-by: jormal <[email protected]>
  • Loading branch information
jormal committed Dec 3, 2024
1 parent 01959c6 commit 978aee7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@ jobs:
with:
python-version: "3.12"

- name: Set up requirements for simple test
if: github.event_name == 'pull_request'
run: pip install -e ".[test_simple]"

- name: Test without rpc using test
if: github.event_name == 'pull_request'
run: pytest -l --skip-rpc-using-test --skip-image-test --ignore=tests/additional/test_file.py

- name: Set up requirements
if: github.event_name == 'push'
run: pip install -e ".[test]"

- name: Test with rpc using test
if: github.event_name == 'push'
run: pytest -l
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Specifies the packages for testing the project.
GitPython==3.1.43
pytest==7.4.4
pytest-asyncio==0.23.7
pigar==2.1.6
35 changes: 13 additions & 22 deletions tests/additional/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from copy import deepcopy
from pathlib import Path
from re import search
from subprocess import run, PIPE

import pytest
from git import Repo
from pydantic import HttpUrl
from web3 import Web3, HTTPProvider

Expand Down Expand Up @@ -71,11 +71,18 @@ async def __test_rpc_url(self, network: Network):
pass

@pytest.mark.asyncio
async def test_all_contracts_info_valid(self):
async def test_modified_contracts_info_valid(self):
"""All contracts in asset information are valid."""
for asset in self.__filter_modified_assets():
await gather(*[self.__test_all_contract_info_valid(asset)])

@pytest.mark.all
@pytest.mark.asyncio
async def test_all_contracts_info_valid(self):
"""All contracts in asset information are valid."""
for asset, _ in self.asset_list:
await gather(*[self.__test_all_contract_info_valid(asset)])

async def __test_all_contract_info_valid(self, asset: Asset):
"""Test the validity of the contract information.
Expand Down Expand Up @@ -107,26 +114,10 @@ async def __test_all_contract_info_valid(self, asset: Asset):

def __filter_modified_assets(self) -> list[Asset]:
"""Filter the modified assets."""
# Get recent tag
recent_tag_result = run(
["git", "describe", "--tags", "--abbrev=0", "HEAD^"],
stdout=PIPE,
stderr=PIPE,
text=True,
check=True,
)
recent_tag = recent_tag_result.stdout.strip()
# Get modified files
diff_result = run(
["git", "diff", "--name-only", recent_tag],
stdout=PIPE,
stderr=PIPE,
text=True,
check=True,
)
changed_files = [
file for file in diff_result.stdout.strip().split("\n") if file
]
repo = Repo(".")
# noinspection PyUnresolvedReferences
main_branch = repo.branches["main"]
changed_files = [item.a_path for item in repo.index.diff(main_branch.commit)]
asset_matches = [
search(r"assets/([^/]+)/info.json", file) for file in changed_files
]
Expand Down
21 changes: 15 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ def pytest_addoption(parser: pytest.Parser):
parser.addoption(
"--skip-image-test", action="store_true", help="Skip the image test."
)
parser.addoption(
"--all",
action="store_true",
help="Run all tests.",
)


def pytest_configure(config: pytest.Config):
config.addinivalue_line("markers", "rpc: Skip the RPC connection using test.")
config.addinivalue_line("markers", "image: Skip the image test.")
config.addinivalue_line("markers", "all: Run all tests.")


def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]):
if config.getoption("--skip-rpc-using-test"):
if config.getoption("--all", default=False):
return
else:
skip_not_all = pytest.mark.skip(reason="Skip the test in all.")
skip_rpc = pytest.mark.skip(reason="Skip the RPC connection using test.")
for item in items:
if "rpc" in item.keywords:
item.add_marker(skip_rpc)
if config.getoption("--skip-image-test"):
skip_image = pytest.mark.skip(reason="Skip the image test.")
for item in items:
if "image" in item.keywords:
if "all" in item.keywords:
item.add_marker(skip_not_all)
elif config.getoption("--skip-rpc-using-test") and "rpc" in item.keywords:
item.add_marker(skip_rpc)
elif config.getoption("--skip-image-test") and "image" in item.keywords:
item.add_marker(skip_image)

0 comments on commit 978aee7

Please sign in to comment.