This repository has been archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_circleci.py
68 lines (48 loc) · 2 KB
/
test_circleci.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from pathlib import Path
import pytest
import yaml
PROJECT_PATH = Path(__file__).parent
PAGES_PATH = PROJECT_PATH / 'pythoncz' / 'pages'
PAGE_BUILDERS_NAMES = sorted(
item.name for item in PAGES_PATH.iterdir()
if item.is_dir() and (PAGES_PATH / item / '__main__.py').is_file()
)
@pytest.fixture
def config():
path = Path(__file__).parent / '.circleci' / 'config.yml'
return yaml.safe_load(path.read_text())
@pytest.mark.parametrize('builder_name', PAGE_BUILDERS_NAMES)
def test_ci_config_runs_all_page_builders(builder_name, config):
job_name = f'build_{builder_name}'
assert job_name in config['jobs']
job = config['jobs'][job_name]
assert job['executor'] == 'python'
assert job['steps'][0] == {'attach_workspace': {'at': '~'}}
assert job['steps'][1] == {'run': f'pipenv run build {builder_name}'}
assert job['steps'][2] == {
'persist_to_workspace': {
'root': '~',
'paths': [f'project/pythoncz/pages/{builder_name}/*_data.json']
}
}
def test_ci_config_workflow_starts_with_install(config):
default_workflow_jobs = config['workflows']['default_workflow']['jobs']
assert default_workflow_jobs[0] == 'install_and_test'
def test_ci_config_workflow_fans_out_to_page_builders(config):
default_workflow_jobs = config['workflows']['default_workflow']['jobs']
builders_jobs = [
{f'build_{builder_name}': {'requires': ['install_and_test']}}
for builder_name in PAGE_BUILDERS_NAMES
]
builders_count = len(PAGE_BUILDERS_NAMES)
assert default_workflow_jobs[1:builders_count + 1] == builders_jobs
def test_ci_config_workflow_fans_into_web_build(config):
default_workflow_jobs = config['workflows']['default_workflow']['jobs']
builders_count = len(PAGE_BUILDERS_NAMES)
builders_job_names = [
f'build_{builder_name}'
for builder_name in PAGE_BUILDERS_NAMES
]
assert default_workflow_jobs[builders_count + 1] == {
'build_web': {'requires': builders_job_names}
}