def test_extends_cache(tmpdir, monkeypatch): user_dir = tmpdir.mkdir('nix') monkeypatch.setattr(sys, 'platform', 'darwin') def mockreturn(path): return path.replace('~', str(user_dir)) monkeypatch.setattr(os.path, 'expanduser', mockreturn) local_dir = tmpdir.mkdir('local') local_dir.join('pyproject.toml').write("[tool.tidypy]\nextends = 'secondary.conf'\ntest = 'base'\nbase = 'foo'") local_dir.join('secondary.conf').write("[tidypy]\ntest = 'extended'\nextension = 'bar'") put_config_cache( 'secondary.conf', { 'tidypy': { 'test': 'cached extended', 'extension': 'cached bar', }, }, ) actual = get_project_config(str(local_dir)) assert actual['test'] == 'base' assert actual['base'] == 'foo' assert actual['extension'] == 'cached bar' actual = get_project_config(str(local_dir), use_cache=False) assert actual['test'] == 'base' assert actual['base'] == 'foo' assert actual['extension'] == 'bar'
def test_extends_multiple(tmpdir, monkeypatch): with requests_mock.Mocker() as m: m.get('https://api.github.com/repos/fake/project/contents/tidypy', json=RESP_FAKE) user_dir = tmpdir.mkdir('nix') monkeypatch.setattr(sys, 'platform', 'darwin') def mockreturn(path): return path.replace('~', str(user_dir)) monkeypatch.setattr(os.path, 'expanduser', mockreturn) local_dir = tmpdir.mkdir('local') local_dir.join('pyproject.toml').write( "[tool.tidypy]\nextends = ['secondary.conf', 'github:fake/project']\ntest = 'base'\nbase = 'foo'" ) local_dir.join('secondary.conf').write( "[tidypy]\ntest = 'extended'\nextension = 'bar'\nextends = ['deepextends']" ) actual = get_project_config(str(local_dir)) assert actual['test'] == 'base' assert actual['base'] == 'foo' assert actual['extension'] == 'bar' assert actual['extension2'] == 'baz' assert actual['extends'] == ['secondary.conf', 'github:fake/project']
def test_extends_missing(tmpdir, monkeypatch): user_dir = tmpdir.mkdir('nix') monkeypatch.setattr(sys, 'platform', 'darwin') def mockreturn(path): return path.replace('~', str(user_dir)) monkeypatch.setattr(os.path, 'expanduser', mockreturn) local_dir = tmpdir.mkdir('local') local_dir.join('pyproject.toml').write("[tool.tidypy]\nextends = ['doesntexist.conf']") with pytest.raises(DoesNotExistError): get_project_config(str(local_dir)) local_dir.join('pyproject.toml').write("[tool.tidypy]\nextends = ['doesntexist.conf']\nignore-missing-extends = true") actual = get_project_config(str(local_dir)) assert actual['extends'] == ['doesntexist.conf']
def test_get_project_config_user(tmpdir, monkeypatch): user_dir = tmpdir.mkdir('nix') user_dir.join('tidypy').write('[tidypy]\ntest = 4') monkeypatch.setattr(sys, 'platform', 'darwin') monkeypatch.setenv('XDG_CONFIG_HOME', str(user_dir)) local_dir = tmpdir.mkdir('local') actual = get_project_config(str(local_dir)) assert actual['test'] == 4
def test_get_project_config_default(tmpdir, monkeypatch): user_dir = tmpdir.mkdir('nix') monkeypatch.setattr(sys, 'platform', 'darwin') def mockreturn(path): return path.replace('~', str(user_dir)) monkeypatch.setattr(os.path, 'expanduser', mockreturn) local_dir = tmpdir.mkdir('local') actual = get_project_config(str(local_dir)) assert actual == get_default_config()
def test_get_project_config_local(tmpdir, monkeypatch): user_dir = tmpdir.mkdir('nix') user_dir.join('tidypy').write('[tidypy]\ntest = 4') monkeypatch.setattr(sys, 'platform', 'darwin') def mockreturn(path): return path.replace('~', str(user_dir)) monkeypatch.setattr(os.path, 'expanduser', mockreturn) local_dir = tmpdir.mkdir('local') local_dir.join('pyproject.toml').write('[tool.tidypy]\ntest = 5') actual = get_project_config(str(local_dir)) assert actual['test'] == 5
def test_extends_default(tmpdir, monkeypatch): user_dir = tmpdir.mkdir('nix') monkeypatch.setattr(sys, 'platform', 'darwin') def mockreturn(path): return path.replace('~', str(user_dir)) monkeypatch.setattr(os.path, 'expanduser', mockreturn) local_dir = tmpdir.mkdir('local') local_dir.join('pyproject.toml').write("[tool.tidypy]\nextends = ['secondary.conf']\ntest = 'base'\nbase = 'foo'\nalist=['a']") local_dir.join('secondary.conf').write("[tidypy]\ntest = 'extended'\nextension = 'bar'\nextends = ['deepextends']\nalist=['b','c']") actual = get_project_config(str(local_dir)) assert actual['test'] == 'base' assert actual['base'] == 'foo' assert actual['extension'] == 'bar' assert actual['extends'] == ['secondary.conf'] assert actual['alist'] == ['b', 'c', 'a']