Ejemplo n.º 1
0
def test_config_loading(local, count):
    with patch_env({"XDG_CONFIG_DIRS": "test1:test2"}):
        cfg = config.read_configs("jnrbase", local=local)
    expect(len(cfg.configs)) == count
    if local:
        expect(cfg.configs[-1]).contains("/.jnrbaserc")
    else:
        expect(cfg.configs).does_not_contain("/.jnrbaserc")
Ejemplo n.º 2
0
def test_config_loading(local, count, monkeypatch, path_exists_force):
    monkeypatch.setattr('builtins.open', lambda s, encoding: StringIO(''))
    monkeypatch.setenv('XDG_CONFIG_DIRS', 'test1:test2')
    cfg = config.read_configs('jnrbase', local=local)
    assert len(cfg.configs) == count
    if local:
        assert '/.jnrbaserc' in cfg.configs[-1]
    else:
        assert '/.jnrbaserc' not in cfg.configs
Ejemplo n.º 3
0
def config_(name: str, local: bool, package: str, section: str,
            key: Optional[str]):
    """Extract or list values from config."""
    cfg = config.read_configs(package, name, local=local)
    if key:
        with suppress(NoOptionError, NoSectionError):
            echo(cfg.get(section, key))
    else:
        with suppress(NoSectionError):
            for opt in cfg.options(section):
                colourise.pinfo(opt)
                echo('    {}'.format(cfg.get(section, opt)))
Ejemplo n.º 4
0
def test_colour_from_config():
    with chdir("tests/data/config"), patch_env(clear=True):
        cfg = config.read_configs("jnrbase", local=True)
    expect(cfg.colour) is False
Ejemplo n.º 5
0
def test_colour_default():
    with patch_env(clear=True):
        cfg = config.read_configs("jnrbase")
    expect(cfg.colour) is True
Ejemplo n.º 6
0
def test_no_colour_from_env():
    with patch_env({"NO_COLOUR": "set"}):
        cfg = config.read_configs("jnrbase")
    expect(cfg.colour) is False
Ejemplo n.º 7
0
def test_config_loading_missing_files():
    expect(config.read_configs("jnrbase").configs) == []
Ejemplo n.º 8
0
def test_colour_from_config(directory, monkeypatch):
    monkeypatch.setattr('os.environ', {})
    with chdir('tests/data/{}'.format(directory)):
        cfg = config.read_configs('jnrbase', local=True)
    assert not cfg.colour
Ejemplo n.º 9
0
def test_colour_default(monkeypatch):
    monkeypatch.setattr('os.environ', {})
    cfg = config.read_configs('jnrbase')
    assert cfg.colour
Ejemplo n.º 10
0
def test_no_colour_from_env(envvar, monkeypatch):
    monkeypatch.setenv(envvar, 'set')
    cfg = config.read_configs('jnrbase')
    assert not cfg.colour
Ejemplo n.º 11
0
def test_config_loading_missing_files(path_exists_force):
    assert config.read_configs('jnrbase').configs == []