Ejemplo 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"
Ejemplo 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,
    }
Ejemplo n.º 3
0
def test_wizard():
    wizard_path = os.path.join(here, "..", "..", "sphinx_explorer", "settings", "plugin", "template")
    assert os.path.exists(wizard_path)

    params_path = os.path.join(here, "..", "..", "sphinx_explorer", "settings")
    assert os.path.exists(params_path)

    quickstart = os.path.join(wizard_path, "quickstart.yml")
    settings = yaml.load(open(quickstart))
    params_dict = toml.load(os.path.join(params_path, "params.toml"))

    model = PropertyModel()
    model.load_settings(
        settings["wizard"],
        params_dict=params_dict,
        default_values={
            "sep": True,
            "path": r"c:\test",
            "project": "test",
        }
    )

    item = model.get("Options.sep")
    assert item and item.value is True

    item = model.get("Required params.path")
    if platform.system() == "Windows":
        assert item and item.value == r"c:\test\test"
    else:
        assert item and item.value == r"c:\test/test"

    item.update_link()
    if platform.system() == "Windows":
        assert item and item.value == r'c:\test\test'
    else:
        assert item and item.value == r'c:\test/test'

    model.get("Required params.project").set_value("test2")
    if platform.system() == "Windows":
        assert item and item.value == r"c:\test\test2"
    else:
        assert item and item.value == r"c:\test/test2"
Ejemplo n.º 4
0
def test_get_property():
    model = PropertyModel()
    settings = """
- "# categoryA"
-
    - a
- "# categoryB"
-
    - b
- c
    """.strip()

    model.load_settings(yaml.load(settings))

    item = model.get("c")
    assert item.text() == "c"

    item = model.get(("categoryA", "a"))
    assert item.text() == "a"
    assert item.tree_key() == ("categoryA", "a")