Exemplo n.º 1
0
def test_table_model():
    model = PropertyModel()
    settings = """
- "# categoryA"
-
    - a
    - b
    - c
- "# categoryB"
-
    - d
    - e
    - f
    """.strip()

    setting_obj = yaml.load(settings)
    model.load_settings(setting_obj)
    root_item = model.get("categoryA")

    assert 3 == model.rowCount(root_item.index())
    assert 2 == model.columnCount(root_item.index())

    model.get("categoryA.a").set_value("100")

    obj = model.dump()
    assert {'categoryA': {'a': '100'}} == obj

    model.clear()
    model.load_settings(setting_obj, default_values=obj)

    item = model.get("categoryA.a")
    assert item.value == "100"
Exemplo n.º 2
0
def test_dump():
    settings = """
    - "#* Epub Settings"
    -
        - epub_cover
        - epub_writing_mode:
            default: horizontal
        - epub_header
    """
    model = PropertyModel()
    model.load_settings(yaml.load(settings))
    dump = model.dump()
    assert dump == {'Epub Settings': {'epub_writing_mode': 'horizontal'}}

    model.get("Epub Settings").epub_cover.set_value("cover")
    dump = model.dump()
    assert dump == {
        "Epub Settings": {
            "epub_cover": "cover",
            "epub_writing_mode": "horizontal",
        }
    }

    model.clear()
    model.load_settings(yaml.load(settings))
    model.set_values({"Epub Settings": {"epub_cover": "cover"}})
    assert model.get("Epub Settings").epub_cover.value == "cover"

    flat_dump = model.dump(flat=True)
    assert flat_dump == {
        "epub_cover": "cover",
        "epub_writing_mode": "horizontal",
    }

    flat_dump = model.dump(flat=True, exclude_default=True)
    assert flat_dump == {
        "epub_cover": "cover",
    }

    flat_dump = model.dump(flat=True, store_none=True, exclude_default=True)
    assert flat_dump == {
        "epub_cover": "cover",
        "epub_header": None,
    }