コード例 #1
0
def test_link():
    model = PropertyModel()
    settings = [
        "#category",
        {
            "a":
                {
                    "label": "Document",
                    "default": "test",
                },
        },
        {
            "b":
                {
                    "label": "Document",
                    "link": "a",
                }
        },
    ]
    model.load_settings(settings)

    prop_map = model.property_map()
    item_a = prop_map["a"]
    item_b = prop_map["b"]
    assert item_b.value == "test"

    item_a.set_value("test x")
    assert item_b.value == "test x"
    item_b.set_value("test xx")
    assert item_b.value == "test xx"
コード例 #2
0
def test_type():
    settings = """
    - a:
        value_type: TypeBool
        default: true
    """
    model = PropertyModel()
    model.load_settings(yaml.load(settings))

    assert model.a.value is True
コード例 #3
0
def test_link():
    settings = """
- a
- b:
    link: a
    """
    model = PropertyModel()
    model.load_settings(yaml.load(settings))
    model.a.set_value("test")
    assert model.a.value == "test"
    assert model.b.value == "test"
コード例 #4
0
def test_allow_empty():
    settings = """
    - a:
        value: ""
        allow_empty: no
        default: "default"
    """
    model = PropertyModel()
    model.load_settings(yaml.load(settings))
    assert model.a.value == "default"
    model.a.set_value("input")
    assert model.a.value == "input"
    model.a.set_value("")
    assert model.a.value == "default"
コード例 #5
0
def test_link_format():
    settings = """
- a
- b
- c:
    link: ({a}, {b})
- d:
    link: "{_default}: {c}"
    default: def
    """
    model = PropertyModel()
    model.load_settings(yaml.load(settings))
    model.a.set_value("a")
    model.b.set_value("b")
    assert model.c.value == "(a, b)"
    assert model.d.value == "def: (a, b)"
コード例 #6
0
def pytest_funcarg__simple_model(request):
    model = PropertyModel()
    settings = """
- "# categoryA"
-
    - a
    - b
    - c
- "# Link"
-
    - d:
        link: a
    """.strip()

    setting_obj = yaml.load(settings)
    model.load_settings(setting_obj)

    return model
コード例 #7
0
 def __init__(self, params_dict, default_values, parent=None):
     super(BaseWizard, self).__init__(parent)
     self._value_dict = {}
     self.params_dict = params_dict
     _default_values = {}
     for key, value in params_dict.items():
         if "default" in value:
             _default_values[key] = value.get("default")
     _default_values.update(default_values)
     self.default_values = DefaultValues(_default_values)
     self.property_model = PropertyModel(self)
コード例 #8
0
def test_required():
    model = PropertyModel()

    settings = [
        "#category",
        {
            "a": {
                "label": "Document",
                "required": True,
            }
        },
    ]
    model.load_settings(settings)
    assert False is model.is_complete()

    model.property_map()["a"].set_value("test")
    assert True is model.is_complete()
コード例 #9
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"
コード例 #10
0
def test_check_tree():
    settings = """
    - "#group":
        checkable: yes
        default: yes
    -
        - a
        - b
    """
    model = PropertyModel()
    model.load_settings(yaml.load(settings))

    assert model.group.a.isEnabled() is True

    model.setData(model.group.index(), Qt.Unchecked, Qt.CheckStateRole)
    assert model.group.a.isEnabled() is False
コード例 #11
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")
コード例 #12
0
def test_load_settings2():
    model = PropertyModel()
    settings = """
- "# categoryA"
-
    - a
    - b
    - c
- "# categoryB"
-
    - d
    - e
    - f
    """.strip()

    model.load_settings(yaml.load(settings))
    assert model.rowCount() == 2

    model.clear()
    settings = """
- a
- b
- c
    """.strip()

    model.load_settings(yaml.load(settings))
    assert model.rowCount() == 3

    model.clear()
    settings = """
- "# cat"
- a
- b
    """.strip()

    model.load_settings(yaml.load(settings))
    assert model.rowCount() == 3

    model.clear()
    settings = """
- a:
    default_value: default
    link: b
- b:
    value: value
- c
        """.strip()

    print(yaml.load(settings))
    model.load_settings(yaml.load(settings))
    assert model.rowCount() == 3
コード例 #13
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"
コード例 #14
0
def test_load_settings():
    model = PropertyModel()

    # category and basic param
    settings = [
        "#category",
        "a",
        "b",
        "c",
    ]

    model.load_settings(settings)
    assert [u'a', u'b', u'c'] == [x.text() for x in model.properties()]
    model.clear()

    # Detailed parameters
    settings = [
        "#category",
        {
            "a": {
                "label": "Document",
            },
        },
        {
            "b": {
                "label": "Check",
                "value_type": "TypeBool",
                "default": False
            }
        },
    ]
    model.load_settings(settings)

    assert ['Document', 'Check'] == [x.text() for x in model.properties()]
    check_item = model.property_map()["b"]  # type: PropertyItem
    assert TypeBool is check_item.value_type
    assert not check_item.value
コード例 #15
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,
    }