Skip to content

Commit d712b05

Browse files
committed
refactor: make coherent lib module for integration testing
1 parent c30fc7f commit d712b05

11 files changed

+65
-65
lines changed

tests_integration/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ A test scenario assigns one test case to every feedstock and runs them in parall
8181
Thus, test cases of different feedstocks can run simultaneously, but the different test cases for the same feedstock
8282
are always run sequentially.
8383

84-
The generation of test scenarios is done in [collect_test_scenarios.py](collect_test_scenarios.py). It is pseudo-random,
84+
The generation of test scenarios is done in [_collect_test_scenarios.py](lib/_collect_test_scenarios.py). It is pseudo-random,
8585
ensuring that faulty interactions between test cases are detected eventually.
8686

8787
In detail, the process of collecting test scenarios is as follows:

tests_integration/lib/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from ._collect_test_scenarios import get_all_test_scenario_ids, get_test_scenario
2+
from ._integration_test_helper import IntegrationTestHelper
3+
from ._run_test_cases import (
4+
close_all_open_pull_requests,
5+
reset_cf_graph,
6+
run_all_prepare_functions,
7+
run_all_validate_functions,
8+
)
9+
from ._setup_repositories import prepare_all_accounts
10+
from ._shared import (
11+
ENV_TEST_SCENARIO_ID,
12+
VIRTUAL_PROXY_HOSTNAME,
13+
VIRTUAL_PROXY_PORT,
14+
get_global_router,
15+
get_transparent_urls,
16+
setup_logging,
17+
)
18+
from ._test_case import TestCase
19+
20+
__all__ = [
21+
"get_all_test_scenario_ids",
22+
"get_test_scenario",
23+
"IntegrationTestHelper",
24+
"close_all_open_pull_requests",
25+
"reset_cf_graph",
26+
"run_all_prepare_functions",
27+
"run_all_validate_functions",
28+
"prepare_all_accounts",
29+
"get_global_router",
30+
"get_transparent_urls",
31+
"setup_logging",
32+
"ENV_TEST_SCENARIO_ID",
33+
"VIRTUAL_PROXY_HOSTNAME",
34+
"VIRTUAL_PROXY_PORT",
35+
"TestCase",
36+
]

tests_integration/collect_test_scenarios.py renamed to tests_integration/lib/_collect_test_scenarios.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import random
33

44
from tests_integration.definitions import TEST_CASE_MAPPING
5-
from tests_integration.lib.shared import ENV_GITHUB_RUN_ID
6-
from tests_integration.lib.test_case import TestCase
5+
6+
from ._shared import ENV_GITHUB_RUN_ID
7+
from ._test_case import TestCase
78

89

910
def get_number_of_test_scenarios() -> int:

