示例#1
0
文件: test_gitr.py 项目: tbarron/gitr
def already_setup(tmpdir, request):
    """
    Setup for 'already_staged' tests
    """
    pytest.this = {}
    rname = request.function.__name__
    target = {'test_bv_already_staged_default': 'version.py',
              'test_bv_already_staged_explicit': 'boodle',
              'test_bv_already_staged_deep': 'sub1/sub2/version.py',
              'test_bv_already_bumped_default': 'version.py',
              'test_bv_already_bumped_explicit': 'frobnicate',
              'test_bv_already_bumped_deep': 'sub1/sub2/version.py',
              'test_bv_already_bumped_deep2': 'sub1/sub2/version.py',
              }[rname]
    pytest.this['target'] = target
    t = tmpdir.join(target)
    t.ensure()
    with tbx.chdir(tmpdir.strpath):
        # init the repo
        r = git.Repo.init(tmpdir.strpath)
        # create the first target and commit it
        t.write('__version__ = "0.0.0"\n')
        r.git.add(target)
        r.git.commit(a=True, m='First commit')
        # update target and (maybe) stage the update
        t.write('__version__ = "0.0.0.1"\n')
        if 'staged' in rname:
            r.git.add(target)
示例#2
0
文件: test_gitr.py 项目: tbarron/gitr
def test_find_repo_root_deep(repo_setup, tmpdir):
    """
    repo is several levels up
    """
    sub = tmpdir.join('a/b/c').ensure(dir=True)
    with tbx.chdir(sub.strpath):
        assert tmpdir.strpath == gitr.find_repo_root()
示例#3
0
文件: test_gitr.py 项目: tbarron/gitr
def test_find_repo_root_not(tmpdir):
    """
    Not in a repo
    """
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(git.InvalidGitRepositoryError):
            gitr.find_repo_root()
示例#4
0
文件: test_gitr.py 项目: tbarron/gitr
def test_find_repo_root_deep(repo_setup, tmpdir):
    """
    repo is several levels up
    """
    sub = tmpdir.join('a/b/c').ensure(dir=True)
    with tbx.chdir(sub.strpath):
        assert tmpdir.strpath == gitr.find_repo_root()
示例#5
0
文件: test_gitr.py 项目: tbarron/gitr
def already_setup(tmpdir, request):
    """
    Setup for 'already_staged' tests
    """
    pytest.this = {}
    rname = request.function.__name__
    target = {
        'test_bv_already_staged_default': 'version.py',
        'test_bv_already_staged_explicit': 'boodle',
        'test_bv_already_staged_deep': 'sub1/sub2/version.py',
        'test_bv_already_bumped_default': 'version.py',
        'test_bv_already_bumped_explicit': 'frobnicate',
        'test_bv_already_bumped_deep': 'sub1/sub2/version.py',
        'test_bv_already_bumped_deep2': 'sub1/sub2/version.py',
    }[rname]
    pytest.this['target'] = target
    t = tmpdir.join(target)
    t.ensure()
    with tbx.chdir(tmpdir.strpath):
        # init the repo
        r = git.Repo.init(tmpdir.strpath)
        # create the first target and commit it
        t.write('__version__ = "0.0.0"\n')
        r.git.add(target)
        r.git.commit(a=True, m='First commit')
        # update target and (maybe) stage the update
        t.write('__version__ = "0.0.0.1"\n')
        if 'staged' in rname:
            r.git.add(target)
示例#6
0
文件: test_gitr.py 项目: tbarron/gitr
def test_find_repo_root_not(tmpdir):
    """
    Not in a repo
    """
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(git.InvalidGitRepositoryError):
            gitr.find_repo_root()
示例#7
0
文件: test_tbx.py 项目: tbarron/gitr
def test_chdir(tmpdir):
    """
    Test the chdir contextmanager
    """
    pytest.dbgfunc()
    here = os.getcwd()
    with tbx.chdir(tmpdir.strpath):
        assert os.getcwd() == tmpdir.strpath
    assert os.getcwd() == here
