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

Improve data types #58

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions drafts/v1.0/MetronInfo.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<xs:element name="Prices" type="pricesType" minOccurs="0" />
<xs:element name="CoverDate" type="xs:date" minOccurs="0" />
<xs:element name="StoreDate" type="xs:date" minOccurs="0" />
<xs:element name="PageCount" type="xs:int" minOccurs="0" default="0" />
<xs:element name="PageCount" type="xs:nonNegativeInteger" minOccurs="0" default="0" />
<xs:element name="Notes" type="xs:string" minOccurs="0" />
<xs:element name="Genres" type="genresType" minOccurs="0" />
<xs:element name="Tags" type="tagsType" minOccurs="0" />
Expand Down Expand Up @@ -92,7 +92,7 @@
<xs:all>
<xs:element name="Name" type="xs:string" />
<xs:element name="SortName" type="xs:string" minOccurs="0" />
<xs:element name="Volume" type="xs:int" minOccurs="0" />
<xs:element name="Volume" type="xs:nonNegativeInteger" minOccurs="0" />
<xs:element name="Format" type="formatType" minOccurs="0" />
<xs:element name="StartYear" type="xs:gYear" minOccurs="0" />
<xs:element name="IssueCount" type="xs:positiveInteger" minOccurs="0" />
Expand Down
36 changes: 31 additions & 5 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,45 @@


@pytest.mark.parametrize(
("xsd", "xml"), [(TEST_XSD, TEST_FILES_PATH / "valid.xml")], ids=["valid_xml"]
("xsd", "xml"),
[
(TEST_XSD, TEST_FILES_PATH / "valid.xml"),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
"<Series><Name>Foo</Name></Series><Number /><PageCount>0</PageCount></MetronInfo>",
),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
"<Series><Name>Foo</Name><Volume>0</Volume></Series><Number /></MetronInfo>",
),
],
ids=["valid_xml", "zero_page_count", "volume_zero"],
)
def test_valid(xsd, xml) -> None:
def test_valid(xsd: Path, xml: Path | str) -> None:
schema = XMLSchema11(xsd)
schema.validate(xml)


@pytest.mark.parametrize(
("xsd", "xml"),
[(TEST_XSD, TEST_FILES_PATH / "dup_primary_attr.xml")],
ids=["dup_primary_attr_xml"],
[
(TEST_XSD, TEST_FILES_PATH / "dup_primary_attr.xml"),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
"<Series><Name>Foo</Name></Series><Number /><PageCount>-1</PageCount></MetronInfo>",
),
(
TEST_XSD,
'<?xml version="1.0" encoding="UTF-8"?><MetronInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
"<Series><Name>Foo</Name><Volume>-1</Volume></Series><Number /></MetronInfo>",
),
],
ids=["dup_primary_attr_xml", "negative_page_count", "negative_volume"],
)
def test_invalid(xsd, xml) -> None:
def test_invalid(xsd: Path, xml: Path | str) -> None:
schema = XMLSchema11(xsd)
with pytest.raises(XMLSchemaValidationError):
schema.validate(xml)