def find_tag(matcher='v[0-9]*', strict=True, git_dir='.'): """Find closest tag for a git repository. .. note:: This defaults to `Semantic Version`_ tag matching. Args: matcher (str): Glob-style tag pattern to match strict (bool): Allow commit-ish, if no tag found git_dir (str): Repository to search Returns: Matching tag name .. _Semantic Version: http://semver.org/ """ command = 'git describe --abbrev=12 --dirty'.split() with chdir(git_dir): try: stdout = check_output(command + ['--match=%s' % matcher, ]) except CalledProcessError: if strict: raise stdout = check_output(command + ['--always', ]) if not PY2: # pragma: Python 3 stdout = stdout.decode('ascii', 'replace') return stdout.strip()
def test_chdir_missing(tmpdir): with raises(FileNotFoundError, match=escape('[Errno 2]')), \ context.chdir(tmpdir.join('missing_dir').strpath): pass
def test_chdir(tmpdir): orig = getcwd() dir_ = tmpdir.join('new').mkdir().strpath with context.chdir(dir_): assert getcwd() == dir_ assert getcwd() == orig
def test_chdir_missing(): with expect.raises(OSError), context.chdir('missing_dir'): pass
def test_chdir(): orig = getcwd() with context.chdir('tests'): expect(getcwd) != orig expect(getcwd()) == orig
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_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