-
-
Notifications
You must be signed in to change notification settings - Fork 175
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
test_fixed_issues restructure #400
Conversation
fc78387
to
93f47ef
Compare
Test fails because |
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.
So, I like where the code is heading!
There is one problem that I see.... To review these conditions seem to be important:
- that no test is left out
- that tests that were changed correspond to the test that was there before
- that nothing was added that was not tested before
Since this is a very big PR, this will take a while and any new PR to tests will create merge conflicts.
How can we tackle that?
To make sure that this is clear: I really like the code that I see!
I find it hard to review.
I see two options:
- You wait until I reviewed this
- I will go through the commits to see that the changes are consistent refectorings
- I will go though each test in the original code (master) and then try to find them in the PR
- You split it up:
- Creating the base (conftest.py first), wait for it to be merged
- Create a PR for tests by cherry-picking
Also a question: Is this possible to port to 4.x?
What are your thoughts on this?
|
||
@pytest.fixture | ||
def timezones(): | ||
return TIMEZONES |
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.
Sometimes, elements might be changed by tests and then, we have side effects.
Personally, I would put DataSource(TIMEZONES_FOLDER, icalendar.Timezone.from_ical)
into the function body.
Does that impact execution time?
I would say that we can use __getattr__
to set the attributes and then, they will only loaded when needed. What do you think?
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.
This is how I do it:
... not quite like I said ...
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.
To be honest, I didn't quite grasp the piece of code you've linked when I was writing my conftest. You're right that side effects are possible. I think implementing simple lazy loading shouldn't be too hard. I can override getattr or use the @property
decorator, like you've said.
@pytest.fixture | ||
def calendars_folder(): | ||
return CALENDARS_FOLDER | ||
|
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 like this file!
@@ -1,30 +1,3 @@ | |||
BEGIN:VCALENDAR | |||
PRODID:-//Google Inc//Google Calendar 70.9054//EN |
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.
Why is is removed is probably in the commit...
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.
Seems like a trip up on my side, weird that the test still passes.
} | ||
) | ||
|
||
assert event.to_ical() == events.issue_116_117_add_x_apple_structured.raw_ics |
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.
Cool!
# Unicode characters in summary | ||
'issue_64_event_with_unicode_summary', | ||
# chokes on umlauts in ORGANIZER | ||
'issue_101_icalendar_chokes_on_umlauts_in_organizer' |
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.
Cool. Very clear which issue is referenced. This was important to me and it seems to work nicely.
src/icalendar/tests/test_encoding.py
Outdated
event = getattr(events, event_name) | ||
assert event.to_ical() == event.raw_ics | ||
|
||
@pytest.mark.parametrize('timezone', [ |
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.
I would like to change this and add a parametrized fixture that takes the time zone string as an argument, so we make sure we have one place in which we list all the different time zone implementations.
In conftest:
# for parametrizing fixtures, see https://docs.pytest.org/en/latest/fixture.html#parametrizing-fixtures
@pytest.fixture(params=[pytz.timezone, tz.gettz, zoneinfo.ZoneInfo], scope="module")
def TZ(request):
return request.param()
Here:
def test_parses_event_with_non_ascii_tzid_issue_237(events, TZ):
...
expected = datetime.datetime(2017, 5, 11, 13, 30, tzinfo=TZ('America/Sao_Paulo'))
- This way, we can add a timezone implementation easily in one place for all tests.
- We can use this fixture in the future, if we were to specify a timezone parameter for the parsing of the ics files.
What do you think?
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.
https://github.com/collective/icalendar/runs/8273351016?check_suite_focus=true#step:6:58 would be solved by passing a parameter to the parser of which implementation to use.
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.
Should that be in the commit with the test or a separate one?
'''Issue #104 - line parsing error in a VCALENDAR | ||
(which doesn't have ignore_exceptions). Should raise an exception. | ||
''' | ||
calendar_path = os.path.join(calendars_folder, 'issue_104_broken_calendar.ics') |
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.
This would use the fixture.
except ModuleNotFoundError: | ||
from backports import zoneinfo | ||
|
||
from icalendar import Event |
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.
WIP, this is empty.
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.
I think I forgot to remove this file, when I moved test 335 to test_parsing. I will remove it
zoneinfo.ZoneInfo('UTC'), | ||
pytz.timezone('UTC'), | ||
tz.UTC, | ||
tz.gettz('UTC')]) |
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.
calls for a general fixture in conftest: utc
recur = events.issue_70_rrule_causes_attribute_error.decoded('RRULE') | ||
assert isinstance(recur, vRecur) | ||
assert recur.to_ical() == b'FREQ=WEEKLY;UNTIL=20070619T225959;INTERVAL=1' | ||
|
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.
I really like the test structure, the different fixtures and the way that there are a few assertions always at the end.
@niccokunzmann Now that I think about it, it really is a big PR. Tomorrow-ish, I will implement the suggestion you've made and cherry pick the PR into few smaller ones (option 2). Thanks :) |
93f47ef
to
577d233
Compare
@jacadzaca nice work that you provide to this package 👍 |
Restructure tests inside test_fixed_issues along the lines of #374. I tried to keep tests for similar assertions in one file.
Before considering merging, please take a look at
#397and #399