-
Notifications
You must be signed in to change notification settings - Fork 99
Adding or updating tests to improve codecov coverage. #7292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
samuel-denton
wants to merge
10
commits into
cylc:master
Choose a base branch
from
samuel-denton:8.6.x_7277_codecov
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e74fe10
Small addition to exceptions tests. (Checking my understanding of cod…
samuel-denton 145e75a
Added new test for get_standardised_point_string
Scott-Owen-James 9a0ddce
Update test_time_parser.py
samuel-denton 569105e
Added comment to test
samuel-denton f1f1cb8
Replace explicit result with calculation for clarity.
samuel-denton d15623b
Improved assert in test
samuel-denton 5ea327f
Referenced a known bug in the relevant methods docstring.
samuel-denton e9de1e9
Improved docstrings on a unit test
samuel-denton ceb6275
Simplified docstring for unit test.
samuel-denton cd5fc81
Simplified a docstring.
samuel-denton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -208,3 +208,109 @@ def test_interval(parsers): | |
| for expression in tests: | ||
| test_data = str(parsers[0].parse_interval(expression)) | ||
| assert test_data == expression | ||
|
|
||
|
|
||
| def test_parse_timepoint_invalid(parsers): | ||
| """It should raise CylcTimeSyntaxError for invalid expressions.""" | ||
| from cylc.flow.exceptions import CylcTimeSyntaxError | ||
|
samuel-denton marked this conversation as resolved.
Outdated
|
||
| with pytest.raises(CylcTimeSyntaxError, match="not a valid"): | ||
| parsers[0].parse_timepoint("not_a_date") | ||
|
|
||
|
|
||
| def test_parse_timepoint_none(parsers): | ||
| """It should raise CylcTimeSyntaxError when expr is None.""" | ||
| from cylc.flow.exceptions import CylcTimeSyntaxError | ||
| with pytest.raises(CylcTimeSyntaxError, match="not a valid"): | ||
| parsers[0].parse_timepoint(None) | ||
|
|
||
|
|
||
| def test_parse_recurrence_invalid(parsers): | ||
| """It should raise CylcTimeSyntaxError for unparsable expressions.""" | ||
| from cylc.flow.exceptions import CylcTimeSyntaxError | ||
| with pytest.raises(CylcTimeSyntaxError, match="Could not parse"): | ||
| parsers[0].parse_recurrence("///") | ||
|
|
||
|
|
||
| def test_parse_recurrence_with_context(parsers): | ||
| """It should use explicit context points when provided.""" | ||
| parser = parsers[0] | ||
| start = parser.parse_timepoint("20000101T00Z") | ||
| end = parser.parse_timepoint("20010101T00Z") | ||
| recurrence = parser.parse_recurrence( | ||
| "R2/P1Y/", | ||
| context_start_point=start, | ||
| context_end_point=end, | ||
| )[0] | ||
| assert str(recurrence) == "R2/P1Y/20010101T0000Z" | ||
|
|
||
|
|
||
| def test_get_interval_from_expression(parsers): | ||
| """It should infer interval from truncated context point.""" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately the function being tested is the cause of a bug: #2382 (comment) We can keep the tests but it would be worth referencing the issue in the docstring |
||
| from unittest.mock import Mock | ||
| from metomi.isodatetime.data import Duration | ||
|
|
||
| parser = parsers[0] | ||
|
|
||
| # when expr is provided, it should just parse it | ||
| assert str(parser._get_interval_from_expression("P1D")) == "P1D" | ||
|
|
||
| # when expr is None and context is None, return None | ||
| assert parser._get_interval_from_expression(None, None) is None | ||
|
|
||
| # when expr is None and context is not truncated, return None | ||
| context = Mock(truncated=False) | ||
| assert parser._get_interval_from_expression(None, context) is None | ||
|
|
||
| # test each truncated property name | ||
| cases = [ | ||
| ("year_of_century", Duration(years=100)), | ||
| ("year_of_decade", Duration(years=10)), | ||
| ("month_of_year", Duration(years=1)), | ||
| ("week_of_year", Duration(years=1)), | ||
| ("day_of_year", Duration(years=1)), | ||
| ("day_of_month", Duration(months=1)), | ||
| ("day_of_week", Duration(days=7)), | ||
| ("hour_of_day", Duration(days=1)), | ||
| ("minute_of_hour", Duration(hours=1)), | ||
| ("second_of_minute", Duration(minutes=1)), | ||
| ] | ||
| for prop_name, expected in cases: | ||
| context = Mock(truncated=True) | ||
| context.get_largest_truncated_property_name.return_value = prop_name | ||
| result = parser._get_interval_from_expression(None, context) | ||
| assert result == expected, f"Failed for {prop_name}" | ||
|
|
||
| # when prop_name doesn't match anything, return None | ||
| context = Mock(truncated=True) | ||
| context.get_largest_truncated_property_name.return_value = "unknown_prop" | ||
| assert parser._get_interval_from_expression(None, context) is None | ||
|
|
||
|
|
||
| def test_get_min_from_expression_unresolvable(parsers): | ||
| """It should skip points that cannot be resolved (cpoint is None).""" | ||
| parser = parsers[0] | ||
|
|
||
| # "+P1M" with context=None results in cpoint=None (pure offset, no | ||
| # context to resolve against), so it should be skipped. | ||
| # "20000101T0000Z" resolves fine and should be selected as the min. | ||
| result = parser._get_min_from_expression( | ||
| "min(+P1M, 20000101T0000Z)", context=None | ||
| ) | ||
| assert result == "20000101T0000Z" | ||
|
|
||
|
|
||
| def test_get_point_from_expression_truncated_isodatetime_error(parsers): | ||
| """It should continue past truncated expressions that raise | ||
| IsodatetimeError.""" | ||
| from cylc.flow.exceptions import CylcTimeSyntaxError | ||
|
|
||
| parser = parsers[0] | ||
|
|
||
| # "99T25" matches the TRUNCATED_REC_MAP regex ^\d\dT (for "---" prefix), | ||
| # but "---99T25" is not a valid truncated ISO point (no day 99, hour 25), | ||
| # so it raises IsodatetimeError and the loop continues. | ||
| # Nothing else matches, so CylcTimeSyntaxError is ultimately raised. | ||
| with pytest.raises(CylcTimeSyntaxError): | ||
| parser._get_point_from_expression( | ||
| "99T25", context=None, allow_truncated=True | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.