示例#8
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_on_tns(tmpdir):
    """
    old is None, target does not exist
    exp: write standard version expression to target
    """
    pytest.dbgfunc()
    trg = tmpdir.join('version.py')
    v = '9.8.7'
    with tbx.chdir(tmpdir.strpath):
        gitr.version_update(trg.strpath, v.split('.'))
    assert tbx.contents(trg.strpath) == "__version__ = '{0}'\n".format(v)
示例#9
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_on_tns(tmpdir):
    """
    old is None, target does not exist
    exp: write standard version expression to target
    """
    pytest.dbgfunc()
    trg = tmpdir.join('version.py')
    v = '9.8.7'
    with tbx.chdir(tmpdir.strpath):
        gitr.version_update(trg.strpath, v.split('.'))
    assert tbx.contents(trg.strpath) == "__version__ = '{0}'\n".format(v)
示例#10
0
文件: test_tbx.py 项目: tbarron/gitr
def test_chdir_nosuch(tmpdir):
    """
    Test the chdir contextmanager when a non-existent directory is named
    """
    pytest.dbgfunc()
    here = os.getcwd()
    badtarg = tmpdir.join('nosuch')
    with pytest.raises(OSError) as e:
        with tbx.chdir(badtarg.strpath):
            assert os.getcwd() == tmpdir.strpath
    assert 'No such file or directory' in str(e)
    assert os.getcwd() == here
示例#11
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_nofile_noarg(basic, tmpdir):
    """
    pre: nothing
    gitr bv
    post: exception('version.py not found')
    """
    bf = pytest.basic_fx
    with tbx.chdir(tmpdir.strpath):
        r = git.Repo.init(tmpdir.strpath)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True})
    assert bf['notfound'].format(bf['defname']) in str(e)
示例#12
0
文件: test_tbx.py 项目: tbarron/gitr
def test_chdir_isfile(tmpdir):
    """
    Test the chdir contextmanager when a file is named
    """
    pytest.dbgfunc()
    here = os.getcwd()
    thisfile = tmpdir.join('thisfile').ensure()
    with pytest.raises(OSError) as e:
        with tbx.chdir(thisfile.strpath):
            assert os.getcwd() == thisfile.strpath
    assert 'Not a directory' in str(e)
    assert os.getcwd() == here
示例#13
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_nofile_noarg(basic, tmpdir):
    """
    pre: nothing
    gitr bv
    post: exception('version.py not found')
    """
    bf = pytest.basic_fx
    with tbx.chdir(tmpdir.strpath):
        r = git.Repo.init(tmpdir.strpath)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True})
    assert bf['notfound'].format(bf['defname']) in str(e)
示例#14
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_already_staged_explicit(basic, tmpdir, already_setup):
    """
    If an explicit target is already staged, don't update it
    """
    bf = pytest.basic_fx
    v = pytest.this['target']
    with tbx.chdir(tmpdir.strpath):
        pre = tbx.contents(v)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': v})
        post = tbx.contents(v)
    assert bf['already'].format(v) in str(e)
    assert pre == post
示例#15
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_norepo(basic, tmpdir):
    """
    pre: nothing
    gitr bv
    post: exception('version.py is not in a git repo')
    """
    bf = pytest.basic_fx
    v = tmpdir.join(bf['defname'])
    with tbx.chdir(tmpdir.strpath):
        v.write(bf['template'].format('0.0.0'))
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True})
    assert bf['notrepo'].format(bf['defname']) in str(e)
示例#16
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_nofile_major_fn(basic, tmpdir):
    """
    pre: nothing
    gitr bv --major frooble
    post: exception('frooble not found')
    """
    bf = pytest.basic_fx
    vname = 'frooble'
    with tbx.chdir(tmpdir.strpath):
        r = git.Repo.init(tmpdir.strpath)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '--major': True, '<path>': vname})
        assert bf['notfound'].format(vname) in str(e)
示例#17
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_nofile_major_fn(basic, tmpdir):
    """
    pre: nothing
    gitr bv --major frooble
    post: exception('frooble not found')
    """
    bf = pytest.basic_fx
    vname = 'frooble'
    with tbx.chdir(tmpdir.strpath):
        r = git.Repo.init(tmpdir.strpath)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '--major': True, '<path>': vname})
        assert bf['notfound'].format(vname) in str(e)
