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"
def test_type(): settings = """ - a: value_type: TypeBool default: true """ model = PropertyModel() model.load_settings(yaml.load(settings)) assert model.a.value is True
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"
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"
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)"
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
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)
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()
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"
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
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")
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
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"
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
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, }