Exemple #1
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
Exemple #2
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"