示例#18
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_already_bumped_default(basic, tmpdir, already_setup):
    """
    If 'version.py' is already bumped, don't update it
    """
    bf = pytest.basic_fx
    v = pytest.this['target']
    with tbx.chdir(tmpdir.strpath):
        pre = tbx.contents(v)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': None})
        post = tbx.contents(v)
    assert bf['already'].format(v) in str(e)
    assert pre == post
示例#19
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_patch_build(basic, tmpdir):
    """
    pre: nothing
    gitr bv --patch --build
    post: exception('--patch and --build are mutually exclusive')
    """
    bf = pytest.basic_fx
    mx_opt1, mx_opt2 = '--patch', '--build'
    exp = bf['mutex'].format(mx_opt1, mx_opt2)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({mx_opt1: True, mx_opt2: True})
        assert exp in str(e)
示例#20
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_already_staged_explicit(basic, tmpdir, already_setup):
    """
    If an explicit target is already staged, don't update it
    """
    bf = pytest.basic_fx
    v = pytest.this['target']
    with tbx.chdir(tmpdir.strpath):
        pre = tbx.contents(v)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': v})
        post = tbx.contents(v)
    assert bf['already'].format(v) in str(e)
    assert pre == post
示例#21
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_major_minor(basic, tmpdir, repo_setup):
    """
    pre: nothing
    gitr bv --major --minor
    post: exception('--major and --minor are mutually exclusive')
    """
    bf = pytest.basic_fx
    mx_opt1, mx_opt2 = '--major', '--minor'
    exp = bf['mutex'].format(mx_opt1, mx_opt2)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({mx_opt1: True, mx_opt2: True})
        assert exp in str(e)
示例#22
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_already_bumped_default(basic, tmpdir, already_setup):
    """
    If 'version.py' is already bumped, don't update it
    """
    bf = pytest.basic_fx
    v = pytest.this['target']
    with tbx.chdir(tmpdir.strpath):
        pre = tbx.contents(v)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': None})
        post = tbx.contents(v)
    assert bf['already'].format(v) in str(e)
    assert pre == post
示例#23
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_norepo(basic, tmpdir):
    """
    pre: nothing
    gitr bv
    post: exception('version.py is not in a git repo')
    """
    bf = pytest.basic_fx
    v = tmpdir.join(bf['defname'])
    with tbx.chdir(tmpdir.strpath):
        v.write(bf['template'].format('0.0.0'))
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True})
    assert bf['notrepo'].format(bf['defname']) in str(e)
示例#24
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_major_minor(basic, tmpdir, repo_setup):
    """
    pre: nothing
    gitr bv --major --minor
    post: exception('--major and --minor are mutually exclusive')
    """
    bf = pytest.basic_fx
    mx_opt1, mx_opt2 = '--major', '--minor'
    exp = bf['mutex'].format(mx_opt1, mx_opt2)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({mx_opt1: True, mx_opt2: True})
        assert exp in str(e)
示例#25
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_patch_build(basic, tmpdir):
    """
    pre: nothing
    gitr bv --patch --build
    post: exception('--patch and --build are mutually exclusive')
    """
    bf = pytest.basic_fx
    mx_opt1, mx_opt2 = '--patch', '--build'
    exp = bf['mutex'].format(mx_opt1, mx_opt2)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({mx_opt1: True, mx_opt2: True})
        assert exp in str(e)
示例#26
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_already_bumped_deep2(basic, tmpdir, already_setup):
    """
    If 'version.py' is already bumped, don't update it
    """
    pytest.dbgfunc()
    bf = pytest.basic_fx
    v = tmpdir.join(pytest.this['target'])
    with tbx.chdir(v.dirname):
        pre = tbx.contents(v.basename)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': None})
        post = tbx.contents(v.basename)
    assert bf['already'].format(pytest.this['target']) in str(e)
    assert pre == post
