added config tests
This commit is contained in:
parent
6d1ace473b
commit
a95cc4e06b
@ -18,12 +18,12 @@ class DotIndexable:
|
|||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
return _get_item_and_maybe_make_dotindexable(self.x, item)
|
return _get_item_and_maybe_make_dotindexable(self.x, item)
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
|
||||||
self.x[key] = value
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.x.__repr__()
|
return self.x.__repr__()
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
return self.__getattr__(item)
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
def __init__(self, config_path):
|
def __init__(self, config_path):
|
||||||
|
|||||||
38
test/unit_tests/config_test.py
Normal file
38
test/unit_tests/config_test.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import tempfile
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from image_prediction.config import Config
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def config_file_content():
|
||||||
|
return {"A": [{"B": [1, 2]}, {"C": 3}, 4], "D": {"E": {"F": True}}}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def config(config_file_content):
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w") as f:
|
||||||
|
yaml.dump(config_file_content, f, default_flow_style=False)
|
||||||
|
yield Config(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dot_access_key_exists(config):
|
||||||
|
assert config.A == [{"B": [1, 2]}, {"C": 3}, 4]
|
||||||
|
assert config.D.E["F"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_access_key_exists(config):
|
||||||
|
assert config["A"] == [{"B": [1, 2]}, {"C": 3}, 4]
|
||||||
|
assert config["A"][0] == {"B": [1, 2]}
|
||||||
|
assert config["A"][0]["B"] == [1, 2]
|
||||||
|
assert config["A"][0]["B"][0] == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_dot_access_key_does_not_exists(config):
|
||||||
|
assert config.B is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_access_key_does_not_exists(config):
|
||||||
|
assert config["B"] is None
|
||||||
Loading…
x
Reference in New Issue
Block a user