Exemplo n.º 1
0
def test_bump(wst, monkeypatch):
    with temp_dir():
        with pytest.raises(SystemExit):
            wst('bump')

    with temp_remote_git_repo():
        # No requirements.txt
        if os.path.exists('requirements.txt'):
            os.unlink('requirements.txt')
        with pytest.raises(SystemExit):
            wst('bump')

        # All requirements are up to date
        with open('requirements.txt', 'w') as fp:
            fp.write('localconfig\nrequests')
        assert ({}, None, []) == wst('bump')

        # All requirements are outdated
        with open('requirements.txt', 'w') as fp:
            fp.write('# Comment for localconfig\nlocalconfig==0.0.1\n# Comment for requests\nrequests<0.1')
        msgs, commit_msg, bumps = wst('bump')
        file, msg = list(msgs.items())[0]
        assert 'requirements.txt' == file

        version = PyPI.latest_package_version('localconfig')
        expected_msg = 'Require localconfig==%s' % version
        assert expected_msg == msg[:len(expected_msg)]
        assert expected_msg == commit_msg[:len(expected_msg)]

        with open('requirements.txt') as fp:
            requirements = fp.read()
            assert '# Comment for localconfig\nlocalconfig==%s\n# Comment for requests\nrequests<0.1\n' % version == requirements
Exemplo n.º 2
0
def test_commit(wst):
    with temp_dir():
        with pytest.raises(SystemExit):
            wst('commit')
    config.merge.branches = '1.0.x 2.0.x 3.0.x master'
    with temp_git_repo():
        test_cleanrun
        with pytest.raises(SystemExit):
            wst('commit "no files to commit"')

    with temp_git_repo():
        run('git checkout -b 3.0.x')
        with open('new_file_commit1', 'w') as fp:
            fp.write('New World')
        run('git add -A')
        wst('commit "Add new file"')
        changes = run('git log --oneline', return_output=True)
        expected_commit_message = "Add new file"
        assert expected_commit_message in changes

        # test commit with branch
        with open('new_file_commit2', 'w') as fp:
            fp.write('Hello World')

        wst('commit "New Master file" --branch master')
        changes = run('git log --oneline', return_output=True)
        expected_commit_message = "New Master file"
        assert expected_commit_message in changes
Exemplo n.º 3
0
def test_test(wst, monkeypatch):
    if 'PYTESTARGS' in os.environ:
        del os.environ['PYTESTARGS']

    with temp_dir() as cwd:
        monkeypatch.setenv('HOME', cwd)  # tox creates virtualenvs in ~/.virtualenvs

        with pytest.raises(SystemExit):
            wst('test')

        with temp_git_repo(name='foo') as cwd:
            with pytest.raises(SystemExit):
                wst('test')
            wst('setup --product')

            with open('foo/__init__.py', 'w') as fp:
                fp.write('hello = "world"')

            pass_test = 'from foo import hello\n\n\ndef test_pass():\n  assert hello == "world"'
            fail_test = 'def test_fail():\n  assert False'

            with open('tests/test_pass.py', 'w') as fp:
                fp.write(pass_test)
            commands = wst('test')
            assert set(commands.keys()) == {'cover', 'py37', 'style'}
            assert 'tox' in commands['cover']

            wst('test --show-dependencies')
            wst('test --install-editable flake8')
            wst('test --install-editable foo')

            results = wst('test --test-dependents')
            assert set(results.keys()) == {'foo'}
            assert '2 passed' in results['foo']

            with open('tests/test_fail.py', 'w') as fp:
                fp.write(pass_test + '\n\n\n' + fail_test)
            with pytest.raises(SystemExit):
                wst('test')

            output = wst('test tests/test_pass.py')
            assert output == {'py36': 'pytest {env:PYTESTARGS:}', 'py37': 'pytest {env:PYTESTARGS:}'}

            os.utime('requirements.txt', None)
            assert list(wst('test -k test_pass').keys()) == ['py36', 'py37']

            with open('tests/test_fail.py', 'w') as fp:
                fp.write(pass_test + '\n' + fail_test)
            with pytest.raises(SystemExit):
                wst('test style')

            with open('tests/test_fail.py', 'w') as fp:
                fp.write(pass_test + '\n\n\n' + fail_test)
            assert 'style' in wst('test style')

            os.unlink('tests/test_fail.py')
            assert 'cover' in wst('test cover')
            assert os.path.exists('coverage.xml')
            assert os.path.exists('htmlcov/index.html')
Exemplo n.º 4
0
def test_bump_no_op():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('localconfig')

        bump()

        new_req = open('requirements.txt').read()
        assert 'localconfig' == new_req