示例#27
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_already_bumped_deep2(basic, tmpdir, already_setup):
    """
    If 'version.py' is already bumped, don't update it
    """
    pytest.dbgfunc()
    bf = pytest.basic_fx
    v = tmpdir.join(pytest.this['target'])
    with tbx.chdir(v.dirname):
        pre = tbx.contents(v.basename)
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': None})
        post = tbx.contents(v.basename)
    assert bf['already'].format(pytest.this['target']) in str(e)
    assert pre == post
示例#28
0
文件: test_tbx.py 项目: tbarron/gitr
def test_chdir_perm(tmpdir):
    """
    Test the chdir contextmanager when chdir is not allowed
    """
    pytest.dbgfunc()
    here = os.getcwd()
    thisdir = tmpdir.join('thisdir').ensure(dir=True)
    thisdir.chmod(0000)
    with pytest.raises(OSError) as e:
        with tbx.chdir(thisdir.strpath):
            assert os.getcwd() == thisfile.strpath
    assert 'Permission denied' in str(e)
    thisdir.chmod(0755)
    assert os.getcwd() == here
示例#29
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_os_tmt(tmpdir):
    """
    old is not None, target is empty
    exp: 'Can't update '<olds>' in an empty file'
    """
    pytest.dbgfunc()
    trg = tmpdir.join('version.py')
    oldv, newv = '9.8.6', '9.8.7'
    trg.write('')
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.version_update(trg.strpath, newv.split('.'), oldv.split('.'))
        assert ''.join(["Can't update '", oldv,
                        "' in an empty file"]) in str(e)
示例#30
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_os_tfl_op(tmpdir):
    """
    old is not None, target is not empty, old IS in target, non-standard
    exp: <olds> replaced with <news> in non-standard expression
    """
    pytest.dbgfunc()
    oldv, newv = '7.3.2.32', '7.3.2.33'
    trg = tmpdir.join('fooble-de-bar')

    t = '"{0}" is the version\n'
    (pre, post) = (t.format(_) for _ in [oldv, newv])
    trg.write(pre)
    with tbx.chdir(tmpdir.strpath):
        gitr.version_update(trg.basename, newv.split('.'), oldv.split('.'))
        assert post in tbx.contents(trg.basename)
示例#31
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_os_tmt(tmpdir):
    """
    old is not None, target is empty
    exp: 'Can't update '<olds>' in an empty file'
    """
    pytest.dbgfunc()
    trg = tmpdir.join('version.py')
    oldv, newv = '9.8.6', '9.8.7'
    trg.write('')
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.version_update(trg.strpath, newv.split('.'), oldv.split('.'))
        assert ''.join(["Can't update '",
                        oldv,
                        "' in an empty file"]) in str(e)
示例#32
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_nofile_patch(basic, tmpdir, repo_setup):
    """
    pre: nothing
    gitr bv --patch
    post: exception('version.py not found')
    """
    bf = pytest.basic_fx
    v = pytest.this['vname']
    v.remove()
    q = pytest.this['q']
    q['foo/bar/version.py']['locpath'].remove()
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'--patch': True})
        assert bf['notfound'].format(v.basename) in str(e)
示例#33
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_os_tfl_op(tmpdir):
    """
    old is not None, target is not empty, old IS in target, non-standard
    exp: <olds> replaced with <news> in non-standard expression
    """
    pytest.dbgfunc()
    oldv, newv = '7.3.2.32', '7.3.2.33'
    trg = tmpdir.join('fooble-de-bar')

    t = '"{0}" is the version\n'
    (pre, post) = (t.format(_) for _ in [oldv, newv])
    trg.write(pre)
    with tbx.chdir(tmpdir.strpath):
        gitr.version_update(trg.basename, newv.split('.'), oldv.split('.'))
        assert post in tbx.contents(trg.basename)
示例#34
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_nofile_patch(basic, tmpdir, repo_setup):
    """
    pre: nothing
    gitr bv --patch
    post: exception('version.py not found')
    """
    bf = pytest.basic_fx
    v = pytest.this['vname']
    v.remove()
    q = pytest.this['q']
    q['foo/bar/version.py']['locpath'].remove()
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'--patch': True})
        assert bf['notfound'].format(v.basename) in str(e)
