示例#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"}
示例#2
0
def _check_standard_config(config: Config) -> None:
    assert config.pop('FOO') == 'bar'
    assert config.pop('BOB') == 'jeff'
    assert len(config) == 0
示例#3
0
def test_config_from_object() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_object(__name__)
    assert config['TEST_KEY'] == 'test_value'
示例#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)
示例#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')
示例#6
0
def test_config_from_json() -> None:
    config = Config(Path(__file__).parent)
    config.from_json('assets/config.json')
    _check_standard_config(config)
示例#7
0
def test_config_from_json() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_json('assets/config.json')
    _check_standard_config(config)
示例#8
0
def test_config_from_pyfile_cfg() -> None:
    config = Config(Path(__file__).parent)
    config.from_pyfile('assets/config.cfg')
    _check_standard_config(config)
示例#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')
示例#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)
示例#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)
示例#12
0
def test_config_from_pyfile_this() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_pyfile(__file__)
    _check_standard_config(config)
示例#13
0
def test_config_from_object() -> None:
    config = Config(os.path.dirname(__file__))
    config.from_object(__name__)
    _check_standard_config(config)
示例#14
0
def test_config_from_object() -> None:
    config = Config(Path(__file__).parent)
    config.from_object(__name__)
    _check_standard_config(config)
示例#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'}
示例#16
0
def test_config_from_pyfile_this() -> None:
    config = Config(Path(__file__).parent)
    config.from_pyfile(__file__)
    _check_standard_config(config)
示例#17
0
def _check_standard_config(config: Config) -> None:
    assert config.pop("FOO") == "bar"
    assert config.pop("BOB") == "jeff"
    assert len(config) == 0
示例#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')
示例#19
0
def test_config_from_pyfile_py() -> None:
    config = Config(Path(__file__).parent)
    config.from_pyfile("assets/config.py")
    _check_standard_config(config)
示例#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)
示例#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)
示例#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'}
示例#23
0
def test_config_from_pyfile_directory() -> None:
    config = Config(os.path.dirname(__file__))
    with pytest.raises(IsADirectoryError):
        config.from_pyfile('assets')