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

test_fixed_issues restructure #400

Closed
wants to merge 19 commits into from

Conversation

jacadzaca
Copy link
Collaborator

@jacadzaca jacadzaca commented Sep 9, 2022

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 #397 and #399

@jacadzaca jacadzaca force-pushed the test_restructure1 branch 2 times, most recently from fc78387 to 93f47ef Compare September 9, 2022 15:23
@jacadzaca
Copy link
Collaborator Author

Test fails because pytz.timezone('America/Sao_Paulo') is not considered the same as (UTC-03:00) Brasília, although it is ( principal city) . ZoneInfo and dateutil.tz detect that.

Copy link
Member

@niccokunzmann niccokunzmann left a 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:

  1. 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
  2. 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
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

@jacadzaca jacadzaca Sep 9, 2022

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

Copy link
Member

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
Copy link
Member

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

Copy link
Collaborator Author

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
Copy link
Member

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'
Copy link
Member

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.

event = getattr(events, event_name)
assert event.to_ical() == event.raw_ics

@pytest.mark.parametrize('timezone', [
Copy link
Member

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.

https://github.com/niccokunzmann/python-recurring-ical-events/blob/7f6aeed4729b97981c22ef0f481029cca225ae76/test/conftest.py#L120

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'))
  1. This way, we can add a timezone implementation easily in one place for all tests.
  2. 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?

Copy link
Member

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.

Copy link
Collaborator Author

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')
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

WIP, this is empty.

Copy link
Collaborator Author

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

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'

Copy link
Member

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.

@jacadzaca
Copy link
Collaborator Author

jacadzaca commented Sep 9, 2022

@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 :)

@angatha
Copy link
Collaborator

angatha commented Sep 27, 2022

@jacadzaca nice work that you provide to this package 👍

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.

3 participants