本文整理汇总了Python中enstaller.repository.Repository.has_package方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.has_package方法的具体用法?Python Repository.has_package怎么用?Python Repository.has_package使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enstaller.repository.Repository
的用法示例。
在下文中一共展示了Repository.has_package方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestRemoveAction
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import has_package [as 别名]
class TestRemoveAction(unittest.TestCase):
def setUp(self):
self.top_prefix = tempfile.mkdtemp()
self.top_installed_repository = Repository()
self.installed_repository = Repository()
def tearDown(self):
shutil.rmtree(self.top_prefix)
def _install_eggs(self, paths):
repository = Repository()
for path in paths:
package = RepositoryPackageMetadata.from_egg(path)
repository.add_package(package)
for path in paths:
action = InstallAction(path, self.top_prefix, repository,
self.top_installed_repository,
self.installed_repository,
os.path.dirname(path))
action.execute()
def test_simple(self):
# Given
filename = "nose-1.3.0-1.egg"
path = os.path.join(_EGGINST_COMMON_DATA, filename)
metadata = PackageMetadata.from_egg(path)
self._install_eggs([path])
# When
action = RemoveAction(path, self.top_prefix,
self.top_installed_repository,
self.installed_repository)
action.execute()
# Then
repository = Repository._from_prefixes([self.top_prefix])
self.assertFalse(repository.has_package(metadata))
self.assertFalse(self.top_installed_repository.has_package(metadata))
self.assertFalse(self.installed_repository.has_package(metadata))
self.assertFalse(action.is_canceled)
def test_iteration(self):
# Given
filename = "nose-1.3.0-1.egg"
path = os.path.join(_EGGINST_COMMON_DATA, filename)
metadata = PackageMetadata.from_egg(path)
self._install_eggs([path])
# When
action = RemoveAction(path, self.top_prefix,
self.top_installed_repository,
self.installed_repository)
for step in action:
pass
# Then
repository = Repository._from_prefixes([self.top_prefix])
self.assertFalse(repository.has_package(metadata))
self.assertFalse(self.top_installed_repository.has_package(metadata))
self.assertFalse(self.installed_repository.has_package(metadata))
self.assertFalse(action.is_canceled)
def test_iteration_cancel(self):
# Given
filename = "nose-1.3.0-1.egg"
path = os.path.join(_EGGINST_COMMON_DATA, filename)
metadata = PackageMetadata.from_egg(path)
self._install_eggs([path])
# When
action = RemoveAction(path, self.top_prefix,
self.top_installed_repository,
self.installed_repository)
for step in action:
action.cancel()
# Then
repository = Repository._from_prefixes([self.top_prefix])
self.assertFalse(repository.has_package(metadata))
self.assertFalse(self.top_installed_repository.has_package(metadata))
self.assertFalse(self.installed_repository.has_package(metadata))
self.assertTrue(action.is_canceled)
示例2: TestRepository
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import has_package [as 别名]
#.........这里部分代码省略.........
self.assertEqual(metadata.key, "nose-1.3.0-2.egg")
self.assertEqual(metadata.name, "nose")
self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-2"))
def test_find_unavailable_package(self):
# Given/When/Then
with self.assertRaises(NoSuchPackage):
self.repository.find_package("nono", "1.4.0-1")
def test_find_packages(self):
V = EnpkgVersion.from_string
# Given/When
metadata = list(self.repository.find_packages("nose"))
metadata = sorted(metadata, key=operator.attrgetter("version"))
# Then
self.assertEqual(len(metadata), 3)
self.assertEqual(metadata[0].version, V("1.2.1-1"))
self.assertEqual(metadata[1].version, V("1.3.0-1"))
self.assertEqual(metadata[2].version, V("1.3.0-2"))
def test_find_packages_with_version(self):
# Given/When
metadata = list(self.repository.find_packages("nose", "1.3.0-1"))
# Then
self.assertEqual(len(metadata), 1)
self.assertEqual(metadata[0].version,
EnpkgVersion.from_string("1.3.0-1"))
def test_has_package(self):
# Given
python = RUNNING_PYTHON
version = EnpkgVersion.from_string("1.3.0-1")
available_package = PackageMetadata("nose-1.3.0-1.egg", "nose",
version, [], python)
version = EnpkgVersion.from_string("1.4.0-1")
unavailable_package = PackageMetadata("nose-1.4.0-1.egg", "nose",
version, [], python)
# When/Then
self.assertTrue(self.repository.has_package(available_package))
self.assertFalse(self.repository.has_package(unavailable_package))
def test_iter_most_recent_packages(self):
# Given
eggs = ["nose-1.3.0-1.egg", "nose-1.2.1-1.egg"]
repository = Repository()
for egg in eggs:
path = os.path.join(_EGGINST_COMMON_DATA, egg)
package = RemotePackageMetadata.from_egg(path)
repository.add_package(package)
# When
metadata = list(repository.iter_most_recent_packages())
# Then
self.assertEqual(len(metadata), 1)
self.assertEqual(metadata[0].version,
EnpkgVersion.from_string("1.3.0-1"))
def test_iter_protocol(self):
示例3: TestRepository
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import has_package [as 别名]
#.........这里部分代码省略.........
self.assertEqual(metadata.key, "nose-1.3.0-2.egg")
self.assertEqual(metadata.name, "nose")
self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-2"))
def test_find_unavailable_package(self):
# Given/When/Then
with self.assertRaises(NoSuchPackage):
self.repository.find_package("nono", "1.4.0-1")
def test_find_packages(self):
V = EnpkgVersion.from_string
# Given/When
metadata = list(self.repository.find_packages("nose"))
metadata = sorted(metadata, key=operator.attrgetter("version"))
# Then
self.assertEqual(len(metadata), 3)
self.assertEqual(metadata[0].version, V("1.2.1-1"))
self.assertEqual(metadata[1].version, V("1.3.0-1"))
self.assertEqual(metadata[2].version, V("1.3.0-2"))
def test_find_packages_with_version(self):
# Given/When
metadata = list(self.repository.find_packages("nose", "1.3.0-1"))
# Then
self.assertEqual(len(metadata), 1)
self.assertEqual(metadata[0].version,
EnpkgVersion.from_string("1.3.0-1"))
def test_has_package(self):
# Given
version = EnpkgVersion.from_string("1.3.0-1")
available_package = PackageMetadata("nose-1.3.0-1.egg", "nose",
version, [], "2.7")
version = EnpkgVersion.from_string("1.4.0-1")
unavailable_package = PackageMetadata("nose-1.4.0-1.egg", "nose",
version, [], "2.7")
# When/Then
self.assertTrue(self.repository.has_package(available_package))
self.assertFalse(self.repository.has_package(unavailable_package))
def test_iter_most_recent_packages(self):
# Given
eggs = ["nose-1.3.0-1.egg", "nose-1.2.1-1.egg"]
repository = Repository()
for egg in eggs:
path = os.path.join(_EGGINST_COMMON_DATA, egg)
package = RepositoryPackageMetadata.from_egg(path)
repository.add_package(package)
# When
metadata = list(repository.iter_most_recent_packages())
# Then
self.assertEqual(len(metadata), 1)
self.assertEqual(metadata[0].version,
EnpkgVersion.from_string("1.3.0-1"))
def test_iter_packages(self):
# Given
示例4: TestRepository
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import has_package [as 别名]
#.........这里部分代码省略.........
self.assertEqual(metadata.key, "nose-1.3.0-2.egg")
self.assertEqual(metadata.name, "nose")
self.assertEqual(metadata.version, EnpkgVersion.from_string("1.3.0-2"))
def test_find_unavailable_package(self):
# Given/When/Then
with self.assertRaises(NoSuchPackage):
self.repository.find_package("nono", "1.4.0-1")
def test_find_packages(self):
V = EnpkgVersion.from_string
# Given/When
metadata = list(self.repository.find_packages("nose"))
metadata = sorted(metadata, key=operator.attrgetter("version"))
# Then
self.assertEqual(len(metadata), 3)
self.assertEqual(metadata[0].version, V("1.2.1-1"))
self.assertEqual(metadata[1].version, V("1.3.0-1"))
self.assertEqual(metadata[2].version, V("1.3.0-2"))
def test_find_packages_with_version(self):
# Given/When
metadata = list(self.repository.find_packages("nose", "1.3.0-1"))
# Then
self.assertEqual(len(metadata), 1)
self.assertEqual(metadata[0].version,
EnpkgVersion.from_string("1.3.0-1"))
def test_has_package(self):
# Given
version = EnpkgVersion.from_string("1.3.0-1")
available_package = PackageMetadata("nose-1.3.0-1.egg", "nose",
version, [], "2.7")
version = EnpkgVersion.from_string("1.4.0-1")
unavailable_package = PackageMetadata("nose-1.4.0-1.egg", "nose",
version, [], "2.7")
# When/Then
self.assertTrue(self.repository.has_package(available_package))
self.assertFalse(self.repository.has_package(unavailable_package))
def test_iter_most_recent_packages(self):
# Given
eggs = ["nose-1.3.0-1.egg", "nose-1.2.1-1.egg"]
repository = Repository()
for egg in eggs:
path = os.path.join(_EGGINST_COMMON_DATA, egg)
package = RemotePackageMetadata.from_egg(path)
repository.add_package(package)
# When
metadata = list(repository.iter_most_recent_packages())
# Then
self.assertEqual(len(metadata), 1)
self.assertEqual(metadata[0].version,
EnpkgVersion.from_string("1.3.0-1"))
def test_iter_packages(self):
# Given