-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add test file for compute overlap time #4
base: main
Are you sure you want to change the base?
Conversation
Add coverage to test
Write coverage as separate test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Made some tiny style comments, but looks good!
.github/workflows/python-tests.yml
Outdated
- name: Test with pytest | ||
run: | | ||
pytest | ||
- name: Test coverage | ||
run: | | ||
pytest --cov=. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to combine these two steps into one, so you don't run the tests twice!
@@ -0,0 +1,34 @@ | |||
generic: | |||
time_range_1: | |||
- !!python/tuple ['2010-01-12 10:00:00', '2010-01-12 12:00:00'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't know about Python-specific tags in PyYAML - as you probably realise, this will prevent you from re-using the data in a different programming language... but probably that's also not a good idea in the first place 🤔
test_times.py
Outdated
@pytest.mark.parametrize("time_range_1,time_range_2,expected", [(fixture["generic"]["time_range_1"],fixture["generic"]["time_range_2"], fixture["generic"]["expected"]),\ | ||
(fixture["no_overlap"]["time_range_1"], fixture["no_overlap"]["time_range_2"], fixture["no_overlap"]["expected"]),(fixture["several_intervals"]["time_range_1"],\ | ||
fixture["several_intervals"]["time_range_2"], fixture["several_intervals"]["expected"]), (fixture["same_time"]["time_range_1"], fixture["same_time"]\ | ||
["time_range_2"], fixture["same_time"]["expected"])]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pytest.mark.parametrize("time_range_1,time_range_2,expected", [(fixture["generic"]["time_range_1"],fixture["generic"]["time_range_2"], fixture["generic"]["expected"]),\ | |
(fixture["no_overlap"]["time_range_1"], fixture["no_overlap"]["time_range_2"], fixture["no_overlap"]["expected"]),(fixture["several_intervals"]["time_range_1"],\ | |
fixture["several_intervals"]["time_range_2"], fixture["several_intervals"]["expected"]), (fixture["same_time"]["time_range_1"], fixture["same_time"]\ | |
["time_range_2"], fixture["same_time"]["expected"])]) | |
@pytest.mark.parametrize("time_range_1,time_range_2,expected", | |
[ | |
(fixture["generic"]["time_range_1"], fixture["generic"]["time_range_2"], fixture["generic"]["expected"]),\ | |
(fixture["no_overlap"]["time_range_1"], fixture["no_overlap"]["time_range_2"], fixture["no_overlap"]["expected"]),\ | |
(fixture["several_intervals"]["time_range_1"], fixture["several_intervals"]["time_range_2"], fixture["several_intervals"]["expected"]),\ | |
(fixture["same_time"]["time_range_1"], fixture["same_time"]["time_range_2"], fixture["same_time"]["expected"]) | |
]) |
or something like this, possibly better done with an automatic formatter, would maybe make this more readable 🙂
Answers UCL-MPHY0021-21-22/RSE-Classwork#16
I hadn't used pytest before so was interesting to see it work, and writing test functions using "assert".