Exemple #1
0
 def test_performance(self):
     cfg = LConfig()
     for i in range(1000):
         key = f"key_{i}"
         value = f"value for {i}"
         cfg[key] = value
     for key, value in cfg.items():
         assert isinstance(key, str)
Exemple #2
0
 def test_setitem(self):
     cfg = LConfig().read_data(TESTDATA)
     proxy = LConfigProxy(cfg, prefix="namespace.")
     proxy["d"] = "dee"
     assert proxy["d"] == "dee"
     with pytest.raises(ValueError):
         proxy["  e   "] = "ee"
Exemple #3
0
 def test_setattr_error(self):
     cfg = LConfig()
     proxy = cfg["namespace."]
     with pytest.raises(AttributeError):
         proxy.a = "b"
Exemple #4
0
 def test_setattr(self):
     cfg = LConfig()
     cfg["a"] = "a"
     assert cfg.a == "a"
     cfg.a = "b"
     assert cfg.a == "b"
Exemple #5
0
 def test_setitem_error(self):
     cfg = LConfig().read_data(TESTDATA)
     proxy = LConfigProxy(cfg, prefix="namespace.")
     with pytest.raises(ValueError):
         proxy["§$%§d"] = "dee"
Exemple #6
0
 def test_read_file(self, testfile):
     cfg = LConfig()
     cfg.read_file(testfile)
     assert cfg.key == "value"
Exemple #7
0
 def test_assign_proxy(self):
     cfg = LConfig()
     proxy = cfg["section."]
     proxy["a"] = 5
     assert cfg["section.a"] == "5"
Exemple #8
0
 def test_read_data(self):
     cfg = LConfig()
     cfg.read_data(TESTDATA.splitlines())
     assert cfg.key == "value"
     cfg = LConfig()
     cfg.read_data(io.StringIO(TESTDATA))
     assert cfg.key == "value"
     cfg = LConfig()
     cfg.read_data(TESTDATA)
     assert cfg.key == "value"
Exemple #9
0
 def test_write_data(self):
     cfg = LConfig()
     cfg["key"] = "value"
     output = io.StringIO()
     cfg.write_data(output)
     assert output.getvalue() == "key = value\n"
Exemple #10
0
 def test_setitem(self):
     cfg = LConfig()
     cfg["adf"] = "my value"
     assert cfg["adf"] == "my value"
Exemple #11
0
 def test_read_dict_list(self):
     cfg = LConfig()
     cfg.read_dict({"a": ["1", "2"], "b": ["eins", "zwei"]})
     assert cfg["a"] == "2"
     assert cfg["b"] == "zwei"
     assert cfg.get_raw("a") == ["1", "2"]
Exemple #12
0
 def test_read_dict_level(self):
     cfg = LConfig()
     cfg.read_dict({"a": {"1": "one", "2": "two"}})
     assert cfg["a.1"] == "one"
     assert cfg["a.2"] == "two"
Exemple #13
0
 def test_read_dict(self):
     cfg = LConfig()
     cfg.read_dict({"a": "b"})
     assert cfg["a"] == "b"
Exemple #14
0
 def test_read_data(self):
     cfg = LConfig()
     proxy = LConfigProxy(cfg, prefix="namespace.")
     proxy.read_data("key = value")
     assert proxy.key == "value"
     assert list(proxy) == ["key"]
Exemple #15
0
 def test_resolve_name(self):
     TESTDATA = """
     .test. = l0
     .test.l1. = l1
     .test.l.l2. = l2
     .test.s.l1 = lvl1
     """
     cfg = LConfig()
     cfg.read_data(io.StringIO(TESTDATA))
     name = cfg.resolve_name(key="", prefix="", default="")
     assert name == ""
     name = cfg.resolve_name(key="", prefix="", default="d")
     assert name == "d"
     name = cfg.resolve_name(key="d", prefix="", default=None)
     assert name is None
     assert cfg.resolve_name("key.a", ".test") == "l0"
     assert cfg.resolve_name("key.a.b.c", ".test") == "l0"
     assert cfg.resolve_name("l1.a", ".test") == "l1"
     assert cfg.resolve_name("l1.a.b.c", ".test") == "l1"
     assert cfg.resolve_name("l.l2.a", ".test") == "l2"
     assert cfg.resolve_name("l.l2.a.b.c", ".test") == "l2"
     assert cfg.resolve_name("s.l1", ".test") == "lvl1"
     assert cfg.resolve_name("s.l1.5", ".test") == "l0"
     assert cfg.resolve_name("z.l1.5", ".testoff", "default") == "default"
Exemple #16
0
def cfg():
    cfg = LConfig()
    cfg.read_data(TESTDATA.splitlines())
    yield cfg
Exemple #17
0
 def test_init(self):
     cfg = LConfig()
     assert len(cfg) == 0