Skip to content

Commit

Permalink
Refactor tests, make link and enclosure a list
Browse files Browse the repository at this point in the history
fixes #49
  • Loading branch information
dhvcc committed Jun 9, 2024
1 parent 5049615 commit 6a7a97b
Show file tree
Hide file tree
Showing 33 changed files with 2,205 additions and 2,119 deletions.
58 changes: 28 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
packages = [
{include = "rss_parser"},
{include = "rss_parser/py.typed"},
]
packages = [{ include = "rss_parser" }, { include = "rss_parser/py.typed" }]


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

[tool.pytest.ini_options]
addopts = "-color=yes"
addopts = "--color=yes"
testpaths = ["tests"]
log_cli = true
log_level = "INFO"


[tool.black]
line-length = 120
Expand All @@ -65,36 +66,33 @@ line-length = 120
target-version = "py38"
respect-gitignore = true
select = [
"PL", # pylint
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort
"N", # pep8-naming
"S", # flake8-bandit
"A", # flake8-builtins
"C40", # flake8-comprehensions
"T10", # flake8-debugger
"EXE", # flake8-executable
"T20", # flake8-print
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"ARG", # flake8-unused-arguments
"RUF", # ruff
"PL", # pylint
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"I", # isort
"N", # pep8-naming
"S", # flake8-bandit
"A", # flake8-builtins
"C40", # flake8-comprehensions
"T10", # flake8-debugger
"EXE", # flake8-executable
"T20", # flake8-print
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"ARG", # flake8-unused-arguments
"RUF", # ruff
]

[tool.ruff.per-file-ignores]
"tests/**.py" = [
"S101", # Use of assert detected
"ARG001", # Unused function argument
"S311", # Allow use of random
]
"**/__init__.py" = [
"F401"
]
"rss_parser/models/atom/**" = [
"A003"
"S101", # Use of assert detected
"ARG001", # Unused function argument
"S311", # Allow use of random
"S301", # Allow use of pickle
]
"**/__init__.py" = ["F401"]
"rss_parser/models/atom/**" = ["A003"]


[build-system]
Expand Down
2 changes: 0 additions & 2 deletions rss_parser/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

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

def json_plain(self, **kw):
Expand Down
1 change: 0 additions & 1 deletion rss_parser/models/rss/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class OptionalChannelElementsMixin(XMLBaseModel):
copyright: Optional[Tag[str]] = None # Copyright 2002, Spartanburg Herald-Journal # noqa
"Copyright notice for content in the channel."

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

web_master: Optional[Tag[str]] = None # [email protected] (Betty Guernsey)
Expand Down
11 changes: 8 additions & 3 deletions rss_parser/models/rss/item.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from typing import Optional

from rss_parser.models import XMLBaseModel
from rss_parser.models.types.only_list import OnlyList
from rss_parser.models.types.tag import Tag
from rss_parser.pydantic_proxy import import_v1_pydantic

pydantic = import_v1_pydantic()


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

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

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

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

guid: Optional[Tag[str]] = None
"A string that uniquely identifies the item."
Expand Down
Empty file added tests/__init__.py
Empty file.
15 changes: 10 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from json import loads
import pickle
from pathlib import Path

import pytest
Expand All @@ -9,7 +9,12 @@

@pytest.fixture
def sample_and_result(request):
with open(sample_dir / f"{request.param[0]}.xml", encoding="utf-8") as sample:
plain = len(request.param) > 1 and request.param[1]
with open(sample_dir / f"{request.param[0]}{'_plain' if plain else ''}.json", encoding="utf-8") as result:
return sample.read(), loads(result.read())
sample_name = request.param[0]

with open(sample_dir / sample_name / "data.xml", encoding="utf-8") as sample_file:
sample = sample_file.read()

with open(sample_dir / sample_name / "result.pkl", "rb") as result_file:
result = pickle.load(result_file)

return sample, result
144 changes: 0 additions & 144 deletions tests/samples/apology_line.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ See Privacy Policy at https://art19.com/privacy and California Privacy Notice at
<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>
<itunes:duration>00:05:01</itunes:duration>
<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"/>
<link>https://wondery.com/shows/the-apology-line/?utm_source=rss</link>
</item>
<item>
<title>Introducing: The Apology Line </title>
Expand All @@ -82,6 +83,7 @@ See Privacy Policy at https://art19.com/privacy and California Privacy Notice at
<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>
<itunes:duration>00:02:24</itunes:duration>
<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"/>
<link>https://wondery.com/shows/the-apology-line/?utm_source=rss</link>
</item>
</channel>
</rss>
Binary file added tests/samples/apology_line/result.pkl
Binary file not shown.
57 changes: 0 additions & 57 deletions tests/samples/apology_line_plain.json

This file was deleted.

Loading

0 comments on commit 6a7a97b

Please sign in to comment.