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 from_file and to_file method #757

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

Conversation

abe-101
Copy link
Collaborator

@abe-101 abe-101 commented Dec 9, 2024

closes #756


📚 Documentation preview 📚: https://icalendar--757.org.readthedocs.build/

@abe-101
Copy link
Collaborator Author

abe-101 commented Dec 9, 2024

A few questions:

  • Are the Examples in the methods doc strings ran as part of the test suite?
  • If yes, is that enough of a test? or should i create a dedicated test file for it?
  • Regarding the projects documentation:
    • Should i add a section in usage.rst and how to use the new method?
    • Or better, perhaps i should change the given examples that open a file to instead use the new from_file() method? and seporatly demonstrate how to use from_ical() to parse a str?

@abe-101 abe-101 requested a review from niccokunzmann December 9, 2024 20:12
@abe-101 abe-101 force-pushed the 756-read-from-file branch from 376e391 to 804ab52 Compare December 9, 2024 20:16
@coveralls
Copy link

coveralls commented Dec 9, 2024

Pull Request Test Coverage Report for Build 12258919799

Details

  • 10 of 10 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 96.364%

Totals Coverage Status
Change from base Build 12219883617: 0.009%
Covered Lines: 4590
Relevant Lines: 4757

💛 - Coveralls

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.

Hi @abe-101, I left a few comments. What are your thoughts?

>>> from icalendar import Calendar
>>> # Read a calendar file
>>> cal = Calendar.from_file("src/icalendar/tests/calendars/example.ics")
>>> # Read multiple calendars
Copy link
Member

Choose a reason for hiding this comment

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

You can remove the >>> here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are you suggestion to remove the >>> on the lines where there is a comment? or perhaps just remove the comments altogether?

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

Choose a reason for hiding this comment

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

if I remove the >>> from the comments then the test fails
This doesn't work:

        Example:
            >>> from icalendar import Calendar
            >>> from pathlib import Path
            # Read a calendar file
            >>> cal = Calendar.from_file("src/icalendar/tests/calendars/example.ics")
            # Read multiple calendars
            >>> cals = Calendar.from_file("src/icalendar/tests/calendars/multiple_calendar_components.ics", multiple=True)
            # or pass a Path object
            >>> path = Path("src/icalendar/tests/calendars/example.ics")
            >>> cal = Calendar.from_file(path)

This does work:

        Example:
            >>> from icalendar import Calendar
            >>> from pathlib import Path
            >>> # Read a calendar file
            >>> cal = Calendar.from_file("src/icalendar/tests/calendars/example.ics")
            >>> # Read multiple calendars
            >>> cals = Calendar.from_file("src/icalendar/tests/calendars/multiple_calendar_components.ics", multiple=True)
            >>> # or pass a Path object
            >>> path = Path("src/icalendar/tests/calendars/example.ics")
            >>> cal = Calendar.from_file(path)

>>> from icalendar import Calendar
>>> from pathlib import Path
>>> # Read a calendar file
>>> cal = Calendar.from_file("src/icalendar/tests/calendars/example.ics")
Copy link
Member

Choose a reason for hiding this comment

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

The examples here seem to be the same as above. You can use a temporary file for this.

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 changed the examples to use the to_file() method

@niccokunzmann
Copy link
Member

Hi @abe-101, thanks for your PR!

Are the Examples in the methods doc strings ran as part of the test suite?

Yes, if they are behind a >>>

Should i add a section in usage.rst and how to use the new method?

No, I think a proper API documentation is enough for now.

Or better, perhaps i should change the given examples that open a file to instead use the new from_file() method? and seporatly demonstrate how to use from_ical() to parse a str?

If you feel like it, a new PR might be the right place for that. Let's finish this one...


Example:
>>> from icalendar import Calendar
>>> # Read a calendar file
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
>>> # Read a calendar file
# Read a calendar file

@niccokunzmann
Copy link
Member

Hi, could you write a test for that?

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.

Allow to read calendars from files
3 participants