本文整理汇总了Python中testing.requirements函数的典型用法代码示例。如果您正苦于以下问题:Python requirements函数的具体用法?Python requirements怎么用?Python requirements使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了requirements函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: it_gives_the_same_python_version_as_we_started_with
def it_gives_the_same_python_version_as_we_started_with(tmpdir):
other_python = OtherPython()
with tmpdir.as_cwd():
requirements('')
# first simulate some unrelated use of venv-update
# this guards against statefulness in the venv-update scratch dir
venv_update('venv=', 'unrelated_venv', 'pip-command=', 'true')
run('virtualenv', '--python', other_python.interpreter, 'venv')
initial_version = assert_python_version(other_python.version_prefix)
venv_update_symlink_pwd()
out, err = run('./venv/bin/python', 'venv_update.py')
err = strip_pip_warnings(err)
assert err == ''
out = uncolor(out)
assert out.startswith('''\
> virtualenv venv
Keeping valid virtualenv from previous run.
> rm -rf venv/local
> pip install venv-update=={}
'''.format(__version__))
final_version = assert_python_version(other_python.version_prefix)
assert final_version == initial_version
示例2: it_installs_stuff_with_dash_e_without_wheeling
def it_installs_stuff_with_dash_e_without_wheeling(tmpdir):
venv = tmpdir.join('venv')
install_coverage(venv)
pip = venv.join('bin/pip').strpath
run(pip, 'install', 'venv-update==' + __version__)
# Install a package from git with no extra dependencies in editable mode.
#
# We need to install a package from VCS instead of the filesystem because
# otherwise we aren't testing that editable requirements aren't wheeled
# (and instead might just be testing that local paths aren't wheeled).
requirements('-e git+git://github.com/Yelp/[email protected]#egg=dumb-init') # noqa
run(str(venv.join('bin/pip-faster')), 'install', '-r', 'requirements.txt')
frozen_requirements = pip_freeze(str(venv)).split('\n')
assert set(frozen_requirements) == {
'-e git://github.com/Yelp/[email protected]#egg=dumb_init', # noqa
'coverage-enable-subprocess==1.0',
'coverage==ANY',
'venv-update==' + __version__,
'',
}
# we shouldn't wheel things installed editable
assert not tuple(cached_wheels(tmpdir))
示例3: it_gives_the_same_python_version_as_we_started_with
def it_gives_the_same_python_version_as_we_started_with(tmpdir):
other_python = OtherPython()
with tmpdir.as_cwd():
requirements('')
# first simulate some unrelated use of venv-update
# this guards against statefulness in the venv-update scratch dir
venv_update('unrelated_venv', '--', '--version')
run('virtualenv', '--python', other_python.interpreter, 'venv')
initial_version = assert_python_version(other_python.version_prefix)
venv_update_symlink_pwd()
out, err = run('./venv/bin/python', 'venv_update.py')
assert err == ''
out = uncolor(out)
assert out.startswith('''\
> virtualenv
Keeping valid virtualenv from previous run.
> venv/bin/python -m pip.__main__ install pip-faster==%s
''' % __version__)
final_version = assert_python_version(other_python.version_prefix)
assert final_version == initial_version
示例4: test_conflicting_reqs
def test_conflicting_reqs(tmpdir):
tmpdir.chdir()
T.requirements('''
dependant_package
conflicting_package
''')
with pytest.raises(CalledProcessError) as excinfo:
T.venv_update()
assert excinfo.value.returncode == 1
out, err = excinfo.value.result
err = T.strip_coverage_warnings(err)
err = T.strip_pip_warnings(err)
assert err == ''
out = T.uncolor(out)
assert (
'''
Cleaning up...
Error: version conflict: many-versions-package 3 (venv/%s)'''
''' <-> many-versions-package<2 (from conflicting-package->-r requirements.txt (line 3))
Storing debug log for failure in %s/home/.pip/pip.log
Something went wrong! Sending 'venv' back in time, so make knows it's invalid.
''' % (PYTHON_LIB, tmpdir)
) in out
assert_venv_marked_invalid(tmpdir.join('venv'))
示例5: test_override_requirements_file
def test_override_requirements_file(tmpdir):
tmpdir.chdir()
requirements('')
Path('.').ensure_dir('requirements.d').join('venv-update.txt').write('''\
pip-faster==%s
pure_python_package
''' % __version__)
out, err = venv_update()
err = strip_pip_warnings(err)
assert err == ''
out = uncolor(out)
assert ' '.join((
'\n> venv/bin/python -m pip.__main__ install',
'-r requirements.d/venv-update.txt\n',
)) in out
expected = ('\nSuccessfully installed pip-1.5.6 pip-faster-%s pure-python-package-0.2.0 virtualenv-1.11.6' % __version__)
assert expected in out
assert '\n Successfully uninstalled pure-python-package\n' in out
expected = '\n'.join((
'pip-faster==%s' % __version__,
'virtualenv==1.11.6',
'wheel==0.29.0',
''
))
assert pip_freeze() == expected
示例6: test_multiple_issues
def test_multiple_issues(tmpdir):
# Make it a bit worse. The output should show all three issues.
tmpdir.chdir()
T.requirements('flake8==2.2.5')
T.venv_update()
T.run('./virtualenv_run/bin/pip', 'uninstall', '--yes', 'pyflakes')
T.requirements('''
# flake8 2.2.5 requires mccabe>=0.2.1 and pep8>=1.5.7, so this isn't satisfiable
flake8==2.2.5
mccabe==0.2
pep8==1.0
''')
with pytest.raises(CalledProcessError) as excinfo:
T.venv_update()
assert excinfo.value.returncode == 1
out, err = excinfo.value.result
err = T.strip_coverage_warnings(err)
assert err == ''
out = T.uncolor(out)
assert (
'''
Cleaning up...
Error: version conflict: mccabe 0.2 (virtualenv_run/%s)'''
''' <-> mccabe>=0.2.1 (from flake8==2.2.5 (from -r requirements.txt (line 3)))
Error: version conflict: pep8 1.0 (virtualenv_run/%s) '''
'''<-> pep8>=1.5.7 (from flake8==2.2.5 (from -r requirements.txt (line 3)))
Error: unmet dependency: pyflakes>=0.8.1 (from flake8==2.2.5 (from -r requirements.txt (line 3)))
Something went wrong! Sending 'virtualenv_run' back in time, so make knows it's invalid.
''' % (PYTHON_LIB, PYTHON_LIB)
) in out
示例7: test_symlink_is_relative
def test_symlink_is_relative(tmpdir):
"""We want to be able to mount ~/.cache/venv-update in different locations
safely, so the symlink must be relative.
https://github.com/Yelp/pip-faster/issues/101
"""
tmpdir.chdir()
scratch_dir = tmpdir.join('home', '.cache').ensure_dir('venv-update').ensure_dir(__version__)
symlink = scratch_dir.join('venv-update')
# run a trivial venv-update to populate the cache and create a proper symlink
assert not symlink.exists()
requirements('')
venv_update()
# it should be a valid, relative symlink
assert symlink.exists()
assert not symlink.readlink().startswith('/')
# and if we move the entire scratch directory, the symlink should still be valid
# (this is what we really care about)
scratch_dir.move(tmpdir.join('derp'))
symlink = tmpdir.join('derp', 'venv-update')
assert symlink.exists()
示例8: test_cant_wheel_package
def test_cant_wheel_package(tmpdir):
with tmpdir.as_cwd():
enable_coverage(tmpdir)
requirements('cant-wheel-package\npure-python-package')
out, err = venv_update()
assert err == ''
out = uncolor(out)
# for unknown reasons, py27 has an extra line with four spaces in this output, where py26 does not.
out = out.replace('\n \n', '\n')
assert '''
----------------------------------------
Failed building wheel for cant-wheel-package
Running setup.py bdist_wheel for pure-python-package
Destination directory: %s/home/.cache/pip-faster/wheelhouse''' % tmpdir + '''
SLOW!! no wheel found after building (couldn't be wheeled?): cant-wheel-package (from -r requirements.txt (line 1))
Installing collected packages: cant-wheel-package, pure-python-package
Running setup.py install for cant-wheel-package
Could not find .egg-info directory in install record for cant-wheel-package (from -r requirements.txt (line 1))
Successfully installed cant-wheel-package pure-python-package
Cleaning up...
> pip uninstall --yes coverage coverage-enable-subprocess
''' in out # noqa
assert pip_freeze().startswith('cant-wheel-package==0.1.0\n')
示例9: test_conflicting_reqs
def test_conflicting_reqs(tmpdir):
tmpdir.chdir()
T.requirements('''
# flake8 2.2.5 requires mccabe>=0.2.1, so this isn't satisfiable
flake8==2.2.5
mccabe==0.2
''')
with pytest.raises(CalledProcessError) as excinfo:
T.venv_update()
assert excinfo.value.returncode == 1
out, err = excinfo.value.result
err = T.strip_coverage_warnings(err)
assert err == ''
out = T.uncolor(out)
assert (
'''
Cleaning up...
Error: version conflict: mccabe 0.2 (virtualenv_run/%s)'''
''' <-> mccabe>=0.2.1 (from flake8==2.2.5 (from -r requirements.txt (line 3)))
Something went wrong! Sending 'virtualenv_run' back in time, so make knows it's invalid.
''' % PYTHON_LIB
) in out
示例10: test_package_name_normalization
def test_package_name_normalization(tmpdir):
with tmpdir.as_cwd():
enable_coverage(tmpdir)
requirements('WEIRD_cAsing-packAge')
venv_update()
assert '\nweird-CASING-pACKage==' in pip_freeze()
示例11: venv_setup
def venv_setup():
# First just set up a blank virtualenv, this'll bypass the
# bootstrap when we're actually testing for speed
if not Path('venv').exists():
requirements('')
venv_update()
install_coverage()
# Now the actual requirements we'll install
requirements('\n'.join((
'project_with_c',
'pure_python_package==0.2.1',
'slow_python_package==0.1.0',
'dependant_package',
'many_versions_package>=2,<3',
''
)))
yield
expected = '\n'.join((
'dependant-package==1',
'implicit-dependency==1',
'many-versions-package==2.1',
'project-with-c==0.1.0',
'pure-python-package==0.2.1',
'slow-python-package==0.1.0',
'venv-update==%s' % __version__,
''
))
assert pip_freeze() == expected
示例12: flake8_older
def flake8_older():
requirements('''\
flake8==2.0
# last pyflakes release before 0.8 was 0.7.3
pyflakes<0.8
# simply to prevent these from drifting:
mccabe<=0.3
pep8<=1.5.7
-r %s/requirements.d/coverage.txt
''' % TOP)
venv_update()
assert pip_freeze() == '\n'.join((
'coverage==4.0.3',
'coverage-enable-subprocess==0',
'flake8==2.0',
'mccabe==0.3',
'pep8==1.5.7',
'pip-faster==' + __version__,
'pyflakes==0.7.3',
'virtualenv==1.11.6',
'wheel==0.29.0',
''
))
示例13: flake8_newer
def flake8_newer():
requirements('''\
flake8==2.2.5
# we expect 0.8.1
pyflakes<=0.8.1
# simply to prevent these from drifting:
mccabe<=0.3
pep8<=1.5.7
-r %s/requirements.d/coverage.txt
''' % TOP)
venv_update()
assert pip_freeze() == '\n'.join((
'coverage==4.0.3',
'coverage-enable-subprocess==0',
'flake8==2.2.5',
'mccabe==0.3',
'pep8==1.5.7',
'pip-faster==' + __version__,
'pyflakes==0.8.1',
'virtualenv==1.11.6',
'wheel==0.29.0',
''
))
示例14: test_bad_symlink_can_be_fixed
def test_bad_symlink_can_be_fixed(tmpdir):
"""If the symlink at ~/.config/venv-update/$version/venv-update is wrong,
we should be able to fix it and keep going.
https://github.com/Yelp/pip-faster/issues/98
"""
tmpdir.chdir()
scratch_dir = tmpdir.join('home', '.cache').ensure_dir('venv-update').ensure_dir(__version__)
symlink = scratch_dir.join('venv-update')
# run a trivial venv-update to populate the cache and create a proper symlink
assert not symlink.exists()
requirements('')
venv_update()
assert symlink.exists()
# break the symlink by hand (in real life, this can happen if mounting
# things into Docker containers, for example)
symlink.remove()
symlink.mksymlinkto('/nonexist')
assert not symlink.exists()
# a simple venv-update should install packages and fix the symlink
enable_coverage(tmpdir)
requirements('pure-python-package')
venv_update()
assert '\npure-python-package==0.2.0\n' in pip_freeze()
assert symlink.exists()
示例15: test_conflicting_reqs
def test_conflicting_reqs(tmpdir):
tmpdir.chdir()
T.requirements('''
dependant_package
conflicting_package
''')
with pytest.raises(CalledProcessError) as excinfo:
T.venv_update()
assert excinfo.value.returncode == 1
out, err = excinfo.value.result
err = T.strip_coverage_warnings(err)
err = T.strip_pip_warnings(err)
assert err == (
"conflicting-package 1 has requirement many-versions-package<2, but you'll "
'have many-versions-package 3 which is incompatible.\n'
# TODO: do we still need to append our own error?
'Error: version conflict: many-versions-package 3 (venv/{}) '
'<-> many-versions-package<2 '
'(from conflicting_package->-r requirements.txt (line 3))\n'.format(
PYTHON_LIB,
)
)
out = T.uncolor(out)
assert_something_went_wrong(out)
assert_venv_marked_invalid(tmpdir.join('venv'))