示例#35
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_on_tfl(tmpdir):
    """
    old is None, target is not empty
    exp: 'Don't know where to put '<news>' in '<c>''
    """
    pytest.dbgfunc()
    trg = tmpdir.join('version.py')
    nov = 'The quick brown fox and all that'
    trg.write(nov)
    v = '9.8.7'
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.version_update(trg.strpath, v.split('.'))
        assert ''.join(["Don't know where to put '", v, "' in '", nov,
                        "'"]) in str(e)
示例#36
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_major_4(basic, tmpdir, capsys, repo_setup):
    """
    pre: '1.0.0.17' in version.py
    gitr bv --major
    post: '2.0.0' in version.py
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    v = pytest.this['vname']
    pre, post = '1.0.0.17', '2.0.0'
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='set version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--major': True, '<path>': v.basename})
        bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
    assert bf['template'].format(post) in v.read()
示例#37
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_patch_4(basic, tmpdir, capsys, repo_setup):
    """
    pre: '1.3.2.7' in version.py
    gitr bv --patch
    post: '1.3.3' in version.py
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    v = pytest.this['vname']
    pre, post = "1.3.2.7", "1.3.3"
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--patch': True})
        bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
    assert bf['template'].format(post) in v.read()
示例#38
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_major_3_fn(basic, tmpdir, capsys, repo_setup):
    """
    pre: '7.4.3' in splack
    gitr bv --major splack
    post: '8.0.0' in splack
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    o = pytest.this['other']
    pre, post = "7.4.3", "8.0.0"
    o.write("__version__ = '{0}'\n".format(pre))
    r.git.commit(a=True, m='set a version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--major': True, '<path>': o.basename})
    assert bf['template'].format(post) in o.read()
    bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
示例#39
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_patch_4(basic, tmpdir, capsys, repo_setup):
    """
    pre: '1.3.2.7' in version.py
    gitr bv --patch
    post: '1.3.3' in version.py
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    v = pytest.this['vname']
    pre, post = "1.3.2.7", "1.3.3"
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--patch': True})
        bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
    assert bf['template'].format(post) in v.read()
示例#40
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_patch_3(basic, tmpdir, repo_setup, capsys):
    """
    pre: '1.3.2' in version.py
    gitr bv --patch
    post: '1.3.3' in version.py
    """
    bf = pytest.basic_fx
    pre, post = '1.3.2', '1.3.3'
    r = pytest.this['repo']
    v = pytest.this['vname']
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--patch': True, '-q': True})
        o, e = capsys.readouterr()
        assert o.strip() == ""
    assert bf['template'].format(post) in v.read()
示例#41
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_noarg_4(basic, tmpdir, capsys):
    """
    pre: 2.7.3.8 in version.py
    gitr bv
    post: 2.7.3.9 in version.py
    """
    bf = pytest.basic_fx
    pre, post = ('2.7.3.8', '2.7.3.9')
    vpath = tmpdir.join(bf['defname'])
    vpath.write(bf['template'].format(pre))
    r = git.Repo.init(tmpdir.strpath)
    with tbx.chdir(tmpdir.strpath):
        r.git.add(vpath.basename)
        r.git.commit(m='inception')
        gitr.gitr_bv({'bv': True})
        bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
    assert post in vpath.read()
示例#42
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_major_4(basic, tmpdir, capsys, repo_setup):
    """
    pre: '1.0.0.17' in version.py
    gitr bv --major
    post: '2.0.0' in version.py
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    v = pytest.this['vname']
    pre, post = '1.0.0.17', '2.0.0'
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='set version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--major': True,
                      '<path>': v.basename})
        bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
    assert bf['template'].format(post) in v.read()
示例#43
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_major_3_fn(basic, tmpdir, capsys, repo_setup):
    """
    pre: '7.4.3' in splack
    gitr bv --major splack
    post: '8.0.0' in splack
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    o = pytest.this['other']
    pre, post = "7.4.3", "8.0.0"
    o.write("__version__ = '{0}'\n".format(pre))
    r.git.commit(a=True, m='set a version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--major': True,
                      '<path>': o.basename})
    assert bf['template'].format(post) in o.read()
    bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
