Skip to content
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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Pete-R-Jones
Copy link

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".

@Pete-R-Jones
Copy link
Author

@Pete-R-Jones
Copy link
Author

Answers UCL-MPHY0021-21-22/RSE-Classwork#18

@Pete-R-Jones
Copy link
Author

Answers
UCL-MPHY0021-21-22/RSE-Classwork#21

@Pete-R-Jones
Copy link
Author

Answers UCL-MPHY0021-21-22/RSE-Classwork#22

Copy link
Contributor

@alessandrofelder alessandrofelder left a 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!

Comment on lines 24 to 29
- name: Test with pytest
run: |
pytest
- name: Test coverage
run: |
pytest --cov=.
Copy link
Contributor

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']
Copy link
Contributor

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
Comment on lines 9 to 13
@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"])])

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@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 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants