File: test_fdb.py

package info (click to toggle)
fdb 5.20.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 89,268 kB
  • sloc: cpp: 40,830; python: 5,079; sh: 4,996; makefile: 32; ansic: 8
file content (102 lines) | stat: -rw-r--r-- 2,348 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from pathlib import Path

import pytest
import yaml

from pyfdb import FDB


def test_initialization():
    fdb = FDB()
    assert fdb


def test_fdb_config_default():
    assert FDB()


def test_fdb_config_wrong_type():
    with pytest.raises(ValueError, match="Config: Unknown config type, must be str, dict or Path"):
        fdb = FDB(0)

        assert fdb


def test_fdb_config_fixture(read_only_fdb_setup):
    fdb = FDB(read_only_fdb_setup)
    assert fdb


def test_fdb_config_equality(read_only_fdb_setup):
    pyfdb_config_str = FDB(read_only_fdb_setup)
    assert pyfdb_config_str

    pyfdb_config_path = FDB(read_only_fdb_setup)
    assert pyfdb_config_path

    config_dict = yaml.safe_load(read_only_fdb_setup.read_bytes())
    pyfdb_config_dict = FDB(config_dict)
    assert pyfdb_config_dict

    print(pyfdb_config_str)
    print(pyfdb_config_path)
    print(pyfdb_config_dict)

    selection = {
        "type": "an",
        "class": "ea",
        "domain": "g",
    }

    elements_str = list(pyfdb_config_str.status(selection))
    elements_path = list(pyfdb_config_path.status(selection))
    elements_dict = list(pyfdb_config_dict.status(selection))

    print(elements_str)
    print(elements_dict)
    print(elements_str)

    assert all(x == y == z for (x, y, z) in zip(elements_str, elements_path, elements_dict))


def test_fdb_user_config(read_only_fdb_setup):
    user_config_str = r"""---
        type: local
        engine: toc
        useSubToc: true
        spaces:
        - roots:
          - path: "/a/path/is/something"
    """

    fdb = FDB(read_only_fdb_setup, user_config_str)
    assert fdb

    print("Check for user config propagation:")
    print(fdb.config())

    system_config, user_config = fdb.config()
    assert "useSubToc" in user_config
    assert user_config["useSubToc"] is True

    fdb_no_user_config = FDB(read_only_fdb_setup)
    print(fdb_no_user_config.config())
    print("Check for empty user config:")
    system_config_no_user_config, user_config_no_user_config = fdb_no_user_config.config()

    assert system_config == system_config_no_user_config
    assert user_config
    assert len(user_config_no_user_config) == 0


def test_fdb_print():
    fdb = FDB()

    assert fdb
    print(fdb)


def test_fdb_context():
    with FDB() as fdb:
        assert fdb
        print(fdb)