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")
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
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)))
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
def test_colour_default(): with patch_env(clear=True): cfg = config.read_configs("jnrbase") expect(cfg.colour) is True
def test_no_colour_from_env(): with patch_env({"NO_COLOUR": "set"}): cfg = config.read_configs("jnrbase") expect(cfg.colour) is False
def test_config_loading_missing_files(): expect(config.read_configs("jnrbase").configs) == []
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
def test_colour_default(monkeypatch): monkeypatch.setattr('os.environ', {}) cfg = config.read_configs('jnrbase') assert cfg.colour
def test_no_colour_from_env(envvar, monkeypatch): monkeypatch.setenv(envvar, 'set') cfg = config.read_configs('jnrbase') assert not cfg.colour
def test_config_loading_missing_files(path_exists_force): assert config.read_configs('jnrbase').configs == []