Exemplo n.º 5
0
def test_sanity(wst, command, exception):
    with temp_dir():
        if exception:
            with pytest.raises(exception):
                wst(command)
        else:
            wst(command)

    with temp_git_repo():
        wst(command)
Exemplo n.º 6
0
def test_bump_filter():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('localconfig==0.0.1\nremoteconfig==0.0.1')

        sys.argv = ['bump', 'remoteconfig']
        bump()

        new_req = open('requirements.txt').read()
        expect_req = 'localconfig==0.0.1\nremoteconfig==%s\n' % PyPI.latest_package_version('remoteconfig')
        assert expect_req == new_req
Exemplo n.º 7
0
def test_bump_latest():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('localconfig==0.0.1')

        bump()

        new_req = open('requirements.txt').read()
        expect_req = 'localconfig==%s\n' % PyPI.latest_package_version('localconfig')
        assert 'localconfig==0.0.1' != new_req
        assert expect_req == new_req
Exemplo n.º 8
0
def test_bump_add():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('localconfig==0.0.1\nremoteconfig==0.0.1')

        sys.argv = ['bump', 'remoteconfig', 'requests', 'clicast>=0.2', '--add']
        bump()

        new_req = open('requirements.txt').read()
        expect_req = 'clicast>=0.2\nlocalconfig==0.0.1\nremoteconfig=={}\nrequests\n'.format(
            PyPI.latest_package_version('remoteconfig'))
        assert expect_req == new_req
Exemplo n.º 9
0
def test_checkout_with_alias(wst, mock_run):
    with temp_dir() as tmpdir:
        with pytest.raises(SystemExit):
            wst('checkout foobazbar-no-such-repo')

        wst('checkout mzheng-repos')
        assert mock_run.call_count == 4
        mock_run.assert_called_with(
            ['git', 'clone', '[email protected]:maxzheng/workspace-tools.git', str(tmpdir / 'workspace-tools'), '--origin', 'origin'],
            silent=True)

        wst('checkout clicast')
        mock_run.assert_called_with(
            ['git', 'clone', '[email protected]:maxzheng/clicast.git', str(tmpdir / 'clicast'), '--origin', 'origin'], silent=True)
Exemplo n.º 10
0
def test_bump_bad_requirements():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('git+https://github.com/someversion@blah@blah=blah\n')
            fp.write('localconfig==0.0.1\n')
            fp.write('http://github.com/someversion@blah@blah=blah')

        bump()

        new_req = open('requirements.txt').read()
        expect_req = ('git+https://github.com/someversion@blah@blah=blah\n' +
                      'localconfig==%s\n' % PyPI.latest_package_version('localconfig') +
                      'http://github.com/someversion@blah@blah=blah\n')
        assert 'localconfig==0.0.1' != new_req
        assert expect_req == new_req
Exemplo n.º 11
0
def test_bump_published_check():
    with temp_dir():
        orig_reqs = 'localconfig==0.0.1\nremoteconfig==0.0.1'

        with pytest.raises(BumpAccident) as e:
            with open('requirements.txt', 'w') as fp:
                fp.write(orig_reqs)

            sys.argv = ['bump', 'remoteconfig', 'requests', 'clicast>1000', '--add', '--debug']
            bump()

        assert 'No published version could satisfy the requirement(s): clicast>1000' in str(e)

        reqs = open('requirements.txt').read()
        assert orig_reqs == reqs
Exemplo n.º 12
0
def test_bump_add_detail():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('remoteconfig==0.0.1')

        with open('pinned.txt', 'w') as fp:
            fp.write('remoteconfig==0.0.1')

        sys.argv = ['bump', 'remoteconfig>0.2,<0.2.5', '--detail']
        bump()

        new_req = open('requirements.txt').read()
        expect_req = 'remoteconfig>0.2,<0.2.5\n'
        assert expect_req == new_req

        new_pinned = open('pinned.txt').read()
        expect_pinned = 'remoteconfig==0.2.4\n'
        assert expect_pinned == new_pinned
Exemplo n.º 13
0
def test_checkout_with_alias(wst, mock_run):
    with temp_dir() as tmpdir:
        with pytest.raises(SystemExit):
            wst('checkout foobazbar-no-such-repo')

        wst('checkout mzheng-repos')
        assert mock_run.call_count == 4
        mock_run.assert_called_with([
            'git', 'clone', '[email protected]:maxzheng/workspace-tools.git',
            str(tmpdir / 'workspace-tools'), '--origin', 'origin'
        ],
                                    silent=True)

        wst('checkout clicast')
        mock_run.assert_called_with([
            'git', 'clone', '[email protected]:maxzheng/clicast.git',
            str(tmpdir / 'clicast'), '--origin', 'origin'
        ],
                                    silent=True)
