Skip to content

Commit

Permalink
Replaced _artefact_store with getter as much as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiker committed Mar 28, 2024
1 parent 4162c78 commit f22bbbf
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions tests/system_tests/CFortranInterop/test_CFortranInterop.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def test_CFortranInterop(tmp_path):
# '/lib/x86_64-linux-gnu/libgfortran.so.5',
# ]

assert len(config._artefact_store[EXECUTABLES]) == 1
assert len(config.artefact_store[EXECUTABLES]) == 1

# run
command = [str(config._artefact_store[EXECUTABLES][0])]
command = [str(config.artefact_store[EXECUTABLES][0])]
res = subprocess.run(command, capture_output=True)
output = res.stdout.decode()
assert output == ''.join(open(PROJECT_SOURCE / 'expected.exec.txt').readlines())
4 changes: 2 additions & 2 deletions tests/system_tests/CUserHeader/test_CUserHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def test_CUseHeader(tmp_path):

link_exe(config, linker='gcc', flags=['-lgfortran']),

assert len(config._artefact_store[EXECUTABLES]) == 1
assert len(config.artefact_store[EXECUTABLES]) == 1

# run
command = [str(config._artefact_store[EXECUTABLES][0])]
command = [str(config.artefact_store[EXECUTABLES][0])]
res = subprocess.run(command, capture_output=True)
output = res.stdout.decode()
assert output == ''.join(open(PROJECT_SOURCE / 'expected.exec.txt').readlines())
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def test_FortranDependencies(tmp_path):
compile_fortran(config, common_flags=['-c']),
link_exe(config, linker='gcc', flags=['-lgfortran']),

assert len(config._artefact_store[EXECUTABLES]) == 2
assert len(config.artefact_store[EXECUTABLES]) == 2

# run both exes
output = set()
for exe in config._artefact_store[EXECUTABLES]:
for exe in config.artefact_store[EXECUTABLES]:
res = subprocess.run(str(exe), capture_output=True)
output.add(res.stdout.decode())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def test_FortranPreProcess(tmp_path):
# stay
stay_config = build(fab_workspace=tmp_path, fpp_flags=['-P', '-DSHOULD_I_STAY=yes'])

stay_exe = stay_config._artefact_store[EXECUTABLES][0]
stay_exe = stay_config.artefact_store[EXECUTABLES][0]
stay_res = subprocess.run(str(stay_exe), capture_output=True)
assert stay_res.stdout.decode().strip() == 'I should stay'

# go
go_config = build(fab_workspace=tmp_path, fpp_flags=['-P'])

go_exe = go_config._artefact_store[EXECUTABLES][0]
go_exe = go_config.artefact_store[EXECUTABLES][0]
go_res = subprocess.run(str(go_exe), capture_output=True)
assert go_res.stdout.decode().strip() == 'I should go now'
4 changes: 2 additions & 2 deletions tests/system_tests/MinimalC/test_MinimalC.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def test_MinimalC(tmp_path):

link_exe(config, linker='gcc'),

assert len(config._artefact_store[EXECUTABLES]) == 1
assert len(config.artefact_store[EXECUTABLES]) == 1

# run
command = [str(config._artefact_store[EXECUTABLES][0])]
command = [str(config.artefact_store[EXECUTABLES][0])]
res = subprocess.run(command, capture_output=True)
output = res.stdout.decode()
assert output == 'Hello world!'
4 changes: 2 additions & 2 deletions tests/system_tests/MinimalFortran/test_MinimalFortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def test_MinimalFortran(tmp_path):
compile_fortran(config, common_flags=['-c']),
link_exe(config, linker='gcc', flags=['-lgfortran']),

assert len(config._artefact_store[EXECUTABLES]) == 1
assert len(config.artefact_store[EXECUTABLES]) == 1

# run
command = [str(config._artefact_store[EXECUTABLES][0])]
command = [str(config.artefact_store[EXECUTABLES][0])]
res = subprocess.run(command, capture_output=True)
output = res.stdout.decode()
assert output.strip() == 'Hello world!'
4 changes: 2 additions & 2 deletions tests/unit_tests/steps/test_archive_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_for_exes(self):
mock_run_command.assert_has_calls(expected_calls)

# ensure the correct artefacts were created
assert config._artefact_store[OBJECT_ARCHIVES] == {
assert config.artefact_store[OBJECT_ARCHIVES] == {
target: [str(config.build_output / f'{target}.a')] for target in targets}

def test_for_library(self):
Expand All @@ -48,5 +48,5 @@ def test_for_library(self):
'ar', 'cr', str(config.build_output / 'mylib.a'), 'util1.o', 'util2.o'])

# ensure the correct artefacts were created
assert config._artefact_store[OBJECT_ARCHIVES] == {
assert config.artefact_store[OBJECT_ARCHIVES] == {
None: [str(config.build_output / 'mylib.a')]}
4 changes: 2 additions & 2 deletions tests/unit_tests/steps/test_compile_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def content(tmp_path):
config = BuildConfig('proj', multiprocessing=False, fab_workspace=tmp_path)

analysed_file = AnalysedC(fpath=Path(f'{config.source_root}/foo.c'), file_hash=0)
config._artefact_store[BUILD_TREES] = {None: {analysed_file.fpath: analysed_file}}
config.artefact_store[BUILD_TREES] = {None: {analysed_file.fpath: analysed_file}}
expect_hash = 9120682468
return config, analysed_file, expect_hash

Expand Down Expand Up @@ -50,7 +50,7 @@ def test_vanilla(self, content):
values['send_metric'].assert_called_once()

# ensure it created the correct artefact collection
assert config._artefact_store[OBJECT_FILES] == {
assert config.artefact_store[OBJECT_FILES] == {
None: {config.prebuild_folder / f'foo.{expect_hash:x}.o', }
}

Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/steps/test_root_inc_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_vanilla(self):
inc_files = [Path('/foo/source/bar.inc')]

config = BuildConfig('proj')
config._artefact_store['all_source'] = inc_files
config.artefact_store['all_source'] = inc_files

with mock.patch('fab.steps.root_inc_files.shutil') as mock_shutil:
with mock.patch('fab.steps.root_inc_files.Path.mkdir'), \
Expand All @@ -27,7 +27,7 @@ def test_skip_output_folder(self):
# ensure it doesn't try to copy a file in the build output
config = BuildConfig('proj')
inc_files = [Path('/foo/source/bar.inc'), config.build_output / 'fab.inc']
config._artefact_store['all_source'] = inc_files
config.artefact_store['all_source'] = inc_files

with mock.patch('fab.steps.root_inc_files.shutil') as mock_shutil:
with mock.patch('fab.steps.root_inc_files.Path.mkdir'), \
Expand All @@ -41,7 +41,7 @@ def test_name_clash(self):
inc_files = [Path('/foo/source/bar.inc'), Path('/foo/sauce/bar.inc')]

config = BuildConfig('proj')
config._artefact_store['all_source'] = inc_files
config.artefact_store['all_source'] = inc_files

with pytest.raises(FileExistsError):
with mock.patch('fab.steps.root_inc_files.shutil'):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def simple_step(config):
def test_add_cleanup(self):
# ensure the cleanup step is added
with BuildConfig('proj') as config:
assert CLEANUP_COUNT not in config._artefact_store
assert CLEANUP_COUNT not in config.artefact_store
pass
assert CLEANUP_COUNT in config._artefact_store
assert CLEANUP_COUNT in config.artefact_store

0 comments on commit f22bbbf

Please sign in to comment.