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_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, }
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_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