Exemplo n.º 14
0
def test_commit(wst):
    with temp_dir():
        with pytest.raises(SystemExit):
            wst('commit')

    with temp_git_repo():
        with pytest.raises(SystemExit):
            wst('commit "no files to commit"')

        with open('new_file', 'w') as fp:
            fp.write('Hello World')
        assert 'new_file' in stat_repo(return_output=True)

        wst('commit "Add new file" --branch master')

        assert 'working tree clean' in stat_repo(return_output=True)
        assert 'Hello World' == open('new_file').read()

        with open('new_file', 'w') as fp:
            fp.write('New World')

        wst('commit "Update file"')

        assert ['update-file@master', 'master'] == all_branches()

        wst('commit --move release')

        assert ['update-file@master', 'master', 'release'] == all_branches()

        wst('commit --discard')

        assert ['master', 'release'] == all_branches()

        wst('checkout release')

        wst('commit --discard')

        assert ['release', 'master'] == all_branches()

        logs = commit_logs()
        assert 'new file' in logs
        assert 1 == len(list(filter(None, logs.split('commit'))))
Exemplo n.º 15
0
def test_bump_recursive():
    with temp_dir():
        with open('requirements.txt', 'w') as fp:
            fp.write('-r requirements/prod.txt\n')
            fp.write('localconfig==0.0.1')
        os.mkdir('requirements')
        with open('requirements/prod.txt', 'w') as fp:
            fp.write('localconfig==0.0.1')

        bump()

        new_req = open('requirements.txt').read()
        expect_req = '-r requirements/prod.txt\nlocalconfig==%s\n' % PyPI.latest_package_version('localconfig')
        assert 'localconfig==0.0.1' != new_req
        assert expect_req == new_req

        new_req = open('requirements/prod.txt').read()
        expect_req = 'localconfig==%s\n' % PyPI.latest_package_version('localconfig')
        assert 'localconfig==0.0.1' != new_req
        assert expect_req == new_req
Exemplo n.º 16
0
def test_cleanrun(wst):
    config.clean.remove_products_older_than_days = 30

    with temp_dir():
        repos = ['repo', 'old_repo', 'old_repo_dirty']
        run('touch file; mkdir ' + ' '.join(repos), shell=True)
        for repo in repos:
            run('cd {}; git init; git commit --allow-empty -m "Initial commit"'.format(repo), shell=True)
            if repo.startswith('old'):
                run('touch -t 200001181205.09 ' + repo)
        run('cd old_repo_dirty; touch new_file', shell=True)
        run('ls -l')
        wst('clean')

        assert os.listdir() == ['old_repo_dirty', 'repo', 'file']

    with temp_git_repo():
        run('touch hello.py hello.pyc')
        wst('clean')

        assert os.listdir() == ['.git', 'hello.py']
Exemplo n.º 17
0
def test_checkout_with_multiple_repos(wst):
    with temp_dir():
        wst('checkout https://github.com/maxzheng/localconfig.git https://github.com/maxzheng/remoteconfig.git')
        assert os.path.exists('localconfig/README.rst')
        assert os.path.exists('remoteconfig/README.rst')
Exemplo n.º 18
0
def test_checkout_with_multiple_repos(wst):
    with temp_dir():
        wst('checkout https://github.com/maxzheng/localconfig.git https://github.com/maxzheng/remoteconfig.git'
            )
        assert os.path.exists('localconfig/README.rst')
        assert os.path.exists('remoteconfig/README.rst')
Exemplo n.º 19
0
def test_checkout_with_git(wst):
    with temp_dir():
        wst('checkout [email protected]:maxzheng/clicast.git')
        assert os.path.exists('clicast/README.rst')
Exemplo n.º 20
0
def test_push_without_repo(wst):
    with temp_dir():
        with pytest.raises(SystemExit):
            wst('push')
Exemplo n.º 21
0
def test_bump_no_file():
    with temp_dir():
        with pytest.raises(SystemExit):
            bump()
Exemplo n.º 22
0
def test_checkout_with_http_git(wst):
    with temp_dir():
        wst('checkout https://github.com/confluentinc/clicast.git')
        assert os.path.exists('clicast/README.rst')
Exemplo n.º 23
0
def test_checkout_with_git(wst):
    with temp_dir():
        wst('checkout [email protected]:maxzheng/clicast.git')
        assert os.path.exists('clicast/README.rst')