def _RunExpectingPackages(self, expected_packages, package_dir=None): packages = jobs_prep.BuildPackages(package_dir or self.package_dir, self.output_path) self.assertSetEqual( set(packages), {os.path.join(self.output_path, p) for p in expected_packages})
def testBuildPackages_ErrorVerifyingWriteAccess(self): self.StartObjectPatch(files, 'HasWriteAccessInDir', side_effect=ValueError) with self.AssertRaisesExceptionMatches( jobs_prep.InvalidSourceDirError, os.path.dirname(self.package_dir)): jobs_prep.BuildPackages(self.package_dir, self.output_path)
def testBuildPackages_Generated(self): os.remove(os.path.join(self.package_parent, 'setup.py')) archive_paths = jobs_prep.BuildPackages(self.package_dir, self.output_dir) self._AssertArchivePathsOkay(archive_paths, package_name='test_package-0.0.0', additional_files=()) self._AssertPackageDirUnmodified(additional_files=())
def testBuildPackages_ExecFails(self): exit_codes = [1] * len(self.SETUPTOOLS_INVOCATIONS) self.exec_mock.side_effect = self._MakeFakeRunSetupTools( exit_code=exit_codes) with self.AssertRaisesExceptionMatches( jobs_prep.SetuptoolsFailedError, 'Packaging of user Python code failed with message:\n\n' 'Writing to stdout...\n' 'Writing to stderr...\n\n\n' 'Try manually building your Python code'): jobs_prep.BuildPackages(self.package_dir, self.output_path)
def testBuildPackagesExisting_UsesDistutils(self): with open(os.path.join(self.package_parent, 'setup.py'), 'w') as f: f.write( 'from distutils.core import setup\n' 'if __name__ == "__main__":\n' ' setup(name="package1", version="1.0", packages=["test_package"])' '\n') archive_paths = jobs_prep.BuildPackages(self.package_dir, self.output_dir) self._AssertArchivePathsOkay(archive_paths, additional_files=()) self._AssertPackageDirUnmodified(additional_files=('setup.py', 'MANIFEST'))
def testBuildPackages_ExecFailsGenerated(self): os.unlink(os.path.join(self.package_root, 'setup.py')) exit_codes = [1] * len(self.SETUPTOOLS_INVOCATIONS) self.exec_mock.side_effect = self._MakeFakeRunSetupTools( exit_code=exit_codes, setup_py_contents=_GENERATED_SETUP_PY) with self.AssertRaisesExceptionMatches( jobs_prep.SetuptoolsFailedError, 'Packaging of user Python code failed with message:\n\n' 'Writing to stdout...\n' 'Writing to stderr...\n\n\n' 'Try manually writing a setup.py file'): jobs_prep.BuildPackages(self.package_dir, self.output_path)
def testBuildPackages_TempDirInSubdirUnwritable(self): # Making a temporary directory *inside* of the package root. This should # result in an error, since we *do* have to make a copy here (that would # result in an infinite loop). other_temp_dir = os.path.join(self.package_root, 'tmp') files.MakeDir(other_temp_dir) self.StartObjectPatch(files, 'TemporaryDirectory', return_value=DummyContextManager(other_temp_dir)) with _UnwritableDirectory(self.package_root): with self.AssertRaisesExceptionMatches( jobs_prep.UncopyablePackageError, ('Cannot copy directory since working directory [{}] is inside of ' 'source directory [{}]').format(other_temp_dir, self.package_root)): jobs_prep.BuildPackages(self.package_dir, self.output_path)
def testBuildPackages_SourceDirDoesNotExist(self): bad_dir = 'junk/junk' with self.AssertRaisesExceptionMatches(jobs_prep.InvalidSourceDirError, 'junk'): jobs_prep.BuildPackages(bad_dir, self.output_path)
def testBuildPackages_NoSysExecutable(self): self.StartDictPatch(os.environ, {}, clear=True) self.get_python_mock.side_effect = ValueError() with self.assertRaises(jobs_prep.SysExecutableMissingError): jobs_prep.BuildPackages(self.package_dir, self.output_path)
def testBuildPackages_NoInitPy(self): os.unlink(os.path.join(self.package_dir, '__init__.py')) with self.AssertRaisesExceptionMatches(jobs_prep.MissingInitError, self.package_dir): jobs_prep.BuildPackages(self.package_dir, self.output_path)
def testBuildPackagesExisting_ReadOnly(self): with _UnwritableDirectory(self.package_parent): archive_paths = jobs_prep.BuildPackages(self.package_dir, self.output_dir) self._AssertArchivePathsOkay(archive_paths) self._AssertPackageDirUnmodified()
def testBuildPackagesExisting_Writable(self): archive_paths = jobs_prep.BuildPackages(self.package_dir, self.output_dir) self._AssertArchivePathsOkay(archive_paths) self._AssertPackageDirUnmodified()