Exemplo n.º 1
0
def test_embedded_dict_inside_list():
    cfg = JSONConfigFile("test_data/test.json")
    assert isinstance(cfg.config.houses, list)
    assert isinstance(cfg.config.houses[0], ConfigKey)
    assert cfg.config.houses[0].red is False
    assert cfg.config.houses[0].blue is True
    assert cfg.config.houses[1].red is True
    assert cfg.config.houses[1].blue is False
Exemplo n.º 2
0
def test_dumpd():
    cfg = JSONConfigFile("test_data/test.json")
    assert cfg.dumpd() == {
        "hello": "goodbye",
        "qaz": 1,
        "wsx": 2,
        "edc": {
            "op": 4,
            "po": 6
        },
        "fruit": ["apples", "oranges", "bananas"],
        "houses": [{
            "red": False,
            "blue": True
        }, {
            "red": True,
            "blue": False
        }]
    }
Exemplo n.º 3
0
def test_created_config_file():
    if os.path.exists("test_data/bleh.json"):
        os.remove("test_data/bleh.json")
    try:
        cfg = JSONConfigFile("test_data/bleh.json")
        # next line should happen
        parsed = True
    except:
        parsed = False
    assert parsed
    assert not cfg.config.parsed
    assert os.path.exists("test_data/bleh.json")
Exemplo n.º 4
0
def test_dumps():
    cfg = JSONConfigFile("test_data/bleh.json")
    assert cfg.dumps() == "{\"a\": 1}"
Exemplo n.º 5
0
def test_initial_populate():
    cfg = JSONConfigFile("test_data/bleh.json")
    pop = cfg.initial_populate({"a": 1})
    assert pop
    cfg.dump() and cfg.reload()
    assert cfg.config.a == 1
Exemplo n.º 6
0
def test_loading_valid_json():
    cfg = JSONConfigFile("test_data/test.json")
    assert isinstance(cfg.config, ConfigKey)
    assert cfg.config.parsed
Exemplo n.º 7
0
def test_configkey_iter():
    cfg = JSONConfigFile("test_data/test.json")
    assert set(x for x in cfg.config) == {
        "hello", "qaz", "wsx", "edc", "fruit", "houses"
    }
Exemplo n.º 8
0
def test_invalid_key_get():
    cfg = JSONConfigFile("test_data/test.json")
    assert cfg.config.q == "w"
Exemplo n.º 9
0
def test_dumps():
    cfg = JSONConfigFile("test_data/bleh.json")
    assert cfg.dumps() == "{\"a\": 1}"
Exemplo n.º 10
0
def test_unsafe_load():
    cfg = JSONConfigFile("test_data/unsafe.json")
    assert tuple(cfg.config.keys()) == ("unsafe___dict__", )
Exemplo n.º 11
0
def test_embedded_list():
    cfg = JSONConfigFile("test_data/test.json")
    assert isinstance(cfg.config.fruit, list)
    assert cfg.config.fruit[0] == "apples"
    assert cfg.config.fruit[1] == "oranges"
    assert cfg.config.fruit[2] == "bananas"
Exemplo n.º 12
0
def test_embedded_dict_getitem():
    cfg = JSONConfigFile("test_data/test.json")
    assert isinstance(cfg.config['edc'], ConfigKey)
    assert cfg.config['edc'].op == 4
    assert cfg.config['edc'].po == 6
Exemplo n.º 13
0
def test_embedded_dict():
    cfg = JSONConfigFile("test_data/test.json")
    assert isinstance(cfg.config.edc, ConfigKey)
    assert cfg.config.edc.op == 4
    assert cfg.config.edc.po == 6
Exemplo n.º 14
0
def test_dumpd():
    cfg = JSONConfigFile("test_data/test.json")
    assert cfg.dumpd() == {"hello": "goodbye", "qaz": 1, "wsx": 2, "edc": {"op": 4, "po": 6},
                                        "fruit": ["apples", "oranges", "bananas"],
                                        "houses": [{"red": False, "blue": True}, {"red": True, "blue": False}]}
Exemplo n.º 15
0
def test_invalid_json_data():
    cfg = JSONConfigFile("test_data/invalid.data")
Exemplo n.º 16
0
def test_loaded_config_item():
    cfg = JSONConfigFile("test_data/test.json")
    assert cfg.config.hello == "goodbye"
Exemplo n.º 17
0
def test_initial_populate():
    cfg = JSONConfigFile("test_data/bleh.json")
    pop = cfg.initial_populate({"a": 1})
    assert pop
    cfg.dump() and cfg.reload()
    assert cfg.config.a == 1