本文整理汇总了Python中tests.test_pip.write_file函数的典型用法代码示例。如果您正苦于以下问题:Python write_file函数的具体用法?Python write_file怎么用?Python write_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _change_test_package_submodule
def _change_test_package_submodule(env, submodule_path):
write_file(submodule_path/'testfile', 'this is a changed file')
write_file(submodule_path/'testfile2', 'this is an added file')
env.run('git', 'add', '.', cwd=submodule_path)
env.run('git', 'commit', '-q',
'--author', 'Pip <[email protected]>',
'-am', 'submodule change', cwd=submodule_path)
示例2: test_upgrade_from_reqs_file
def test_upgrade_from_reqs_file():
"""
Upgrade from a requirements file.
"""
env = reset_env()
write_file(
"test-req.txt",
textwrap.dedent(
"""\
PyLogo<0.4
# and something else to test out:
INITools==0.3
"""
),
)
install_result = run_pip("install", "-r", env.scratch_path / "test-req.txt")
write_file(
"test-req.txt",
textwrap.dedent(
"""\
PyLogo
# and something else to test out:
INITools
"""
),
)
run_pip("install", "--upgrade", "-r", env.scratch_path / "test-req.txt")
uninstall_result = run_pip("uninstall", "-r", env.scratch_path / "test-req.txt", "-y")
assert_all_changes(install_result, uninstall_result, [env.venv / "build", "cache", env.scratch / "test-req.txt"])
示例3: test_download_should_skip_existing_files
def test_download_should_skip_existing_files():
"""
It should not download files already existing in the scratch dir
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""
INITools==0.1
"""))
result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
# adding second package to test-req.txt
write_file('test-req.txt', textwrap.dedent("""
INITools==0.1
python-openid==2.2.5
"""))
# only the second package should be downloaded
result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
openid_tarball_prefix = str(Path('scratch')/ 'python-openid-')
assert any(path.startswith(openid_tarball_prefix) for path in result.files_created)
assert Path('scratch')/ 'INITools-0.1.tar.gz' not in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
assert env.site_packages/ 'openid' not in result.files_created
示例4: test_cleanup_after_create_bundle
def test_cleanup_after_create_bundle():
"""
Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/.
"""
env = reset_env()
# Install an editable to create a src/ dir.
args = ['install']
args.extend(['-e',
'%s#egg=pip-test-package' %
local_checkout('git+http://github.com/pypa/pip-test-package.git')])
run_pip(*args)
build = env.venv_path/"build"
src = env.venv_path/"src"
assert not exists(build), "build/ dir still exists: %s" % build
assert exists(src), "expected src/ dir doesn't exist: %s" % src
# Make the bundle.
fspkg = 'file://%s/FSPkg' %join(here, 'packages')
pkg_lines = textwrap.dedent('''\
-e %s
-e %s#egg=initools-dev
pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
write_file('bundle-req.txt', pkg_lines)
run_pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle')
build_bundle = env.scratch_path/"build-bundle"
src_bundle = env.scratch_path/"src-bundle"
assert not exists(build_bundle), "build-bundle/ dir still exists: %s" % build_bundle
assert not exists(src_bundle), "src-bundle/ dir still exists: %s" % src_bundle
# Make sure previously created src/ from editable still exists
assert exists(src), "expected src dir doesn't exist: %s" % src
示例5: test_uninstall_from_reqs_file
def test_uninstall_from_reqs_file():
"""
Test uninstall from a requirements file.
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""\
-e %s#egg=initools-dev
# and something else to test out:
PyLogo<0.4
""" % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
result = run_pip('install', '-r', 'test-req.txt')
write_file('test-req.txt', textwrap.dedent("""\
# -f, -i, and --extra-index-url should all be ignored by uninstall
-f http://www.example.com
-i http://www.example.com
--extra-index-url http://www.example.com
-e %s#egg=initools-dev
# and something else to test out:
PyLogo<0.4
""" % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
assert_all_changes(
result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
示例6: test_freeze_with_requirement_option
def test_freeze_with_requirement_option():
"""
Test that new requirements are created correctly with --requirement hints
"""
reset_env()
ignores = textwrap.dedent("""\
# Unchanged requirements below this line
-r ignore.txt
--requirement ignore.txt
-Z ignore
--always-unzip ignore
-f http://ignore
-i http://ignore
--extra-index-url http://ignore
--find-links http://ignore
--index-url http://ignore
""")
write_file('hint.txt', textwrap.dedent("""\
INITools==0.1
NoExist==4.2
""") + ignores)
result = run_pip('install', 'initools==0.2')
result = run_pip('install', 'MarkupSafe')
result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: pip freeze --requirement hint.txt
-- stderr: --------------------
Requirement file contains NoExist==4.2, but that package is not installed
-- stdout: --------------------
INITools==0.2
""") + ignores + "## The following requirements were added by pip --freeze:..."
_check_output(result, expected)
示例7: _test_config_file_override_stack
def _test_config_file_override_stack(config_file):
environ = clear_environ(os.environ.copy())
environ["PIP_CONFIG_FILE"] = config_file # set this to make pip load it
reset_env(environ)
write_file(
config_file,
textwrap.dedent(
"""\
[global]
index-url = http://download.zope.org/ppix
"""
),
)
result = run_pip("install", "-vvv", "INITools", expect_error=True)
assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout
reset_env(environ)
write_file(
config_file,
textwrap.dedent(
"""\
[global]
index-url = http://download.zope.org/ppix
[install]
index-url = http://pypi.appspot.com/
"""
),
)
result = run_pip("install", "-vvv", "INITools", expect_error=True)
assert "Getting page http://pypi.appspot.com/INITools" in result.stdout
result = run_pip("install", "-vvv", "--index-url", "http://pypi.python.org/simple", "INITools", expect_error=True)
assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout
assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout
assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
示例8: test_schema_check_in_requirements_file
def test_schema_check_in_requirements_file():
"""
Test installing from a requirements file with an invalid vcs schema..
"""
env = reset_env()
write_file('file-egg-req.txt', textwrap.dedent("""\
git://github.com/alex/django-fixture-generator.git#egg=fixture_generator
"""))
assert_raises(AssertionError, run_pip, 'install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
示例9: test_install_folder_using_dot_slash
def test_install_folder_using_dot_slash():
"""
Test installing a folder using pip install ./foldername
"""
env = reset_env()
mkdir("mock")
pkg_path = env.scratch_path / "mock"
write_file("setup.py", mock100_setup_py, pkg_path)
result = run_pip("install", "./mock")
egg_folder = env.site_packages / "mock-100.1-py%s.egg-info" % pyversion
assert egg_folder in result.files_created, str(result)
示例10: test_install_folder_using_slash_in_the_end
def test_install_folder_using_slash_in_the_end():
r"""
Test installing a folder using pip install foldername/ or foldername\
"""
env = reset_env()
mkdir('mock')
pkg_path = env.scratch_path/'mock'
write_file('setup.py', mock100_setup_py, pkg_path)
result = run_pip('install', 'mock' + os.path.sep)
egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion
assert egg_folder in result.files_created, str(result)
示例11: test_single_download_from_requirements_file
def test_single_download_from_requirements_file():
"""
It should support download (in the scratch path) from PyPi from a requirements file
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""
INITools==0.1
"""))
result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
示例12: test_install_folder_using_relative_path
def test_install_folder_using_relative_path():
"""
Test installing a folder using pip install folder1/folder2
"""
env = reset_env()
mkdir("initools")
mkdir(Path("initools") / "mock")
pkg_path = env.scratch_path / "initools" / "mock"
write_file("setup.py", mock100_setup_py, pkg_path)
result = run_pip("install", Path("initools") / "mock")
egg_folder = env.site_packages / "mock-100.1-py%s.egg-info" % pyversion
assert egg_folder in result.files_created, str(result)
示例13: test_install_folder_using_relative_path
def test_install_folder_using_relative_path():
"""
Test installing a folder using pip install folder1/folder2
"""
env = reset_env()
mkdir('initools')
mkdir(Path('initools')/'mock')
pkg_path = env.scratch_path/'initools'/'mock'
write_file('setup.py', mock100_setup_py, pkg_path)
result = run_pip('install', Path('initools')/'mock')
egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion
assert egg_folder in result.files_created, str(result)
示例14: test_relative_requirements_file
def test_relative_requirements_file():
"""
Test installing from a requirements file with a relative path with an egg= definition..
"""
url = path_to_url(os.path.join(here, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg'
env = reset_env()
write_file('file-egg-req.txt', textwrap.dedent("""\
%s
""" % url))
result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
示例15: test_find_command_folder_in_path
def test_find_command_folder_in_path():
"""
If a folder named e.g. 'git' is in PATH, and find_command is looking for
the 'git' executable, it should not match the folder, but rather keep
looking.
"""
env = reset_env()
mkdir('path_one'); path_one = env.scratch_path/'path_one'
mkdir(path_one/'foo')
mkdir('path_two'); path_two = env.scratch_path/'path_two'
write_file(path_two/'foo', '# nothing')
found_path = find_command('foo', map(str, [path_one, path_two]))
assert found_path == path_two/'foo'