Skip to content

Commit a75867b

Browse files
committed
Refactor tests, make link and enclosure a list
fixes #49
1 parent 5049615 commit a75867b

33 files changed

+2205
-2119
lines changed

pyproject.toml

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ classifiers = [
2929
"Programming Language :: Python :: 3.11",
3030
"Programming Language :: Python :: 3.12",
3131
]
32-
packages = [
33-
{include = "rss_parser"},
34-
{include = "rss_parser/py.typed"},
35-
]
32+
packages = [{ include = "rss_parser" }, { include = "rss_parser/py.typed" }]
3633

3734

3835
[tool.poetry.urls]
@@ -54,7 +51,11 @@ rich = "*"
5451
pytest = "^7.4.0"
5552

5653
[tool.pytest.ini_options]
57-
addopts = "-color=yes"
54+
addopts = "--color=yes"
55+
testpaths = ["tests"]
56+
log_cli = true
57+
log_level = "INFO"
58+
5859

5960
[tool.black]
6061
line-length = 120
@@ -65,36 +66,33 @@ line-length = 120
6566
target-version = "py38"
6667
respect-gitignore = true
6768
select = [
68-
"PL", # pylint
69-
"F", # pyflakes
70-
"E", # pycodestyle errors
71-
"W", # pycodestyle warnings
72-
"I", # isort
73-
"N", # pep8-naming
74-
"S", # flake8-bandit
75-
"A", # flake8-builtins
76-
"C40", # flake8-comprehensions
77-
"T10", # flake8-debugger
78-
"EXE", # flake8-executable
79-
"T20", # flake8-print
80-
"TID", # flake8-tidy-imports
81-
"TCH", # flake8-type-checking
82-
"ARG", # flake8-unused-arguments
83-
"RUF", # ruff
69+
"PL", # pylint
70+
"F", # pyflakes
71+
"E", # pycodestyle errors
72+
"W", # pycodestyle warnings
73+
"I", # isort
74+
"N", # pep8-naming
75+
"S", # flake8-bandit
76+
"A", # flake8-builtins
77+
"C40", # flake8-comprehensions
78+
"T10", # flake8-debugger
79+
"EXE", # flake8-executable
80+
"T20", # flake8-print
81+
"TID", # flake8-tidy-imports
82+
"TCH", # flake8-type-checking
83+
"ARG", # flake8-unused-arguments
84+
"RUF", # ruff
8485
]
8586

8687
[tool.ruff.per-file-ignores]
8788
"tests/**.py" = [
88-
"S101", # Use of assert detected
89-
"ARG001", # Unused function argument
90-
"S311", # Allow use of random
91-
]
92-
"**/__init__.py" = [
93-
"F401"
94-
]
95-
"rss_parser/models/atom/**" = [
96-
"A003"
89+
"S101", # Use of assert detected
90+
"ARG001", # Unused function argument
91+
"S311", # Allow use of random
92+
"S301", # Allow use of pickle
9793
]
94+
"**/__init__.py" = ["F401"]
95+
"rss_parser/models/atom/**" = ["A003"]
9896

9997

10098
[build-system]

rss_parser/models/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
class XMLBaseModel(pydantic.BaseModel):
1515
class Config:
16-
# Not really sure if we want for the schema obj to be immutable, disabling for now
17-
# allow_mutation = False
1816
alias_generator = camel_case
1917

2018
def json_plain(self, **kw):

rss_parser/models/rss/channel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class OptionalChannelElementsMixin(XMLBaseModel):
3636
copyright: Optional[Tag[str]] = None # Copyright 2002, Spartanburg Herald-Journal # noqa
3737
"Copyright notice for content in the channel."
3838

39-
managing_editor: Optional[Tag[str]] = None # [email protected] (George Matesky)
4039
"Email address for person responsible for editorial content."
4140

4241
web_master: Optional[Tag[str]] = None # [email protected] (Betty Guernsey)

rss_parser/models/rss/item.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from typing import Optional
22

33
from rss_parser.models import XMLBaseModel
4+
from rss_parser.models.types.only_list import OnlyList
45
from rss_parser.models.types.tag import Tag
6+
from rss_parser.pydantic_proxy import import_v1_pydantic
7+
8+
pydantic = import_v1_pydantic()
59

610

