Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rprimet committed Feb 16, 2024
1 parent f3e3692 commit 0ba7aee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/catleg/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ async def article_skeleton(articleid: str, breadcrumbs: bool = True) -> str:
back = get_backend("legifrance")
# This uses the Legifrance API directly, not the backend abstraction
raw_article_json = await back.query_article_legi(articleid)
return _article_skeleton(raw_article_json=raw_article_json, breadcrumbs=breadcrumbs)


# separate network calls and processing to ease unit testing
def _article_skeleton(raw_article_json, breadcrumbs: bool = True):
article_json = raw_article_json["article"]
article = _article_from_legifrance_reply(raw_article_json)
if article is None:
Expand Down
13 changes: 12 additions & 1 deletion tests/test_skeleton.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from io import StringIO

import pytest

from catleg.parse_catala_markdown import parse_catala_file
from catleg.query import _article_from_legifrance_reply
from catleg.skeleton import _formatted_atricle
from catleg.skeleton import _article_skeleton, _formatted_atricle

from .test_legifrance_queries import _json_from_test_file

Expand Down Expand Up @@ -85,3 +87,12 @@ def test_no_article_renumbering_in_catala_file_parsing():
assert "1. Le bénéfice ou revenu imposable est constitué" in article.text
assert "2. Le revenu global net annuel" in article.text
assert "3. Le bénéfice ou revenu net de chacune des catégories" in article.text


@pytest.mark.parametrize("breadcrumbs", [False, True])
def test_article_skeleton(breadcrumbs: bool):
article_json = _json_from_test_file("LEGIARTI000044983201.json")
askel = _article_skeleton(article_json)
assert "excédent du produit brut" in askel
if breadcrumbs:
assert "## Première Partie : Impôts d'État" in askel

0 comments on commit 0ba7aee

Please sign in to comment.