def test_no_git(monkeypatch): def mockreturn(program_name): return None monkeypatch.setattr(programs, 'find_program', mockreturn) branch_tags, branch, files_modified = get_git_refs(__file__) assert len(branch_tags) == 0 assert branch == '' assert len(files_modified) == 0
def test_get_git_refs(): branch_tags, branch, files_modified = get_git_refs(__file__) assert bool(branch) # This must always return a branch_name assert len(files_modified) >= 0 # It seems when Travis run tests on tags, master doesn't # appear among the list of git branches. if not os.environ.get('TRAVIS_TAG'): assert any(['master' in b for b in branch_tags])
def update_vcs(self, fname, index): """Update vcs status.""" fpath = os.path.dirname(fname) branches, branch, files_modified = get_git_refs(fpath) text = branch if branch else '' if len(files_modified): text = text + ' [{}]'.format(len(files_modified)) self.setVisible(bool(branch)) self.set_value(text)
def test_get_git_refs(): branch_tags, branch, files_modified = get_git_refs(__file__) assert bool(branch) # This must always return a branch_name assert len(files_modified) >= 0 assert any([('master' in b or '4.x' in b) for b in branch_tags])
def get_git_refs(self, fname): """Get Git active branch, state, branches (plus tags).""" return get_git_refs(osp.dirname(fname))