def test_psys_neither(capsys): """ Test routine psys with dryrun False and quiet False. """ pytest.dbgfunc() root = tbx.dirname(os.path.abspath(__file__), level=2) v = {'-n': False, '-q': False} expected = "ls -d %s/fx\n%s/fx\n" % (root, root) fx.psys('ls -d %s/fx' % root, v) assert expected in " ".join(capsys.readouterr())
def test_dirname(level): """ Default level for dirname is 0 """ pytest.dbgfunc() inp = '/a/b/c/d/e' exp = inp[:] if level is None: exp = os.path.dirname(exp) else: for _ in range(level): exp = os.path.dirname(exp) result = tbx.dirname(inp, level=level) assert result == exp
def gitr_bv(opts): """bv - bump version If multiple matches are found, only the first is updated """ for a, b in [('--major', '--minor'), ('--major', '--patch'), ('--major', '--build'), ('--minor', '--patch'), ('--minor', '--build'), ('--patch', '--build'), ]: if opts.get(a, False) and opts.get(b, False): sys.exit('{0} and {1} are mutually exclusive'.format(a, b)) tl = [] target = opts.get('<path>', 'version.py') or 'version.py' if not os.path.exists(target): if '/' in target: td = tbx.dirname(target) if not os.path.exists(td): os.makedirs(td) version_update(target, ['0', '0', '0']) if opts.get('-q', False) or opts.get('--quiet', False): msg = "" else: msg = "{0} is not in git -- no diff available".format(target) sys.exit(msg) else: for r,d,f in os.walk('.'): if target in f: tl.append(os.path.join(r, target)) if tl == []: sys.exit('{0} not found'.format(target)) target = tl[0] try: repo_root = find_repo_root() repo = git.Repo(repo_root) # compute the target path relative to the repo root repo_rel_target = os.path.relpath(os.path.abspath(target), repo_root) s = repo.git.status(repo_rel_target, porc=True) if s.strip() != '': sys.exit('{0} is already bumped'.format(repo_rel_target)) except git.InvalidGitRepositoryError: sys.exit('{0} is not in a git repo'.format(target)) with open(target, 'r') as f: content = f.read() q = re.findall(r'(\d+\.\d+\.\d+\.?\w*)', content) try: v = q[0] except NameError: sys.exit("No version found in {0} ['{1}']".format(target, content)) except IndexError: sys.exit("No version found in {0} ['{1}']".format(target, content)) iv = v.split('.') ov = version_increment(iv, opts) version_update(target, ov, iv) if not opts.get('-q', False) and not opts.get('--quiet', False): version_diff(repo, repo_rel_target)
def gitr_bv(opts): """bv - bump version If multiple matches are found, only the first is updated """ for a, b in [ ('--major', '--minor'), ('--major', '--patch'), ('--major', '--build'), ('--minor', '--patch'), ('--minor', '--build'), ('--patch', '--build'), ]: if opts.get(a, False) and opts.get(b, False): sys.exit('{0} and {1} are mutually exclusive'.format(a, b)) tl = [] target = opts.get('<path>', 'version.py') or 'version.py' if not os.path.exists(target): if '/' in target: td = tbx.dirname(target) if not os.path.exists(td): os.makedirs(td) version_update(target, ['0', '0', '0']) if opts.get('-q', False) or opts.get('--quiet', False): msg = "" else: msg = "{0} is not in git -- no diff available".format(target) sys.exit(msg) else: for r, d, f in os.walk('.'): if target in f: tl.append(os.path.join(r, target)) if tl == []: sys.exit('{0} not found'.format(target)) target = tl[0] try: repo_root = find_repo_root() repo = git.Repo(repo_root) # compute the target path relative to the repo root repo_rel_target = os.path.relpath(os.path.abspath(target), repo_root) s = repo.git.status(repo_rel_target, porc=True) if s.strip() != '': sys.exit('{0} is already bumped'.format(repo_rel_target)) except git.InvalidGitRepositoryError: sys.exit('{0} is not in a git repo'.format(target)) with open(target, 'r') as f: content = f.read() q = re.findall(r'(\d+\.\d+\.\d+\.?\w*)', content) try: v = q[0] except NameError: sys.exit("No version found in {0} ['{1}']".format(target, content)) except IndexError: sys.exit("No version found in {0} ['{1}']".format(target, content)) iv = v.split('.') ov = version_increment(iv, opts) version_update(target, ov, iv) if not opts.get('-q', False) and not opts.get('--quiet', False): version_diff(repo, repo_rel_target)
def test_dirname(arg, kw, exp): """ Test tbx.dirname() """ pytest.dbgfunc() assert tbx.dirname(*arg, **kw) == exp