def test_pod(self): """Validate we can save and load a PerFamilyOrder to it's pod representation.""" self._test_pod( PerFamilyOrder(order_dict={'foo': NullPackageOrder()}, default_order=NullPackageOrder())) # No default_order self._test_pod(PerFamilyOrder(order_dict={'foo': NullPackageOrder()}))
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_comparison(self): """Validate we can compare PerFamilyOrder.""" inst1 = PerFamilyOrder(order_dict={'foo': NullPackageOrder()}, default_order=NullPackageOrder()) inst2 = PerFamilyOrder(order_dict={'foo': NullPackageOrder()}, default_order=NullPackageOrder()) inst3 = PerFamilyOrder(order_dict={'bar': NullPackageOrder()}, default_order=NullPackageOrder()) inst4 = PerFamilyOrder(order_dict={'foo': NullPackageOrder()}, default_order=None) self.assertTrue(inst1 == inst2) # __eq__ positive self.assertFalse( inst1 == inst3) # __eq__ negative (different order dict) self.assertFalse( inst1 == inst4) # __eq__ negative (different default_order) self.assertTrue( inst1 != inst3) # __ne__ positive (different order dict) self.assertTrue( inst1 != inst4) # __ne__ positive (different default order) self.assertFalse(inst1 != inst2) # __ne__ negative
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_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))
def test_reorder_no_default_order(self): """Test behavior when there's no secondary default_order.""" fam_orderer = PerFamilyOrder(order_dict={}) self._test_reorder(fam_orderer, "pymum", ["3", "2", "1"])
def test_reorder_no_packages(self): """Validate ordering for a family with no packages.""" orderer = PerFamilyOrder(order_dict=dict( missing_package=NullPackageOrder())) self._test_reorder(orderer, "missing_package", [])