コード例 #1
0
    def test_compare(self):
        assert ContextValue.compare("1", "1") == 0
        assert ContextValue.compare("a", "a") == 0

        assert ContextValue.compare("rawhide", "aaa") == 1
        assert ContextValue.compare("rawhide", "9999") == 1

        assert ContextValue.compare("8", "19") == -1
コード例 #2
0
 def test_creation(self):
     for created in [
             Context(dim_a="value", dim_b=["val"], dim_c=["foo", "bar"]),
             Context("dim_a=value and dim_b=val and dim_c == foo,bar")]:
         assert created._dimensions["dim_a"] == set([ContextValue("value")])
         assert created._dimensions["dim_b"] == set([ContextValue("val")])
         assert created._dimensions["dim_c"] == set(
             [ContextValue("foo"), ContextValue("bar")])
     # Invalid ways to create Context
     with pytest.raises(InvalidContext):
         Context("a=b", "c=d")  # Just argument
     with pytest.raises(InvalidContext):
         Context("a=b or c=d")  # Can't use OR
     with pytest.raises(InvalidContext):
         Context("a < d")  # Operator other than =/==
コード例 #3
0
    def test_parse_rule(self):
        """ Rule parsing """
        for invalid in self.rule_groups_invalid + self.invalid_expressions:
            with pytest.raises(InvalidRule):
                Context.parse_rule(invalid)

        assert Context.parse_rule("dim is defined") == [
            [("dim", "is defined", None)]]
        assert Context.parse_rule("dim < value") == [
            [("dim", "<", [ContextValue("value")])]]
        assert Context.parse_rule("dim < value-123") == [
            [("dim", "<", [ContextValue("value-123")])]]
        assert Context.parse_rule("dim ~< value, second") == [
            [("dim", "~<", [ContextValue("value"), ContextValue("second")])]]
        assert Context.parse_rule(
            "dim < value and dim > valueB or dim != valueC") == [
            [
                ("dim", "<", [ContextValue("value")]),
                ("dim", ">", [ContextValue("valueB")])],
            [
                ("dim", "!=", [ContextValue("valueC")])]]
コード例 #4
0
 def test_prints(self):
     f33 = ContextValue("fedora-33")
     str(f33)
     repr(f33)
コード例 #5
0
    def test_version_cmp_fedora(self):
        """ Fedora comparison """
        f33 = ContextValue("fedora-33")
        frawhide = ContextValue("fedora-rawhide")

        assert f33.version_cmp(ContextValue("fedora-33")) == 0
        assert f33.version_cmp(ContextValue("fedora-13")) > 0
        assert f33.version_cmp(ContextValue("fedora-43")) < 0

        assert frawhide.version_cmp(ContextValue("fedora-rawhide")) == 0
        assert frawhide.version_cmp(f33) > 0
        assert f33.version_cmp(frawhide) < 0
コード例 #6
0
    def test_version_cmp(self):
        first = ContextValue("name")
        assert first.version_cmp(ContextValue("name")) == 0
        assert first.version_cmp(ContextValue("name"), minor_mode=True) == 0
        assert first.version_cmp(ContextValue("name"), ordered=True) == 0
        assert first.version_cmp(ContextValue("name"), ordered=False) == 0

        assert first.version_cmp(ContextValue("name-1"), ordered=False) == 1
        with pytest.raises(CannotDecide):
            first.version_cmp(ContextValue("name-1"),
                              minor_mode=True,
                              ordered=False)
        with pytest.raises(CannotDecide):
            first.version_cmp(
                ContextValue("name-1"),
                ordered=True) == -1  # name missing at least on version part
        with pytest.raises(CannotDecide):
            first.version_cmp(ContextValue("name-1"),
                              minor_mode=True,
                              ordered=True)

        assert first.version_cmp(ContextValue("name-1-2"),
                                 ordered=False) == 1  # name-0.0 != name-1-2

        with pytest.raises(CannotDecide):
            first.version_cmp(ContextValue("name-1-2"),
                              minor_mode=True,
                              ordered=False)

        second = ContextValue("name-1-2-3")
        assert second.version_cmp(ContextValue("name"), ordered=False) == 0
        assert second.version_cmp(ContextValue("name"), ordered=True) == 0
        assert second.version_cmp(ContextValue("name"),
                                  minor_mode=True,
                                  ordered=False) == 0
        assert second.version_cmp(ContextValue("name"),
                                  minor_mode=True,
                                  ordered=True) == 0
        assert second.version_cmp(ContextValue("name-1")) == 0
        assert second.version_cmp(ContextValue("name-1"), minor_mode=True) == 0
        # Same minor
        assert second.version_cmp(ContextValue("name-1-2")) == 0
        assert (second.version_cmp(ContextValue("name-1-2"),
                                   minor_mode=True) == 0)

        third = ContextValue("name-1-2-3")
        with pytest.raises(CannotDecide):
            third.version_cmp(ContextValue("aaa"))
        with pytest.raises(CannotDecide):
            third.version_cmp(ContextValue("zzz"))
        with pytest.raises(CannotDecide):
            third.version_cmp(ContextValue("aaa"), minor_mode=True)

        # Minor mode should care only about minor, aka Y presence
        # so name-1 vs name-2 is defined, but name-1-1 vs name-2-1 is not
        fourth = ContextValue("name-2")
        assert fourth.version_cmp(ContextValue("name-2")) == 0
        assert fourth.version_cmp(ContextValue("name-2"), minor_mode=True) == 0
        assert fourth.version_cmp(ContextValue("name-3")) < 0
        assert fourth.version_cmp(ContextValue("name-3"),
                                  minor_mode=True) == -1
        assert fourth.version_cmp(ContextValue("name-1")) > 0
        assert fourth.version_cmp(ContextValue("name-1"), minor_mode=True) == 1
        with pytest.raises(CannotDecide):
            assert fourth.version_cmp(ContextValue("name-1-1"),
                                      minor_mode=True)

        fifth = ContextValue("name-2-1")
        for undecidable in ["name-1-1", ""]:
            with pytest.raises(CannotDecide):
                fifth.version_cmp(ContextValue(undecidable), minor_mode=True)

        # More error states
        with pytest.raises(CannotDecide):
            first.version_cmp(Context())  # different object classes

        sixth = ContextValue([])
        with pytest.raises(CannotDecide):
            sixth.version_cmp(first, minor_mode=True)
        with pytest.raises(CannotDecide):
            sixth.version_cmp(first)
        assert sixth != Context()
コード例 #7
0
 def test_eq(self):
     assert ContextValue("name") == ContextValue("name")
     assert ContextValue("name1-2-3") == ContextValue("name1-2-3")
     assert ContextValue("name1-2-3") != ContextValue("name1-2-4")
     assert ContextValue("foo") != ContextValue("bar")
     assert ContextValue("value-123") == ContextValue(["value", "123"])
コード例 #8
0
 def test_split_to_version(self):
     """ Possible/impossible splitting to version"""
     for name in self.impossible_split:
         assert ContextValue._split_to_version(name) == tuple([name])
     for name, expected in self.splittable:
         assert ContextValue._split_to_version(name) == (expected)
コード例 #9
0
 def test_simple_names(self):
     """ Values with simple name """
     for name in self.impossible_split:
         assert ContextValue(name)._to_compare == tuple([name])
     for name, _ in self.splittable:
         assert ContextValue([name])._to_compare == tuple([name])