diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0997fac..66cf62d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,11 +11,11 @@ permissions: jobs: test: - name: Test - Python ${{ matrix.python-version }} - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + os: ["ubuntu-latest", "macos-latest", "windows-latest"] + python-version: ["pypy3.11", "3.9", "3.10", "3.11", "3.12", "3.13"] env: UV_PYTHON: ${{ matrix.python-version }} steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5b811c0..534aee6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-ast @@ -15,7 +15,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + rev: v3.20.0 hooks: - id: pyupgrade - args: [--py38-plus] + args: [--py39-plus] diff --git a/pyproject.toml b/pyproject.toml index f6c8e5a..c6e45bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,9 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] requires-python = "~=3.9" -dependencies = [] +dependencies = [ + "tzdata; sys_platform == 'win32'", +] [project.urls] Homepage = "https://github.com/getpelican/feedgenerator" diff --git a/tests/test_feedgenerator.py b/tests/test_feedgenerator.py index c389b54..7845378 100644 --- a/tests/test_feedgenerator.py +++ b/tests/test_feedgenerator.py @@ -1,9 +1,13 @@ import datetime +from zoneinfo import ZoneInfo import pytest import feedgenerator +AWARE_DATE = datetime.datetime(2016,8,11,0,0,0,0,tzinfo=ZoneInfo("America/New_York")) +AWARE_DATE_UTC = datetime.datetime(2016,8,11,0,0,0,0,tzinfo=ZoneInfo("UTC")) +NAIVE_DATE = datetime.datetime(2016,8,11,0,0,0,0) FIXT_FEED = dict( title="Poynter E-Media Tidbits", @@ -20,7 +24,7 @@ link="http://www.holovaty.com/täst/", description="Testing.", content="Full content of our testing entry.", - pubdate=datetime.datetime(2016,8,11,0,0,0,0), + pubdate=NAIVE_DATE, ) @@ -135,3 +139,26 @@ def test_subtitle(description, subtitle, fragment, nonfragment): assert fragment in result if nonfragment: assert nonfragment not in result + +@pytest.mark.parametrize("generator, date, expected_date_string", [ + (feedgenerator.Atom1Feed, AWARE_DATE, "2016-08-11T00:00:00-04:00"), + (feedgenerator.Atom1Feed, AWARE_DATE_UTC, "2016-08-11T00:00:00+00:00"), + (feedgenerator.Atom1Feed, NAIVE_DATE, "2016-08-11T00:00:00Z"), + (feedgenerator.Rss201rev2Feed, AWARE_DATE, "Thu, 11 Aug 2016 00:00:00 -0400"), + (feedgenerator.Rss201rev2Feed, AWARE_DATE_UTC, "Thu, 11 Aug 2016 00:00:00 +0000"), + (feedgenerator.Rss201rev2Feed, NAIVE_DATE, "Thu, 11 Aug 2016 00:00:00 -0000"), + (feedgenerator.RssUserland091Feed, AWARE_DATE, "Thu, 11 Aug 2016 00:00:00 -0400"), + (feedgenerator.RssUserland091Feed, AWARE_DATE_UTC, "Thu, 11 Aug 2016 00:00:00 +0000"), + (feedgenerator.RssUserland091Feed, NAIVE_DATE, "Thu, 11 Aug 2016 00:00:00 -0000"), + ]) +def test_timezone_handling(generator, date, expected_date_string): + """ + Test that dates are handled correctly in all Feed generators. + Also test special cases of no timezone given, vs timezone without offset + """ + + feed = generator(**FIXT_FEED) + feed.add_item(**(FIXT_ITEM | {'pubdate': date})) + result = feed.writeString(ENCODING) + + assert expected_date_string in result