Skip to content

Commit

Permalink
Fixed testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ddobie committed Aug 23, 2023
1 parent 06ac82c commit d44b48e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 9 deletions.
88 changes: 82 additions & 6 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def load_parquet_side_effect(


@pytest.fixture
def dummy_PipeAnalysis(
def dummy_PipeAnalysis_base(
dummy_pipeline_object: vtp.Pipeline,
mocker: MockerFixture
) -> vtp.PipeAnalysis:
"""
A dummy PipeAnalysis object used in testing.
The base dummy PipeAnalysis object used in testing.
Because the raw pipeline outputs are processed in the load run function
it is easier to test while creating the object each time. It is a little
Expand All @@ -382,10 +382,6 @@ def dummy_PipeAnalysis(
dask_read_parquet_mocker.return_value.compute.return_value = (
dummy_pipeline_measurements()
)
measurement_pairs_existence_mocker = mocker.patch(
'vasttools.pipeline.PipeRun._check_measurement_pairs_file',
return_value=True
)

pipe = dummy_pipeline_object
run_name = 'test_run'
Expand All @@ -394,6 +390,37 @@ def dummy_PipeAnalysis(
return run


@pytest.fixture
def dummy_PipeAnalysis(
dummy_PipeAnalysis_base: vtp.PipeAnalysis,
mocker: MockerFixture
) -> vtp.PipeAnalysis:
"""
The dummy PipeAnalysis object used for most testing.
Because the raw pipeline outputs are processed in the load run function
it is easier to test while creating the object each time. It is a little
inefficient and really the pipeline process should be refactored slightly
to support better testing.
Args:
dummy_PipeAnalysis_base: The base vtp.PipeAnalysis fixture
mocker: The pytest mock mocker object.
Returns:
The vtp.PipeAnalysis instance.
"""

measurement_pairs_existence_mocker = mocker.patch(
'vasttools.pipeline.PipeRun._check_measurement_pairs_file',
return_value=True
)

dummy_PipeAnalysis_base._measurement_pairs_exists = True

return dummy_PipeAnalysis_base


@pytest.fixture
def dummy_PipeAnalysis_wtwoepoch(
dummy_PipeAnalysis: vtp.PipeAnalysis,
Expand Down Expand Up @@ -937,6 +964,55 @@ class TestPipeAnalysis:
the pipeline component.
"""

@pytest.mark.parametrize(
"pairs_existence",
[
[True],
[False],
[True,True],
[False,False],
[True,False],
],
ids=("single-exists",
"single-no-exists",
"multiple-all-exists",
"multiple-no-exists",
"multiple-some-exists",
)
)
def test__check_measurement_pairs_file(self,
pairs_existence: List[bool],
dummy_PipeAnalysis_base: vtp.PipeAnalysis,
mocker: MockerFixture
) -> None:
"""
Tests the _check_measurement_pairs_file method.
Args:
pairs_existence: A list of booleans corresponding to whether a
pairs file exists.
dummy_PipeAnalysis_base: The base dummy PipeAnalysis object.
mocker: The pytest-mock mocker object.
Returns:
None
"""
mocker_isfile = mocker.patch(
"os.path.isfile",
side_effect=pairs_existence
)

fake_pairs_file = [""]*len(pairs_existence)

dummy_PipeAnalysis_base.measurement_pairs_file = fake_pairs_file

returned_val = dummy_PipeAnalysis_base._check_measurement_pairs_file()

all_exist = sum(pairs_existence) == len(pairs_existence)

assert returned_val == all_exist


def test_combine_with_run(
self,
dummy_PipeAnalysis: vtp.PipeAnalysis
Expand Down
6 changes: 3 additions & 3 deletions vasttools/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def _check_measurement_pairs_file(self):

for filepath in self.measurement_pairs_file:
if not os.path.isfile(filepath):
self.logger.warning("Measurement pairs file ({filepath}) does"
" not exist. You will be unable to access"
" measurement pairs or two-epoch metrics."
self.logger.warning(f"Measurement pairs file ({filepath}) does"
f" not exist. You will be unable to access"
f" measurement pairs or two-epoch metrics."
)
measurement_pairs_exists = False

Expand Down

0 comments on commit d44b48e

Please sign in to comment.