示例#44
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_build_deep(basic, tmpdir, repo_setup):
    """
    pre: '7.8.9' in ./pkg/foobar
    gitr bv --build ./pkg/foobar
    post: '7.8.9.1' in ./pkg/foobar
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    pre, post = '7.8.9', '7.8.9.1'
    t = pytest.this['template']
    op = 'foo/bar/other_name'
    o = pytest.this['q'][op]
    o['locpath'].write(t.format(pre))
    r.git.commit(a=True, m='version')
    with tbx.chdir(o['locpath'].dirname):
        gitr.gitr_bv({'--build': True, '<path>': o['locpath'].basename})
    assert t.format(post) in o['locpath'].read()
示例#45
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_dir_nofile(basic, tmpdir):
    """
    pre: '/' in target; dirname(target) exists; target does not
    gitr bv <target-path>
    post: no traceback
    """
    bf = pytest.basic_fx
    (sub, trg) = ('sub', 'trg')
    sub_lp = tmpdir.join(sub).ensure(dir=True)
    trg_lp = sub_lp.join(trg)
    rel = '{0}/{1}'.format(sub, trg)
    r = git.Repo.init(tmpdir.strpath)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': rel})
            assert bf['nodiff'].format(rel) in str(e)
    assert "'0.0.0'" in trg_lp.read()
示例#46
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_os_tfl_onp(tmpdir):
    """
    old is not None, target is not empty, old is not in target
    exp: '<olds>' not found in '<c>'
    """
    pytest.dbgfunc()
    oldv, newv = '7.3.2.32', '7.3.2.33'
    trg = tmpdir.join('fooble-de-bar')

    t = '"sizzle" is the version'
    (pre, post) = (t.format(_) for _ in [oldv, newv])
    trg.write(pre)
    exp = "'{0}' not found in '{1}'".format(oldv, pre)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.version_update(trg.basename, newv.split('.'), oldv.split('.'))
        assert exp in str(e)
示例#47
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_os_tfl_onp(tmpdir):
    """
    old is not None, target is not empty, old is not in target
    exp: '<olds>' not found in '<c>'
    """
    pytest.dbgfunc()
    oldv, newv = '7.3.2.32', '7.3.2.33'
    trg = tmpdir.join('fooble-de-bar')

    t = '"sizzle" is the version'
    (pre, post) = (t.format(_) for _ in [oldv, newv])
    trg.write(pre)
    exp = "'{0}' not found in '{1}'".format(oldv, pre)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.version_update(trg.basename, newv.split('.'), oldv.split('.'))
        assert exp in str(e)
示例#48
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_dir_nofile(basic, tmpdir):
    """
    pre: '/' in target; dirname(target) exists; target does not
    gitr bv <target-path>
    post: no traceback
    """
    bf = pytest.basic_fx
    (sub, trg) = ('sub', 'trg')
    sub_lp = tmpdir.join(sub).ensure(dir=True)
    trg_lp = sub_lp.join(trg)
    rel = '{0}/{1}'.format(sub, trg)
    r = git.Repo.init(tmpdir.strpath)
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '<path>': rel})
            assert bf['nodiff'].format(rel) in str(e)
    assert "'0.0.0'" in trg_lp.read()
示例#49
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_noarg_4(basic, tmpdir, capsys):
    """
    pre: 2.7.3.8 in version.py
    gitr bv
    post: 2.7.3.9 in version.py
    """
    bf = pytest.basic_fx
    pre, post = ('2.7.3.8', '2.7.3.9')
    vpath = tmpdir.join(bf['defname'])
    vpath.write(bf['template'].format(pre))
    r = git.Repo.init(tmpdir.strpath)
    with tbx.chdir(tmpdir.strpath):
        r.git.add(vpath.basename)
        r.git.commit(m='inception')
        gitr.gitr_bv({'bv': True})
        bv_verify_diff(bf['template'], pre, post, capsys.readouterr())
    assert post in vpath.read()
示例#50
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_minor_4_fn(basic, tmpdir, repo_setup):
    """
    pre: '3.3.2.7' in version.py
    gitr bv --minor frockle
    post: '3.3.2.7' in version.py, exception('frockle not found')
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    v = pytest.this['vname']
    fn = 'frockle'
    pre, post = "3.3.2.7", "3.4.0"
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '--minor': True, '<path>': fn})
        assert bf['notfound'].format(fn) in str(e)
