Beispiel #1
0
def test_config_get_namespace() -> None:
    config = Config(Path(__file__).parent)
    config["FOO_A"] = "a"
    config["FOO_BAR"] = "bar"
    config["BAR"] = "bar"
    assert config.get_namespace("FOO_") == {"a": "a", "bar": "bar"}
Beispiel #2
0
def _check_standard_config(config: Config) -> None:
    assert config.pop('FOO') == 'bar'
    assert config.pop('BOB') == 'jeff'
    assert len(config) == 0
Beispiel #3
0
def test_config_from_object() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_object(__name__)
    assert config['TEST_KEY'] == 'test_value'
Beispiel #4
0
def test_config_from_toml() -> None:
    config = Config(Path(__file__).parent)
    config.from_file("assets/config.toml", toml.load)
    _check_standard_config(config)
Beispiel #5
0
def test_config_from_pyfile_directory() -> None:
    config = Config(Path(__file__).parent)
    with pytest.raises(PermissionError if os.name ==
                       'nt' else IsADirectoryError):
        config.from_pyfile('assets')
Beispiel #6
0
def test_config_from_json() -> None:
    config = Config(Path(__file__).parent)
    config.from_json('assets/config.json')
    _check_standard_config(config)
Beispiel #7
0
def test_config_from_json() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_json('assets/config.json')
    _check_standard_config(config)
Beispiel #8
0
def test_config_from_pyfile_cfg() -> None:
    config = Config(Path(__file__).parent)
    config.from_pyfile('assets/config.cfg')
    _check_standard_config(config)
Beispiel #9
0
def test_config_from_pyfile_no_file() -> None:
    config = Config(os.path.dirname(__file__))
    with pytest.raises(FileNotFoundError):
        config.from_pyfile('assets/no_file.cfg')
Beispiel #10
0
def test_config_from_envvar() -> None:
    config = Config(os.path.dirname(__file__))
    os.environ['CONFIG'] = 'assets/config.cfg'
    config.from_envvar('CONFIG')
    _check_standard_config(config)
Beispiel #11
0
def test_config_from_pyfile_cfg() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_pyfile('assets/config.cfg')
    _check_standard_config(config)
Beispiel #12
0
def test_config_from_pyfile_this() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_pyfile(__file__)
    _check_standard_config(config)
Beispiel #13
0
def test_config_from_object() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_object(__name__)
    _check_standard_config(config)
Beispiel #14
0
def test_config_from_object() -> None:
    config = Config(Path(__file__).parent)
    config.from_object(__name__)
    _check_standard_config(config)
Beispiel #15
0
def test_config_get_namespace() -> None:
    config = Config(os.path.dirname(__file__))
    config['FOO_A'] = 'a'
    config['FOO_BAR'] = 'bar'
    config['BAR'] = 'bar'
    assert config.get_namespace('FOO_') == {'a': 'a', 'bar': 'bar'}
Beispiel #16
0
def test_config_from_pyfile_this() -> None:
    config = Config(Path(__file__).parent)
    config.from_pyfile(__file__)
    _check_standard_config(config)
Beispiel #17
0
def _check_standard_config(config: Config) -> None:
    assert config.pop("FOO") == "bar"
    assert config.pop("BOB") == "jeff"
    assert len(config) == 0
Beispiel #18
0
def test_config_from_pyfile_no_file() -> None:
    config = Config(Path(__file__).parent)
    with pytest.raises(FileNotFoundError):
        config.from_pyfile('assets/no_file.cfg')
Beispiel #19
0
def test_config_from_pyfile_py() -> None:
    config = Config(Path(__file__).parent)
    config.from_pyfile("assets/config.py")
    _check_standard_config(config)
Beispiel #20
0
def test_config_from_envvar() -> None:
    config = Config(Path(__file__).parent)
    os.environ['CONFIG'] = 'assets/config.cfg'
    config.from_envvar('CONFIG')
    _check_standard_config(config)
Beispiel #21
0
def test_config_from_envvar() -> None:
    config = Config(Path(__file__).parent)
    os.environ["CONFIG"] = "assets/config.cfg"
    config.from_envvar("CONFIG")
    _check_standard_config(config)
Beispiel #22
0
def test_config_get_namespace() -> None:
    config = Config(Path(__file__).parent)
    config['FOO_A'] = 'a'
    config['FOO_BAR'] = 'bar'
    config['BAR'] = 'bar'
    assert config.get_namespace('FOO_') == {'a': 'a', 'bar': 'bar'}
Beispiel #23
0
def test_config_from_pyfile_directory() -> None:
    config = Config(os.path.dirname(__file__))
    with pytest.raises(IsADirectoryError):
        config.from_pyfile('assets')