def _copy_file(filename, location, link):
copy = True
download_location = os.path.join(location, link.filename)
if os.path.exists(download_location):
response = ask_path_exists(
'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abort' %
display_path(download_location), ('i', 'w', 'b', 'a'))
if response == 'i':
copy = False
elif response == 'w':
logger.warning('Deleting %s', display_path(download_location))
os.remove(download_location)
elif response == 'b':
dest_file = backup_dir(download_location)
logger.warning(
'Backing up %s to %s',
display_path(download_location),
display_path(dest_file),
)
shutil.move(download_location, dest_file)
elif response == 'a':
sys.exit(-1)
if copy:
shutil.copy(filename, download_location)
logger.info('Saved %s', display_path(download_location))
python类copy()的实例源码
def backup_propic(self):
"""Backups the profile picture for the given
entity as the current peer profile picture, returning its path"""
# Allow multiple versions of the profile picture
# TODO Maybe this should be another method, because when downloading media... We also have multiple versions
filename = self.media_handler.get_propic_path(self.entity, allow_multiple=True)
generic_filename = self.media_handler.get_propic_path(self.entity)
if filename: # User may not have a profile picture
if not isfile(filename):
# Only download the file if it doesn't exist yet
self.client.download_profile_photo(self.entity.photo,
file_path=filename,
add_extension=False)
# If we downloaded a new version, copy it to the "default" generic file
if isfile(generic_filename):
remove(generic_filename)
shutil.copy(filename, generic_filename)
# The user may not have a profile picture
return generic_filename
def _copy_file(filename, location, link):
copy = True
download_location = os.path.join(location, link.filename)
if os.path.exists(download_location):
response = ask_path_exists(
'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abort' %
display_path(download_location), ('i', 'w', 'b', 'a'))
if response == 'i':
copy = False
elif response == 'w':
logger.warning('Deleting %s', display_path(download_location))
os.remove(download_location)
elif response == 'b':
dest_file = backup_dir(download_location)
logger.warning(
'Backing up %s to %s',
display_path(download_location),
display_path(dest_file),
)
shutil.move(download_location, dest_file)
elif response == 'a':
sys.exit(-1)
if copy:
shutil.copy(filename, download_location)
logger.info('Saved %s', display_path(download_location))
def run(self):
_install.run(self)
print("Installing udev rules...")
if not os.path.isdir("/etc/udev/rules.d"):
print("WARNING: udev rules have not been installed (/etc/udev/rules.d is not a directory)")
return
try:
shutil.copy("./rivalcfg/data/99-steelseries-rival.rules", "/etc/udev/rules.d/")
except IOError:
print("WARNING: udev rules have not been installed (permission denied)")
return
try:
subprocess.call(["udevadm", "trigger"])
except OSError:
print("WARNING: unable to update udev rules, please run the 'udevadm trigger' command")
return
print("Done!")
def concatenate(out_file_name, all_in_file_names):
""" Concatenate a list of bam files into a final output file """
# Filter out empty BAM files -- these cause samtools cat to generate
# a BAM with a premature end block
in_file_names = [f for f in all_in_file_names if not bam_is_empty(f)]
if len(in_file_names) > 1:
args = ['samtools', 'cat', '-o', out_file_name]
args.extend(in_file_names)
subprocess.check_call(args)
elif len(in_file_names) == 0:
# If all the BAMs are empty, just copy 1 over
shutil.copy(all_in_file_names[0], out_file_name)
else:
shutil.copy(in_file_names[0], out_file_name)
def post_action(self):
mbed_tools_path = self.get_tools_dir()
if not mbed_tools_path and (self.is_classic or os.path.exists(os.path.join(self.path, Cfg.file))):
self.add_tools(os.path.join(self.path, '.temp'))
mbed_tools_path = self.get_tools_dir()
if not mbed_tools_path:
warning("Cannot find the mbed tools directory in \"%s\"" % self.path)
return False
if (not os.path.isfile(os.path.join(self.path, 'mbed_settings.py')) and
os.path.isfile(os.path.join(mbed_tools_path, 'default_settings.py'))):
shutil.copy(os.path.join(mbed_tools_path, 'default_settings.py'), os.path.join(self.path, 'mbed_settings.py'))
self.check_requirements(True)
def copyFromReader(self, reader, sourcePath, destPath):
"""
Copy the sourcePath in the provided UFOReader to destPath
in this writer. The paths must be relative. They may represent
directories or paths. This uses the most memory efficient
method possible for copying the data possible.
"""
if not isinstance(reader, UFOReader):
raise UFOLibError("The reader must be an instance of UFOReader.")
fullSourcePath = os.path.join(reader._path, sourcePath)
if not reader._checkForFile(fullSourcePath):
raise UFOLibError("No file named \"%s\" to copy from." % sourcePath)
fullDestPath = os.path.join(self._path, destPath)
if os.path.exists(fullDestPath):
raise UFOLibError("A file named \"%s\" already exists." % sourcePath)
self._buildDirectoryTree(destPath)
if os.path.isdir(fullSourcePath):
shutil.copytree(fullSourcePath, fullDestPath)
else:
shutil.copy(fullSourcePath, fullDestPath)
# UFO mod time
def summonMagic():
import magic
if hasattr(magic, 'from_file'):
# https://pypi.python.org/pypi/python-magic
return magic
elif hasattr(magic, 'open'):
# http://www.darwinsys.com/file/, in Debian as python3-magic
class WrapMagic:
def __init__(self):
self.magic = magic.open(magic.NONE)
self.magic.load()
def from_file(self, name):
return self.magic.file(name)
return WrapMagic()
else:
raise NotImplementedError("I do not understand your magic")
### directory copy ###
def load_layer_index(self):
# Load Layer_Index
# Check if we have a mirror-index, and load it if we do...
mirror_index_path = self.load_mirror_index(self.base_url + '/mirror-index')
# Mirror also has a copy of the associated XML bits
if mirror_index_path:
self.xml_dir = os.path.join(mirror_index_path, 'xml')
# Setup replace strings as late as possible. The various self.* values
# may be modified prior to this place.
replace = []
replace = replace + settings.REPLACE
replace = replace + [
( '#INSTALL_DIR#', self.install_dir ),
( '#BASE_URL#', self.base_url ),
( '#BASE_BRANCH#', self.base_branch ),
]
self.index = Layer_Index(indexcfg=settings.INDEXES, base_branch=self.base_branch, replace=replace, mirror=mirror_index_path)
def sourcecpy(src, des):
src = os.path.normpath(src)
des = os.path.normpath(des)
if not os.path.exists(src) or not os.path.exists(src):
print("folder is not exist")
sys.exit(1)
# ?????????????????????????
os.chdir(src)
src_file = [os.path.join(src, file) for file in os.listdir()]
for source in src_file:
# ????
if os.path.isfile(source):
shutil.copy(source, des) # ????????????????
# ????
if os.path.isdir(source):
p, src_name = os.path.split(source)
des = os.path.join(des, src_name)
shutil.copytree(source, des) # ??????????????????
# ??CLI?????
def __unitsNumChanged(self):
if hasattr(self,"auto_result"):
if self.autoSortThisCheck.isChecked():
self.saveChannelCheck.setChecked(False)
self.chnResultPool.pop(self.selectChan,None)
self.units = self.auto_result.copy()
self.units[self.units>int(self.unitsNumWgt.currentText())] = 0
self.__draw_pk3()
self.__update_pk3_roi()
self.__draw_pk2()
if self.pca_3d is True:
self.__draw_3D_PCA()
# The SpikeSorting class use this class to draw multiple lines quickly in a memory-efficient way.
def __unitsNumChanged(self):
if hasattr(self,"auto_result"):
if self.autoSortThisCheck.isChecked():
self.saveChannelCheck.setChecked(False)
self.chnResultPool.pop(self.selectChan,None)
self.units = self.auto_result.copy()
self.units[self.units>int(self.unitsNumWgt.currentText())] = 0
self.__draw_pk3()
self.__update_pk3_roi()
self.__draw_pk2()
if self.pca_3d is True:
self.__draw_3D_PCA()
# The SpikeSorting class use this class to draw multiple lines quickly in a memory-efficient way.
def _copy_file(filename, location, content_type, link):
copy = True
download_location = os.path.join(location, link.filename)
if os.path.exists(download_location):
response = ask_path_exists(
'The file %s exists. (i)gnore, (w)ipe, (b)ackup ' %
display_path(download_location), ('i', 'w', 'b'))
if response == 'i':
copy = False
elif response == 'w':
logger.warn('Deleting %s' % display_path(download_location))
os.remove(download_location)
elif response == 'b':
dest_file = backup_dir(download_location)
logger.warn('Backing up %s to %s'
% (display_path(download_location), display_path(dest_file)))
shutil.move(download_location, dest_file)
if copy:
shutil.copy(filename, download_location)
logger.notify('Saved %s' % display_path(download_location))
def test_updates_package(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements.txt', requirements)
args = ['-r', requirements]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated flask: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_updates_package_in_nested_requirements(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements-with-nested-reqfile.txt')
requirements_nested = os.path.join(tempdir, 'requirements-nested.txt')
shutil.copy('tests/samples/requirements-with-nested-reqfile.txt', requirements)
shutil.copy('tests/samples/requirements-nested.txt', requirements_nested)
args = ['-r', requirements]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'readtime'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated readtime: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package_in_nested_requirements').read()
self.assertEquals(open(requirements).read(), expected_requirements)
expected_requirements = open('tests/samples/results/test_updates_package_in_nested_requirements_nested').read()
self.assertEquals(open(requirements_nested).read(), expected_requirements)
def test_requirements_long_option_accepted(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements.txt', requirements)
args = ['--requirement', requirements]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated flask: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_exit_code_from_no_updates(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements-up-to-date.txt', requirements)
args = ['-r', requirements, '--nonzero-exit-code']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertEqual(result.exception.code, 10)
expected_output = "All requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 10)
expected_requirements = open('tests/samples/results/test_updates_package').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_exit_code_from_nested_requirements_file(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements-with-nested-reqfile.txt')
requirements_nested = os.path.join(tempdir, 'requirements-nested.txt')
shutil.copy('tests/samples/requirements-with-nested-reqfile.txt', requirements)
shutil.copy('tests/samples/requirements-nested.txt', requirements_nested)
args = ['-r', requirements, '--nonzero-exit-code']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'readtime'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertEqual(result.exception.code, 11)
expected_output = "Updated readtime: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 11)
expected_requirements = open('tests/samples/results/test_updates_package_in_nested_requirements').read()
self.assertEquals(open(requirements).read(), expected_requirements)
expected_requirements = open('tests/samples/results/test_updates_package_in_nested_requirements_nested').read()
self.assertEquals(open(requirements_nested).read(), expected_requirements)
def test_no_recursive_option(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements-with-nested-reqfile.txt')
requirements_nested = os.path.join(tempdir, 'requirements-nested.txt')
shutil.copy('tests/samples/requirements-with-nested-reqfile.txt', requirements)
shutil.copy('tests/samples/requirements-nested.txt', requirements_nested)
args = ['-r', requirements, '-n']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'readtime'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "All requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/requirements-with-nested-reqfile.txt').read()
self.assertEquals(open(requirements).read(), expected_requirements)
expected_requirements = open('tests/samples/requirements-nested.txt').read()
self.assertEquals(open(requirements_nested).read(), expected_requirements)
def test_skip_package(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements-multiple.txt', requirements)
args = ['-r', requirements, '-s', 'flask']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated Alembic: 0.9 -> 0.10.1\nUpdated sqlalchemy: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_skip_package').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_skip_multiple_packages(self):
requirements = 'tests/samples/requirements-multiple.txt'
tempdir = tempfile.mkdtemp()
tmpfile = os.path.join(tempdir, 'requirements.txt')
shutil.copy(requirements, tmpfile)
args = ['-r', tmpfile, '-s', 'flask, alembic , SQLAlchemy']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "All requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open(requirements).read()
self.assertEquals(open(tmpfile).read(), expected_requirements)
def test_only(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements-multiple.txt', requirements)
args = ['-r', requirements, '--only', 'flask']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated flask: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_only').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_updates_package_with_no_version_specified(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements.txt', requirements)
args = ['-r', requirements, '-f']
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated flask: 0.9 -> 0.10.1\nUpdated flask: Unknown -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package_with_no_version_specified').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_invalid_package(self):
requirements = 'tests/samples/requirements.txt'
tempdir = tempfile.mkdtemp()
tmpfile = os.path.join(tempdir, 'requirements.txt')
shutil.copy(requirements, tmpfile)
args = ['-r', tmpfile]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
mock_find_all_candidates.return_value = []
result = self.runner.invoke(pur, args)
expected_output = "All requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertIsNone(result.exception)
self.assertEquals(result.exit_code, 0)
self.assertEquals(open(tmpfile).read(), open(requirements).read())
def test_no_arguments(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements.txt', requirements)
args = []
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'flask'
version = '0.10.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
with self.cd(tempdir):
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated flask: 0.9 -> 0.10.1\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_updates_package_with_number_in_name(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements-version-in-name.txt', requirements)
args = ['-r', requirements]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'package1'
version = '2.0'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated package1: 1 -> 2.0\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package_with_version_in_name').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_updates_package_with_extras(self):
tempdir = tempfile.mkdtemp()
requirements = os.path.join(tempdir, 'requirements.txt')
shutil.copy('tests/samples/requirements-with-extras.txt', requirements)
args = ['-r', requirements]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'firstpackage'
version = '2.0'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
expected_output = "Updated firstpackage1: 1 -> 2.0\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertIsNone(result.exception)
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package_with_extras').read()
self.assertEquals(open(requirements).read(), expected_requirements)
def test_max_version_spec_prevents_updating_package(self):
requirements = 'tests/samples/requirements-with-max-version-spec.txt'
tempdir = tempfile.mkdtemp()
tmpfile = os.path.join(tempdir, 'requirements.txt')
shutil.copy(requirements, tmpfile)
args = ['-r', tmpfile]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'afakepackage'
version = '2.0'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "All requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open(tmpfile).read()
self.assertEquals(open(tmpfile).read(), expected_requirements)
def test_notequal_version_spec_prevents_updating_package(self):
requirements = 'tests/samples/requirements-multiline.txt'
tempdir = tempfile.mkdtemp()
tmpfile = os.path.join(tempdir, 'requirements.txt')
shutil.copy(requirements, tmpfile)
args = ['-r', tmpfile]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'afakepackage'
version = '0.9.1'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "All requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open(tmpfile).read()
self.assertEquals(open(tmpfile).read(), expected_requirements)
def test_updates_package_with_multiline_spec(self):
requirements = 'tests/samples/requirements-multiline.txt'
tempdir = tempfile.mkdtemp()
tmpfile = os.path.join(tempdir, 'requirements.txt')
shutil.copy(requirements, tmpfile)
args = ['-r', tmpfile]
with utils.mock.patch('pip._internal.index.PackageFinder.find_all_candidates') as mock_find_all_candidates:
project = 'afakepackage'
version = '1.0'
link = Link('')
candidate = InstallationCandidate(project, version, link)
mock_find_all_candidates.return_value = [candidate]
result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = "Updated afakepackage: 0.9 -> 1.0\nUpdated afakepackage: 0.9 -> 1.0\nAll requirements up-to-date.\n"
self.assertEquals(u(result.output), u(expected_output))
self.assertEquals(result.exit_code, 0)
expected_requirements = open('tests/samples/results/test_updates_package_with_multiline_spec').read()
self.assertEquals(open(tmpfile).read(), expected_requirements)