def test_factories(self) -> None: """Test all implemented factory equivalents.""" # write all test data to local files for ftype, data in FACTORIES.items(): with open(f'{TMPDIR}/{ftype}.{ftype}', mode='w') as output: output.write(data) # test both file-like object and file path modes of construction assert (Namespace(TEST_DICT) == Namespace.from_toml(StringIO(TEST_TOML)) == Namespace.from_toml(f'{TMPDIR}/toml.toml') == Namespace.from_yaml(StringIO(TEST_YAML)) == Namespace.from_yaml(f'{TMPDIR}/yaml.yaml') == Namespace.from_json(StringIO(TEST_JSON)) == Namespace.from_json(f'{TMPDIR}/json.json'))
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())