def test_setdefault(self) -> None: """Test Namespace.setdefault().""" ns = Namespace() for key, value in zip(KEYS, VALUES): ns.setdefault(key, value) assert list(ns.keys()) == list(DATA.keys()) assert list(ns.values()) == list(DATA.values())
def test_update_simple(self) -> None: """Test Namespace.update() behavior""" ns = Namespace() for i, (key, value) in enumerate(DATA.items()): ns.update({key: value}) assert list(ns.keys()) == list(DATA.keys()) assert list(ns.values()) == list(DATA.values())
def test_set(self) -> None: """Test Namespace[] setter.""" ns = Namespace() for key, value in zip(KEYS, VALUES): ns[key] = value assert list(ns.keys()) == list(DATA.keys()) assert list(ns.values()) == list(DATA.values())
def test_init(self) -> None: """Test initialization.""" # test namespaces ns_a = Namespace(TEST_DICT) ns_b = Namespace.from_toml(StringIO(TEST_TOML)) ns_c = Namespace.from_yaml(StringIO(TEST_YAML)) ns_d = Namespace.from_json(StringIO(TEST_JSON)) # initialize construction results in member namespaces cfg = Configuration(A=ns_a, B=ns_b) assert dict(cfg) == cfg.namespaces['A'] == ns_a == cfg.namespaces['B'] == ns_b # extend the configuration cfg.extend(C=ns_c, D=ns_d) assert (cfg.namespaces['A'] == ns_a == cfg.namespaces['B'] == ns_b == cfg.namespaces['C'] == ns_c == cfg.namespaces['D'] == ns_d == dict(cfg)) # keys() and values() are available assert list(cfg.keys()) == list(ns_a.keys()) assert list(cfg.values()) == list(ns_a.values())