711
class RequiredItemElementsMixin(XMLBaseModel):
812
title: Tag[str] = None # Venice Film Festival Tries to Quit Sinking
913
"The title of the item."
1014

11-
link: Tag[str] = None # http://nytimes.com/2004/12/07FEST.html
15+
links: OnlyList[Tag[str]] = pydantic.Field(alias="link") # http://nytimes.com/2004/12/07FEST.html
1216
"The URL of the item."
1317

1418
description: Tag[
@@ -28,8 +32,9 @@ class OptionalItemElementsMixin(XMLBaseModel):
2832
comments: Optional[Tag[str]] = None
2933
"URL of a page for comments relating to the item."
3034

31-
enclosure: Optional[Tag[str]] = None
32-
"Describes a media object that is attached to the item."
35+
enclosures: Optional[OnlyList[Tag[str]]] = pydantic.Field(alias="enclosure", default=[])
36+
# enclosure: Optional[OnlyList[Tag[str]]] = None
37+
"Describes a media object that is attached to the item.\n" "Can be a list -> https://validator.w3.org/feed/docs/warning/DuplicateEnclosure.html"
3338

3439
guid: Optional[Tag[str]] = None
3540
"A string that uniquely identifies the item."

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from json import loads
1+
import pickle
22
from pathlib import Path
33

44
import pytest
@@ -9,7 +9,12 @@
99

1010
@pytest.fixture
1111
def sample_and_result(request):
12-
with open(sample_dir / f"{request.param[0]}.xml", encoding="utf-8") as sample:
13-
plain = len(request.param) > 1 and request.param[1]
14-
with open(sample_dir / f"{request.param[0]}{'_plain' if plain else ''}.json", encoding="utf-8") as result:
15-
return sample.read(), loads(result.read())
12+
sample_name = request.param[0]
13+
14+
with open(sample_dir / sample_name / "data.xml", encoding="utf-8") as sample_file:
15+
sample = sample_file.read()
16+
17+
with open(sample_dir / sample_name / "result.pkl", "rb") as result_file:
18+
result = pickle.load(result_file)
19+
20+
return sample, result

tests/samples/apology_line.json

Lines changed: 0 additions & 144 deletions
This file was deleted.

tests/samples/apology_line.xml renamed to tests/samples/apology_line/data.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ See Privacy Policy at https://art19.com/privacy and California Privacy Notice at
5959
<itunes:keywords>Serial killer,TRUE CRIME,Society,This American Life,MURDER,Apology,Apology Line,Binge Worthy Documentary,New York City,Binge-worthy true crime,exhibit c</itunes:keywords>
6060
<itunes:duration>00:05:01</itunes:duration>
6161
<enclosure url="https://dts.podtrac.com/redirect.mp3/chrt.fm/track/9EE2G/pdst.fm/e/rss.art19.com/episodes/7bfce2e9-7889-480a-afde-46e810e82b1a.mp3?rss_browser=BAhJIhRweXRob24tcmVxdWVzdHMGOgZFVA%3D%3D--ac965bdf6559f894a935511702ea4ac963845aca" type="audio/mpeg" length="4824502"/>
62+
<link>https://wondery.com/shows/the-apology-line/?utm_source=rss</link>
6263
</item>
6364
<item>
6465
<title>Introducing: The Apology Line </title>
@@ -82,6 +83,7 @@ See Privacy Policy at https://art19.com/privacy and California Privacy Notice at
8283
<itunes:keywords>Exhibit C,New York City,Murder,This American Life,society,serial killer,true crime,Apology Line,Binge Worthy Documentary ,Binge-worthy true crime,Apology</itunes:keywords>
8384
<itunes:duration>00:02:24</itunes:duration>
8485
<enclosure url="https://dts.podtrac.com/redirect.mp3/chrt.fm/track/9EE2G/pdst.fm/e/rss.art19.com/episodes/a462e9fa-5e7b-4b0a-b992-d59fa1ca06cd.mp3?rss_browser=BAhJIhRweXRob24tcmVxdWVzdHMGOgZFVA%3D%3D--ac965bdf6559f894a935511702ea4ac963845aca" type="audio/mpeg" length="2320091"/>
86+
<link>https://wondery.com/shows/the-apology-line/?utm_source=rss</link>
8587
</item>
8688
</channel>
8789
</rss>
5.51 KB
Binary file not shown.

tests/samples/apology_line_plain.json

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)