def test_comparison(self): """Validate we can compare VersionSplitPackageOrder together.""" inst1 = VersionSplitPackageOrder(first_version=Version("1.2.3")) inst2 = VersionSplitPackageOrder(first_version=Version("1.2.3")) inst3 = VersionSplitPackageOrder(first_version=Version("1.2.4")) self.assertTrue(inst1 == inst2) # __eq__ positive self.assertFalse(inst1 == inst3) # __eq__ negative self.assertTrue(inst1 != inst3) # __ne__ positive self.assertFalse(inst1 != inst2) # __ne__ negative self.assertFalse(inst1 == "wrong_type") # __eq__ negative (wrong type) self.assertTrue(inst1 != "wrong_type") # __eq__ negative (wrong type)
def test_from_pod_old_style(self): """Validate from_pod is still compatible with the older pod style.""" self.assertEqual( VersionSplitPackageOrder(first_version=Version("1.2.3")), from_pod(("version_split", { "first_version": "1.2.3" })))
def test_pod(self): """Validate we can save and load a PackageOrdererList to pod representation.""" inst = PackageOrderList( (VersionSplitPackageOrder(Version("2.6.0")), PerFamilyOrder(order_dict={}, default_order=SortedOrder(descending=False)))) self._test_pod(inst)
def test_9(self): """test package orderers.""" from rez.package_order import NullPackageOrder, PerFamilyOrder, \ VersionSplitPackageOrder, TimestampPackageOrder, SortedOrder, \ to_pod, from_pod def _test(orderer, package_name, expected_order): it = iter_packages(package_name) descending = sorted(it, key=lambda x: x.version, reverse=True) pod = to_pod(orderer) orderer2 = from_pod(pod) for orderer_ in (orderer, orderer2): ordered = orderer_.reorder(descending) result = [str(x.version) for x in ordered] self.assertEqual(result, expected_order) null_orderer = NullPackageOrder() split_orderer = VersionSplitPackageOrder(Version("2.6.0")) # after v1.1.0 and before v1.1.1 timestamp_orderer = TimestampPackageOrder(timestamp=3001, rank=3) # after v2.1.0 and before v2.1.5 timestamp2_orderer = TimestampPackageOrder(timestamp=7001, rank=3) expected_null_result = ["7", "6", "5"] expected_split_result = ["2.6.0", "2.5.2", "2.7.0", "2.6.8"] expected_timestamp_result = [ "1.1.1", "1.1.0", "1.0.6", "1.0.5", "1.2.0", "2.0.0", "2.1.5", "2.1.0" ] expected_timestamp2_result = [ "2.1.5", "2.1.0", "2.0.0", "1.2.0", "1.1.1", "1.1.0", "1.0.6", "1.0.5" ] _test(null_orderer, "pysplit", expected_null_result) _test(split_orderer, "python", expected_split_result) _test(timestamp_orderer, "timestamped", expected_timestamp_result) _test(timestamp2_orderer, "timestamped", expected_timestamp2_result) fam_orderer = PerFamilyOrder( order_dict=dict(pysplit=null_orderer, python=split_orderer, timestamped=timestamp_orderer), default_order=SortedOrder(descending=False)) _test(fam_orderer, "pysplit", expected_null_result) _test(fam_orderer, "python", expected_split_result) _test(fam_orderer, "timestamped", expected_timestamp_result) _test(fam_orderer, "pymum", ["1", "2", "3"])
def test_reorder(self): """Test ordering.""" expected_null_result = ["7", "6", "5"] expected_split_result = ["2.6.0", "2.5.2", "2.7.0", "2.6.8"] expected_timestamp_result = [ "1.1.1", "1.1.0", "1.0.6", "1.0.5", "1.2.0", "2.0.0", "2.1.5", "2.1.0" ] orderer = PerFamilyOrder(order_dict=dict( pysplit=NullPackageOrder(), python=VersionSplitPackageOrder(Version("2.6.0")), timestamped=TimestampPackageOrder(timestamp=3001, rank=3)), default_order=SortedOrder(descending=False)) self._test_reorder(orderer, "pysplit", expected_null_result) self._test_reorder(orderer, "python", expected_split_result) self._test_reorder(orderer, "timestamped", expected_timestamp_result) self._test_reorder(orderer, "pymum", ["1", "2", "3"])
def test_singleton(self): """Validate we can build a PackageOrderList object from configuration values.""" config.override("package_orderers", [{ "type": "per_family", "orderers": [{ "packages": ["python"], "type": "version_split", "first_version": "2.9.9" }] }]) expected = PackageOrderList() expected.append( PerFamilyOrder(order_dict={ "python": VersionSplitPackageOrder(Version("2.9.9")) })) # Clear @classproperty cache try: delattr(PackageOrderList, '_class_property_singleton') except AttributeError: pass self.assertEqual(expected, PackageOrderList.singleton)
def test_pod(self): """Validate we can save and load a VersionSplitPackageOrder to it's pod representation.""" self._test_pod( VersionSplitPackageOrder(first_version=Version("1.2.3")))
def test_repr(self): """Validate we can represent a VersionSplitPackageOrder as a string.""" inst = VersionSplitPackageOrder(first_version=Version("1,2,3")) self.assertEqual("VersionSplitPackageOrder(1,2,3)", repr(inst))
def test_reordere(self): """Validate package ordering with a VersionSplitPackageOrder""" orderer = VersionSplitPackageOrder(Version("2.6.0")) expected = ["2.6.0", "2.5.2", "2.7.0", "2.6.8"] self._test_reorder(orderer, "python", expected)
def test_repr(self): """Validate we can represent a PerFamilyOrder as a string.""" inst = PerFamilyOrder( order_dict={"family1": VersionSplitPackageOrder(Version("2.6.0"))}) self.assertEqual("PerFamilyOrder(([('family1', '2.6.0')], 'None'))", repr(inst))