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

Fix RecursionError when accessing article_range #18

Merged
merged 2 commits into from
Jan 9, 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 ja_law_parser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ class WithArticleRange(BaseXmlModel, arbitrary_types_allowed=True):

@computed_element(tag="ArticleRange") # type: ignore[arg-type]
def article_range(self) -> Optional[ArticleRange]:
if self.article_range is None:
if self.article_range_raw is None:
return None
return ArticleRange(raw_element=self.article_range)
return ArticleRange(raw_element=self.article_range_raw)

article_range_raw: Optional[etree._Element] = element(tag="ArticleRange", default=None, exclude=True)

Expand Down
32 changes: 32 additions & 0 deletions tests/test_toc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from ja_law_parser.model import TOC


class TestTOC:
def test_toc(self):
xml = """\
<TOC>
<TOCLabel>目次</TOCLabel>
<TOCChapter Num="1">
<ChapterTitle>Chapter 1</ChapterTitle>
<ArticleRange>(第一条・第二条)</ArticleRange>
</TOCChapter>
<TOCChapter Num="2">
<ChapterTitle>Chapter 2</ChapterTitle>
<ArticleRange>(第三条―第五条)</ArticleRange>
</TOCChapter>
<TOCSupplProvision>
<SupplProvisionLabel>附則</SupplProvisionLabel>
</TOCSupplProvision>
</TOC>
"""
toc: TOC = TOC.from_xml(xml)
assert toc is not None
assert toc.toc_label == "目次"
assert len(toc.toc_chapters) == 2
assert toc.toc_chapters[0].num == "1"
assert toc.toc_chapters[0].chapter_title.text == "Chapter 1"
assert toc.toc_chapters[0].article_range.text == "(第一条・第二条)"
assert toc.toc_chapters[1].num == "2"
assert toc.toc_chapters[1].chapter_title.text == "Chapter 2"
assert toc.toc_chapters[1].article_range.text == "(第三条―第五条)"
assert toc.toc_suppl_provision.suppl_provision_label.text == "附則"