def test_variant_install(self): """test variant installation.""" repo_path = os.path.join(self.root, "packages") if not os.path.exists(repo_path): os.makedirs(repo_path) def _data(obj): d = obj.validated_data() keys = package_release_keys + ("base", ) for key in keys: d.pop(key, None) return d # package with variants and package without dev_pkgs_list = (("developer", "developer_changed"), ("developer_novar", "developer_novar_changed")) for path1, path2 in dev_pkgs_list: path = os.path.join(self.packages_base_path, path1) package = get_developer_package(path) # install variants of the developer package into new repo variant = next(package.iter_variants()) result = variant.install(repo_path, dry_run=True) self.assertEqual(result, None) for variant in package.iter_variants(): variant.install(repo_path) variant = next(package.iter_variants()) result = variant.install(repo_path, dry_run=True) self.assertNotEqual(result, None) # now there should be a package that matches the dev package installed_package = get_package(package.name, package.version, paths=[repo_path]) data = _data(package) data_ = _data(installed_package) self.assertDictEqual(data, data_) # make a change in the dev pkg, outside of the variants. path = os.path.join(self.packages_base_path, path2) package = get_developer_package(path) # install a variant again. Even though the variant is already installed, # this should update the package, because data outside the variant changed. variant = next(package.iter_variants()) result = variant.install(repo_path, dry_run=True) self.assertEqual(result, None) variant.install(repo_path) # check that the change was applied. This effectively also checks that the # variant order hasn't changed. installed_package = get_package(package.name, package.version, paths=[repo_path]) data = _data(package) data_ = _data(installed_package) self.assertDictEqual(data, data_)
def test_cache_fail_per_repo(self): """Test that caching fails on a package from a repo set to non-cachable.""" pkgcache = self._pkgcache() package = get_package("pyfoo", "3.1.0") variant = next(package.iter_variants()) with self.assertRaises(PackageCacheError): pkgcache.add_variant(variant)
def test_cache_fail_no_variant_payload(self): """Test that adding a variant with no disk payload, fails.""" pkgcache = self._pkgcache() package = get_package("variants_py", "2.0") variant = next(package.iter_variants()) with self.assertRaises(PackageCacheError): pkgcache.add_variant(variant)
def test_cache_fail_uncachable_variant(self): """Test that caching of an uncachable variant fails.""" pkgcache = self._pkgcache() package = get_package("timestamped", "1.1.1") variant = next(package.iter_variants()) with self.assertRaises(PackageCacheError): pkgcache.add_variant(variant)
def test_cache_fail_per_package(self): """Test that caching fails on a package with a blacklisted name.""" pkgcache = self._pkgcache() package = get_package("late_binding", "1.0") variant = next(package.iter_variants()) with self.assertRaises(PackageCacheError): pkgcache.add_variant(variant)
def test_cache_variant(self): """Test direct caching of a cachable variant.""" pkgcache = self._pkgcache() package = get_package("versioned", "3.0") variant = next(package.iter_variants()) _, status = pkgcache.add_variant(variant) self.assertEqual(status, PackageCache.VARIANT_CREATED) # adding again should indicate the variant is already cached _, status = pkgcache.add_variant(variant) self.assertEqual(status, PackageCache.VARIANT_FOUND)
def test_delete_cached_variant(self): """Test variant deletion from cache.""" pkgcache = self._pkgcache() package = get_package("versioned", "3.0") variant = next(package.iter_variants()) pkgcache.add_variant(variant) result = pkgcache.remove_variant(variant) self.assertEqual(result, PackageCache.VARIANT_REMOVED) # another deletion should say not found result = pkgcache.remove_variant(variant) self.assertEqual(result, PackageCache.VARIANT_NOT_FOUND)
def test_variant_iteration(self): """test variant iteration.""" base = canonical_path( os.path.join(self.py_packages_path, "variants_py", "2.0")) expected_data = dict( name="variants_py", version=Version("2.0"), description="package with variants", base=base, requires=[PackageRequest("python-2.7")], commands=SourceCode('env.PATH.append("{root}/bin")')) package = get_package("variants_py", "2.0") for i, variant in enumerate(package.iter_variants()): data = variant.validated_data() self.assertDictEqual(data, expected_data) self.assertEqual(variant.index, i) self.assertEqual(variant.parent, package)
def test_pkg_data(self): """check package contents.""" # a py-based package package = get_package("versioned", "3.0") expected_data = dict( name="versioned", version=Version("3.0"), base=canonical_path( os.path.join(self.py_packages_path, "versioned", "3.0")), commands=SourceCode('env.PATH.append("{root}/bin")')) data = package.validated_data() self.assertDictEqual(data, expected_data) # a yaml-based package package = get_package("versioned", "2.0") expected_uri = canonical_path( os.path.join(self.yaml_packages_path, "versioned", "2.0", "package.yaml")) self.assertEqual(package.uri, expected_uri) # a py-based package with late binding attribute functions package = get_package("late_binding", "1.0") self.assertEqual(package.tools, ["util"]) # a 'combined' type package package = get_package("multi", "1.0") expected_uri = canonical_path( os.path.join(self.yaml_packages_path, "multi.yaml<1.0>")) self.assertEqual(package.uri, expected_uri) expected_data = dict(name="multi", version=Version("1.0"), tools=["tweak"]) data = package.validated_data() self.assertDictEqual(data, expected_data) # a 'combined' type package, with version overrides package = get_package("multi", "1.1") expected_uri = canonical_path( os.path.join(self.yaml_packages_path, "multi.yaml<1.1>")) self.assertEqual(package.uri, expected_uri) expected_data = dict(name="multi", version=Version("1.1"), tools=["twerk"]) data = package.validated_data() self.assertDictEqual(data, expected_data) # check that visibility of 'combined' packages is correct package = get_package("multi", "2.0") expected_uri = canonical_path( os.path.join(self.py_packages_path, "multi.py<2.0>")) self.assertEqual(package.uri, expected_uri)
def test_variant_from_uri(self): """Test getting a variant from its uri.""" package = get_package("variants_py", "2.0") for variant in package.iter_variants(): variant2 = get_variant_from_uri(variant.uri) self.assertEqual(variant, variant2)
def test_package_from_uri(self): """Test getting a package from its uri.""" package = get_package("variants_py", "2.0") package2 = get_package_from_uri(package.uri) self.assertEqual(package, package2)