Skip to content

Conversation

@sgillies
Copy link
Contributor

@sgillies sgillies commented Jan 4, 2022

This fixes the last failing test and improves the test that was failing. I'm going to make some comments inline that point out some defects in the original tests and suggest better patterns that we should use in future work.

cc @jreiberkyle @kevinlacaille @JuLeeAtPlanet @karrabatcheller @mkshah605 @sarasafavi

@sgillies sgillies added the bug label Jan 4, 2022
@sgillies sgillies self-assigned this Jan 4, 2022
'ps4b_basic_analytic_xml_nitf', 'ps4b_udm', 'udm', 'ortho_udm2',
'video_file', 'video_frames', 'video_metadata', 'ortho_visual',
'visual', 'visual_xml'
'analytic', 'visual', 'visual_xml'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like "visual", "analytic" was missing from the list of default asset types. That was the core problem.

@mock.patch('planet.scripts.types.get_asset_types',
new=mock.Mock(return_value=DEFAULT_ASSET_TYPES))
def test_asset_type():
check = convert_asserter(AssetType())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests for v1 of this package very often use assertion helpers like this convert_asserter. It is unnecessary and the tests are easier to read and comprehend without it. Let's not do this in future work.

check('visual*', ['visual', 'visual_xml'])
check('*data_*', ['metadata_aux', 'metadata_txt'])
check('analytic', ['analytic'])
check('analytic,visual', ['analytic', 'visual'])
Copy link
Contributor Author

@sgillies sgillies Jan 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each of these checks should be its own test function. When serialized an early failure can hide later failures from being seen until the tests are run again. And serialization prevents checking in random order, which allows state-dependent bugs to lurk.

("*data_*", ["metadata_aux", "metadata_txt"]),
("analytic", ["analytic"]),
("analytic,visual", ["analytic", "visual"]),
],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest's parametrization is how we turn that one test with N steps into N tests of 1 step.


with pytest.raises(Exception) as e:
AssetType().convert('x', None, None)
assert 'invalid choice: x' in str(e.value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the same reasons, this check should be its own separate test.

@sgillies sgillies marked this pull request as ready for review January 4, 2022 22:05
@sgillies sgillies merged commit c054a7d into master Jan 4, 2022
@sgillies sgillies deleted the test-asset-type-fix branch January 4, 2022 22:06
)
def test_asset_type_convert(pattern, type_list):
"""Patterns are correctly converted to a list of assert types."""
assert sorted(AssetType()(pattern)) == sorted(type_list)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in convert_asserter is replaced by a single line. The assertion is in the body of the test, no need to check elsewhere to see what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants