Пример #1
0
def test_json_output(tmpdir: Any) -> None:
    generator = GenerateCommand()
    generator.run(["json", "2013/185", "--output-dir", str(tmpdir)])
    body = json.load(tmpdir.join("2013. évi CLXXV. törvény.json").open())

    assert body["identifier"] == "2013. évi CLXXV. törvény"
    assert body[
        "subject"] == "a gondnokoltak és az előzetes jognyilatkozatok nyilvántartásáról"
    assert body["preamble"] == ""

    assert body["children"][0]['__type__'] == "Subtitle"
    assert body["children"][0]['title'] == "A törvény hatálya"

    assert body["children"][4]['__type__'] == "Article"
    assert body["children"][4]['identifier'] == "3"
    assert body["children"][4]['children'][0]['identifier'] == '1'
    assert body["children"][4]['children'][0]['children'][0][
        'identifier'] == 'a'
    assert body["children"][4]['children'][0]['children'][0][
        'intro'] == "a gondnokolt"

    assert body["children"][34]['__type__'] == "Article"
    assert body["children"][34]['identifier'] == "29"
    assert body["children"][34]['children'][0][
        'intro'] == "Az illetékekről szóló 1990. évi XCIII. törvény 43. §-a következő (9) bekezdéssel egészül ki:"

    assert body["children"][36]['__type__'] == "Article"
    assert body["children"][36]['identifier'] == "31"
    assert body["children"][36]['children'][0][
        'text'] == "Hatályát veszti a gondnokoltak nyilvántartásáról szóló 2010. évi XVIII. törvény."

    # This should not throw
    act: Act = dict2object.to_object(body, Act)
    assert act.article('27').paragraph().semantic_data == (EnforcementDate(
        position=None, date=Date(2014, 3, 15)), )
Пример #2
0
def test_as_field(cls: Type, obj: Any, dct: Any) -> None:
    @attr.s(slots=True, frozen=True, auto_attribs=True)
    class Tester:
        field: cls  # type: ignore

    obj = Tester(obj)
    dct = {'field': dct}

    assert to_dict(obj, Tester) == dct
    assert to_object(dct, Tester) == obj
Пример #3
0
def test_obj_to_dict_can_handle_specials() -> None:
    # This also used to test for Type fields, but we no longer have those.
    # But the dict2object unittests do, so it's properly tested.
    # This test will remain as a real-world test though.
    test_data = BlockAmendment(position=StructuralReference(
        "Btk.",
        special=SubtitleArticleCombo(
            SubtitleArticleComboType.BEFORE_WITH_ARTICLE, "123")), )

    the_dict = dict2object.to_dict(test_data, BlockAmendment)

    # This should not throw
    the_json = json.dumps(the_dict)
    reconstructed_dict = json.loads(the_json)

    reconstructed_data = dict2object.to_object(reconstructed_dict,
                                               BlockAmendment)

    assert reconstructed_data == test_data
Пример #4
0
def test_optional(cls: Type, obj: Any, dct: Any) -> None:
    assert to_dict(obj, Optional[cls]) == dct
    assert to_object(dct, Optional[cls]) == obj
    assert to_dict(None, Optional[cls]) is None
    assert to_object(None, Optional[cls]) is None
Пример #5
0
def test_to_obj(cls: Type, obj: Any, dct: Any) -> None:
    assert to_object(dct, cls) == obj