File: test_tree.py

package info (click to toggle)
python-pytray 0.3.5-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 192 kB
  • sloc: python: 510; sh: 30; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 908 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
from pytray import tree


def test_flattening():
    my_tree = {
        "a": {"b": 6, "c": "potato"},
        "d": [
            {
                "e": [],
            },
            "hello",
        ],
    }
    flattened = tree.flatten(my_tree)
    assert flattened.pop(("a", "b")) == 6
    assert flattened.pop(("a", "c")) == "potato"
    assert flattened.pop(("d", 0, "e")) == []
    assert flattened.pop(("d", 1)) == "hello"
    assert not flattened


def test_flattening_filter():
    my_tree = {"a": {"b": 5, "c": {"d": 6}}}
    # Don't flatten {'d': 6}
    flattened = tree.flatten(my_tree, filter=lambda value: value != {"d": 6})
    assert flattened.pop(("a", "b")) == 5
    assert flattened.pop(("a", "c")) == {"d": 6}
    assert not flattened


def test_path_to_string():
    pathstring = tree.path_to_string(("a", "b", "c", 0, "d"))
    assert pathstring == "a.b.c.0.d"