示例#51
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_patch_3(basic, tmpdir, repo_setup, capsys):
    """
    pre: '1.3.2' in version.py
    gitr bv --patch
    post: '1.3.3' in version.py
    """
    bf = pytest.basic_fx
    pre, post = '1.3.2', '1.3.3'
    r = pytest.this['repo']
    v = pytest.this['vname']
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--patch': True, '-q': True})
        o, e = capsys.readouterr()
        assert o.strip() == ""
    assert bf['template'].format(post) in v.read()
示例#52
0
文件: test_gitr.py 项目: tbarron/gitr
def test_vu_on_tfl(tmpdir):
    """
    old is None, target is not empty
    exp: 'Don't know where to put '<news>' in '<c>''
    """
    pytest.dbgfunc()
    trg = tmpdir.join('version.py')
    nov = 'The quick brown fox and all that'
    trg.write(nov)
    v = '9.8.7'
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.version_update(trg.strpath, v.split('.'))
        assert ''.join(["Don't know where to put '",
                        v,
                        "' in '",
                        nov,
                        "'"]) in str(e)
示例#53
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_build_4(basic, tmpdir, capsys, repo_setup):
    """
    pre: '1.2.3.4' in foo/bar/version.py
    gitr bv --build
    post: '1.2.3.5' in foo/bar/version.py
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    pytest.this['vname'].remove()
    vp = 'foo/bar/version.py'
    v = pytest.this['q'][vp]
    pre, post = "1.2.3.4", "1.2.3.5"
    t = pytest.this['template']
    v['locpath'].write(t.format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--build': True})
        bv_verify_diff(t, pre, post, capsys.readouterr())
示例#54
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_major_3(basic, tmpdir, capsys, repo_setup):
    """
    pre: '7.4.3' in version.py
    gitr bv --major --quiet
    post: '8.0.0' in version.py, nothing on stdout
    """
    bf = pytest.basic_fx
    pre, post = '7.4.3', '8.0.0'
    r = pytest.this['repo']
    v = pytest.this['vname']
    v.write(pre)
    r.git.commit(a=True, m='set version')
    with tbx.chdir(tmpdir.strpath):
        gitr.gitr_bv({'bv': True, '--major': True, '--quiet': True})
    assert post in v.read()
    assert 'M version.py' in r.git.status(porc=True)
    o, e = capsys.readouterr()
    assert o.strip() == ""
示例#55
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_minor_4_fn(basic, tmpdir, repo_setup):
    """
    pre: '3.3.2.7' in version.py
    gitr bv --minor frockle
    post: '3.3.2.7' in version.py, exception('frockle not found')
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    v = pytest.this['vname']
    fn = 'frockle'
    pre, post = "3.3.2.7", "3.4.0"
    v.write(bf['template'].format(pre))
    r.git.commit(a=True, m='first version')
    with tbx.chdir(tmpdir.strpath):
        with pytest.raises(SystemExit) as e:
            gitr.gitr_bv({'bv': True, '--minor': True,
                          '<path>': fn})
        assert bf['notfound'].format(fn) in str(e)
示例#56
0
文件: test_gitr.py 项目: tbarron/gitr
def test_bv_file_build_deep(basic, tmpdir, repo_setup):
    """
    pre: '7.8.9' in ./pkg/foobar
    gitr bv --build ./pkg/foobar
    post: '7.8.9.1' in ./pkg/foobar
    """
    bf = pytest.basic_fx
    r = pytest.this['repo']
    pre, post = '7.8.9', '7.8.9.1'
    t = pytest.this['template']
    op = 'foo/bar/other_name'
    o = pytest.this['q'][op]
    o['locpath'].write(t.format(pre))
    r.git.commit(a=True, m='version')
    with tbx.chdir(o['locpath'].dirname):
        gitr.gitr_bv({'--build': True,
                      '<path>': o['locpath'].basename})
    assert t.format(post) in o['locpath'].read()