Skip to content

Commit d7091d0

Browse files
committed
Add import guard for legacy models, fix tests for 3.14
1 parent cdcca19 commit d7091d0

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

rss_parser/models/legacy/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44
Some types and validation may be a bit custom to account for broken standards in some RSS feeds.
55
"""
66

7+
import sys
78
from json import loads
89
from typing import TYPE_CHECKING
910

11+
if sys.version_info >= (3, 14):
12+
raise ImportError("Legacy models are not supported in Python 3.14 and above")
13+
1014
from rss_parser.models.legacy.pydantic_proxy import import_v1_pydantic
1115
from rss_parser.models.legacy.utils import camel_case
1216

tests/test_parsing.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1+
import sys
12
from typing import Type
23

34
import pytest
45

56
from rss_parser import AtomParser, BaseParser, RSSParser
6-
from rss_parser.models.legacy.atom import Atom as LegacyAtom
7-
from rss_parser.models.legacy.rss import RSS as LegacyRSS
87

8+
if sys.version_info < (3, 14):
9+
from rss_parser.models.legacy.atom import Atom as LegacyAtom
10+
from rss_parser.models.legacy.rss import RSS as LegacyRSS
911

10-
class LegacyRSSParser(RSSParser):
11-
schema = LegacyRSS
12+
class LegacyRSSParser(RSSParser):
13+
schema = LegacyRSS
1214

15+
class LegacyAtomParser(AtomParser):
16+
schema = LegacyAtom
1317

14-
class LegacyAtomParser(AtomParser):
15-
schema = LegacyAtom
18+
rss_parser_list = [RSSParser, LegacyRSSParser]
19+
rss_ids = ["rss-v2", "rss-legacy"]
20+
atom_parser_list = [AtomParser, LegacyAtomParser]
21+
atom_ids = ["atom-v2", "atom-legacy"]
22+
else:
23+
rss_parser_list = [RSSParser]
24+
rss_ids = ["rss-v2"]
25+
atom_parser_list = [AtomParser]
26+
atom_ids = ["atom-v2"]
1627

1728

1829
class DataHelper:
@@ -32,14 +43,14 @@ def compare_parsing(sample_and_result, parser: Type[BaseParser]):
3243

3344
RSS_PARSERS = pytest.mark.parametrize(
3445
"parser_cls",
35-
[RSSParser, LegacyRSSParser],
36-
ids=["rss-v2", "rss-legacy"],
46+
rss_parser_list,
47+
ids=rss_ids,
3748
)
3849

3950
ATOM_PARSERS = pytest.mark.parametrize(
4051
"parser_cls",
41-
[AtomParser, LegacyAtomParser],
42-
ids=["atom-v2", "atom-legacy"],
52+
atom_parser_list,
53+
ids=atom_ids,
4354
)
4455

4556

@@ -74,3 +85,10 @@ class TestAtom:
7485
@ATOM_PARSERS
7586
def test_parses_all_atom_samples(self, sample_and_result, parser_cls):
7687
DataHelper.compare_parsing(sample_and_result, parser=parser_cls)
88+
89+
90+
class TestLegacyImportError:
91+
@pytest.mark.skipif(sys.version_info < (3, 14), reason="Legacy models still work in Python 3.13 and below")
92+
def test_legacy_import_error(self):
93+
with pytest.raises(ImportError):
94+
from rss_parser.models.legacy import XMLBaseModel # noqa: F401, PLC0415

0 commit comments

Comments
 (0)