Beispiel #1
0
    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"])
Beispiel #2
0
 def test_comparison(self):
     """Validate we can compare TimestampPackageOrder."""
     inst1 = TimestampPackageOrder(timestamp=1, rank=1)
     inst2 = TimestampPackageOrder(timestamp=1, rank=1)
     inst3 = TimestampPackageOrder(timestamp=2, rank=1)
     inst4 = TimestampPackageOrder(timestamp=2, rank=2)
     self.assertTrue(inst1 == inst2)  # __eq__ positive
     self.assertFalse(
         inst1 == inst3)  # __eq__ negative (different timestamp)
     self.assertFalse(inst1 == inst4)  # __eq__ negative (different rank)
     self.assertTrue(
         inst1 != inst3)  # __ne__ positive (different timestamp)
     self.assertTrue(inst1 != inst4)  # __ne__ positive (different rank)
     self.assertFalse(inst1 != inst2)  # __ne__ negative
Beispiel #3
0
 def test_reorder_all_packages_after_timestamp(self):
     """Test behavior when all packages are after the timestamp."""
     timestamp_orderer = TimestampPackageOrder(timestamp=0, rank=3)
     expected = [
         '1.0.6', '1.0.5', '1.1.1', '1.1.0', '1.2.0', '2.0.0', '2.1.5',
         '2.1.0'
     ]
     self._test_reorder(timestamp_orderer, "timestamped", expected)
Beispiel #4
0
 def test_reorder_rank_2(self):
     """Add coverage for a corner case where there's only one candidate without the rank."""
     orderer = TimestampPackageOrder(timestamp=4001, rank=3)  # 1.1.1
     expected = [
         '1.1.1', '1.1.0', '1.0.6', '1.0.5', '1.2.0', '2.0.0', '2.1.5',
         '2.1.0'
     ]
     self._test_reorder(orderer, "timestamped", expected)
Beispiel #5
0
    def test_reorder_rank_3(self):
        """Validate reordering with a rank of 3."""
        # after v1.1.0 and before v1.1.1
        orderer1 = TimestampPackageOrder(timestamp=3001, rank=3)
        expected1 = [
            "1.1.1", "1.1.0", "1.0.6", "1.0.5", "1.2.0", "2.0.0", "2.1.5",
            "2.1.0"
        ]
        self._test_reorder(orderer1, "timestamped", expected1)

        # after v2.1.0 and before v2.1.5
        orderer2 = TimestampPackageOrder(timestamp=7001, rank=3)
        expected2 = [
            "2.1.5", "2.1.0", "2.0.0", "1.2.0", "1.1.1", "1.1.0", "1.0.6",
            "1.0.5"
        ]
        self._test_reorder(orderer2, "timestamped", expected2)
Beispiel #6
0
 def test_reorder_no_rank(self):
     """Validate reordering with a rank of 0."""
     orderer = TimestampPackageOrder(timestamp=3001)
     expected = [
         '1.1.0', '1.0.6', '1.0.5', '1.1.1', '1.2.0', '2.0.0', '2.1.0',
         '2.1.5'
     ]
     self._test_reorder(orderer, "timestamped", expected)
Beispiel #7
0
    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"])
Beispiel #8
0
 def test_pod(self):
     """Validate we can save and load a TimestampPackageOrder to pod representation."""
     self._test_pod(TimestampPackageOrder(timestamp=3001, rank=3))
Beispiel #9
0
 def test_repr(self):
     """Validate we can represent a TimestampPackageOrder as a string."""
     inst = TimestampPackageOrder(timestamp=1, rank=2)
     self.assertEqual(repr(inst), "TimestampPackageOrder((1, 2))")
Beispiel #10
0
 def test_reorder_packages_without_timestamps(self):
     """Validate reordering of packages that have no timestamp data."""
     orderer = TimestampPackageOrder(timestamp=3001)
     self._test_reorder(orderer, "pymum", ["3", "2", "1"])