tests_integration/lib/integration_test_helper.py renamed to tests_integration/lib/_integration_test_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from conda_forge_tick.utils import (
1212
run_command_hiding_token,
1313
)
14-
from tests_integration.lib.shared import (
14+
15+
from ._shared import (
1516
FEEDSTOCK_SUFFIX,
1617
GitHubAccount,
1718
get_github_token,

tests_integration/step_prepare.py renamed to tests_integration/lib/_run_test_cases.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
"""
2-
After closing all open Pull Requests in the conda-forge staging organization,
3-
runs the prepare() function of all test cases of the current test scenario to prepare the test environment.
4-
5-
Expects the scenario ID to be present in the environment variable named SCENARIO_ID.
6-
"""
7-
81
import logging
92
from pathlib import Path
103

114
from github import Github
125

136
from conda_forge_tick.settings import settings
14-
from tests_integration.lib.integration_test_helper import IntegrationTestHelper
15-
from tests_integration.lib.shared import (
16-
FEEDSTOCK_SUFFIX,
17-
GitHubAccount,
18-
get_github_token,
19-
)
20-
from tests_integration.lib.test_case import TestCase
7+
from tests_integration.lib import IntegrationTestHelper
8+
9+
from ._shared import FEEDSTOCK_SUFFIX, GitHubAccount, get_github_token
10+
from ._test_case import TestCase
2111

2212
LOGGER = logging.getLogger(__name__)
2313

@@ -50,3 +40,10 @@ def run_all_prepare_functions(scenario: dict[str, TestCase]):
5040
for feedstock_name, test_case in scenario.items():
5141
LOGGER.info("Preparing %s...", feedstock_name)
5242
test_case.prepare(test_helper)
43+
44+
45+
def run_all_validate_functions(scenario: dict[str, TestCase]):
46+
test_helper = IntegrationTestHelper()
47+
for feedstock_name, test_case in scenario.items():
48+
LOGGER.info("Validating %s...", feedstock_name)
49+
test_case.validate(test_helper)

tests_integration/setup_repositories.py renamed to tests_integration/lib/_setup_repositories.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
test cases themselves because tests could purposefully rely on the actual bot itself to create repositories.
77
88
However, we do delete unnecessary feedstocks from the bot's user account.
9-
10-
After the repositories are set up, we write a list of all test scenario ids to be run to $GITHUB_OUTPUT.
119
"""
1210

1311
import logging
@@ -19,7 +17,8 @@
1917
from github.Repository import Repository
2018

2119
from tests_integration.definitions import TEST_CASE_MAPPING
22-
from tests_integration.lib.shared import (
20+
21+
from ._shared import (
2322
FEEDSTOCK_SUFFIX,
2423
REGRO_ACCOUNT_REPOS,
2524
GitHubAccount,
@@ -29,10 +28,6 @@
2928

3029
LOGGER = logging.getLogger(__name__)
3130

32-
IGNORE_FEEDSTOCK_NAMES = {
33-
"__pycache__",
34-
}
35-
3631

3732
@dataclass(frozen=True)
3833
class GitHubAccountSetup:

tests_integration/lib/shared.py renamed to tests_integration/lib/_shared.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
import os
33
from enum import StrEnum
4-
from pathlib import Path
54

65
from fastapi import APIRouter
76

@@ -28,20 +27,12 @@ class GitHubAccount(StrEnum):
2827

2928
REGRO_ACCOUNT_REPOS = {"cf-graph-countyfair"}
3029

31-
ENV_GITHUB_OUTPUT = "GITHUB_OUTPUT"
3230
ENV_GITHUB_RUN_ID = "GITHUB_RUN_ID"
3331
"""
3432
Used as a random seed for the integration tests.
3533
"""
3634
ENV_TEST_SCENARIO_ID = "SCENARIO_ID"
3735

38-
GITHUB_OUTPUT_KEY_SCENARIO_IDS = "scenario_ids"
39-
40-
TESTS_INTEGRATION_DIR_NAME = "tests_integration"
41-
DEFINITIONS_DIR_NAME = "definitions"
42-
43-
DEFINITIONS_DIR = Path(__file__).parents[1] / DEFINITIONS_DIR_NAME
44-
4536
FEEDSTOCK_SUFFIX = "-feedstock"
4637

4738

tests_integration/lib/test_case.py renamed to tests_integration/lib/_test_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from fastapi import APIRouter
44

5-
from tests_integration.lib.integration_test_helper import IntegrationTestHelper
5+
from ._integration_test_helper import IntegrationTestHelper
66

77

88
class TestCase(ABC):

tests_integration/mock_server_addon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
from mitmproxy.addons import asgiapp
1717
from mitmproxy.http import HTTPFlow
1818

19-
from tests_integration.collect_test_scenarios import get_test_scenario
20-
from tests_integration.lib.shared import (
19+
from tests_integration.lib import (
2120
ENV_TEST_SCENARIO_ID,
2221
VIRTUAL_PROXY_HOSTNAME,
2322
VIRTUAL_PROXY_PORT,
2423
get_global_router,
24+
get_test_scenario,
2525
get_transparent_urls,
2626
)
2727

tests_integration/step_validate.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)