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
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
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
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
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
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
def latest_package_version(self, name): """ Latest version for package """ return PyPI.latest_package_version(name)
def all_package_versions(self, name): return PyPI.all_package_versions(name)
def _package_changes(self, name, current_version, new_version): return PyPI.changes(name, current_version, new_version)