Beispiel #1
0
    def test_caps(self):
        cases = (("vendor.example.org/cap-name", "vendor.example.org/cap-name",
                  None), )

        for text, name, value in cases:
            cap = Cap.parse(text)
            assert cap.name == name
            assert cap.value == value
Beispiel #2
0
 def test_eq(self, name, value):
     """Test equals"""
     assert Cap(name, value) == Cap(name, value)
Beispiel #3
0
 def test_str(self, name, value, expected):
     """Test string conversion"""
     c = Cap(name, value)
     assert str(c) == expected
Beispiel #4
0
class TestCap:
    """Test Cap class"""

    @pytest.mark.parametrize(
        "name,value,expected",
        [
            ("capname", "somevalue", "capname=somevalue"),
            ("capname", None, "capname"),
        ],
    )
    def test_str(self, name, value, expected):
        """Test string conversion"""
        c = Cap(name, value)
        assert str(c) == expected

    @pytest.mark.parametrize(
        "name,value",
        [
            ("a", "b"),
            ("foo", "bar"),
        ],
    )
    def test_eq(self, name, value):
        """Test equals"""
        assert Cap(name, value) == Cap(name, value)

    @pytest.mark.parametrize(
        "name,value,string",
        [
            ("a", "b", "a=b"),
            ("foo", "bar", "foo=bar"),
        ],
    )
    def test_eq_str(self, name, value, string):
        """Test equals string"""
        assert Cap(name, value) == string
        assert string == Cap(name, value)

    @pytest.mark.parametrize(
        "name,value,other_name,other_value",
        [
            ("a", "b", "c", "b"),
            ("a", "b", "a", "c"),
            ("a", "b", "c", "d"),
            ("foo", "bar", "baz", "zing"),
            ("foo", "bar", "baz", None),
            ("foo", None, "baz", None),
            ("foo", None, "baz", "zing"),
            ("foo", "bar", "foo", "zing"),
            ("foo", "bar", "foo", None),
            ("foo", None, "foo", "zing"),
        ],
    )
    def test_ne(self, name, value, other_name, other_value):
        """Test not-equals"""
        assert Cap(name, value) != Cap(other_name, other_value)
        assert Cap(other_name, other_value) != Cap(name, value)

    @pytest.mark.parametrize(
        "name,value,string",
        [
            ("a", "b", "c=b"),
            ("a", "b", "a=c"),
            ("a", "b", "c=d"),
            ("foo", "bar", "baz=zing"),
            ("foo", "bar", "foo=zing"),
            ("foo", "bar", "foo"),
            ("foo", "bar", "foo=baz"),
            ("foo", None, "foo=baz"),
            ("foo", None, "baz"),
        ],
    )
    def test_ne_str(self, name, value, string):
        """Test not-equals string"""
        assert Cap(name, value) != string
        assert string != Cap(name, value)

    @pytest.mark.parametrize(
        "obj,other",
        [
            (Cap("foo"), 1),
        ],
    )
    def test_no_cmp(self, obj, other):
        """Test not-equals"""
        assert obj != other
        assert other != obj

        assert not obj == other
        assert not other == obj

    @pytest.mark.parametrize(
        "text,name,value",
        [
            (
                "vendor.example.org/cap-name",
                "vendor.example.org/cap-name",
                None,
            ),
        ],
    )
    def test_parse(self, text, name, value):
        """Test parsing string"""
        cap = Cap.parse(text)
        assert cap.name == name
        assert cap.value == value
Beispiel #5
0
class TestCapList:
    """Test parsing a list of CAPs"""

    @pytest.mark.parametrize(
        "text,expected",
        [
            (
                "blah blah-blah cap-1 test-cap=value-data",
                (
                    ("blah", None),
                    ("blah-blah", None),
                    ("cap-1", None),
                    ("test-cap", "value-data"),
                ),
            ),
            (
                "blah blah-blah cap-1 test-cap=value-data ",
                (
                    ("blah", None),
                    ("blah-blah", None),
                    ("cap-1", None),
                    ("test-cap", "value-data"),
                ),
            ),
            (
                ":blah blah-blah cap-1 test-cap=value-data",
                (
                    ("blah", None),
                    ("blah-blah", None),
                    ("cap-1", None),
                    ("test-cap", "value-data"),
                ),
            ),
            (
                ":blah blah-blah cap-1 test-cap=value-data ",
                (
                    ("blah", None),
                    ("blah-blah", None),
                    ("cap-1", None),
                    ("test-cap", "value-data"),
                ),
            ),
            (
                "",
                (),
            ),
        ],
    )
    def test_parse(self, text, expected):
        """Test string parsing"""
        parsed = CapList.parse(text)
        assert len(parsed) == len(expected)
        for (name, value), actual in zip(expected, parsed):
            assert actual.name == name
            assert actual.value == value

    @pytest.mark.parametrize("caps", [[], [Cap("a"), Cap("b", "c")]])
    def test_eq_list(self, caps):
        """Test equals list"""
        assert CapList(caps) == caps
        assert caps == CapList(caps)

    @pytest.mark.parametrize(
        "caps",
        [
            [],
            [Cap("a"), Cap("b", "c")],
        ],
    )
    def test_ne_list(self, caps):
        """Test not-equals list"""
        b = CapList(caps) != caps
        assert not b
        b1 = caps != CapList(caps)
        assert not b1

    @pytest.mark.parametrize(
        "caps,text",
        [
            ([], ""),
            ([Cap("a"), Cap("b", "c")], "a b=c"),
            ([Cap("a"), Cap("b", "c")], "a b=c "),
        ],
    )
    def test_eq_str(self, caps, text):
        """Test equals strings"""
        assert CapList(caps) == text
        assert text == CapList(caps)

    @pytest.mark.parametrize(
        "caps,text",
        [
            ([], ""),
            ([Cap("a"), Cap("b", "c")], "a b=c"),
            ([Cap("a"), Cap("b", "c")], "a b=c "),
        ],
    )
    def test_ne_str(self, caps, text):
        """Test not-equals strings"""
        b = CapList(caps) != text
        assert not b
        b1 = text != CapList(caps)
        assert not b1

    @pytest.mark.parametrize(
        "obj,other",
        [
            (CapList(), None),
            (CapList(), 0),
        ],
    )
    def test_no_cmp(self, obj, other):
        """Test not-equals"""
        assert obj != other
        assert other != obj

        assert not obj == other
        assert not other == obj

    @pytest.mark.parametrize(
        "obj,text",
        [
            (CapList([Cap("foo")]), "foo"),
            (CapList([Cap("foo"), Cap("bar")]), "foo bar"),
            (CapList([Cap("foo"), Cap("bar=baz")]), "foo bar=baz"),
        ],
    )
    def test_str(self, obj, text):
        """Test string conversion"""
        assert str(obj) == text
        assert text == str(obj)
Beispiel #6
0
 def test_parse(self, text, name, value):
     """Test parsing string"""
     cap = Cap.parse(text)
     assert cap.name == name
     assert cap.value == value
Beispiel #7
0
 def test_ne_str(self, name, value, string):
     """Test not-equals string"""
     assert Cap(name, value) != string
     assert string != Cap(name, value)
Beispiel #8
0
 def test_str(self, name, value, expected):
     c = Cap(name, value)
     assert str(c) == expected
Beispiel #9
0
class TestCapList:
    @pytest.mark.parametrize('text,expected',
                             [("blah blah-blah cap-1 test-cap=value-data",
                               (("blah", None), ("blah-blah", None),
                                ("cap-1", None), ("test-cap", "value-data"))),
                              ("blah blah-blah cap-1 test-cap=value-data ",
                               (("blah", None), ("blah-blah", None),
                                ("cap-1", None), ("test-cap", "value-data"))),
                              (":blah blah-blah cap-1 test-cap=value-data",
                               (("blah", None), ("blah-blah", None),
                                ("cap-1", None), ("test-cap", "value-data"))),
                              (":blah blah-blah cap-1 test-cap=value-data ",
                               (("blah", None), ("blah-blah", None),
                                ("cap-1", None), ("test-cap", "value-data"))),
                              (
                                  "",
                                  (),
                              )])
    def test_parse(self, text, expected):
        parsed = CapList.parse(text)
        assert len(parsed) == len(expected)
        for (name, value), actual in zip(expected, parsed):
            assert actual.name == name
            assert actual.value == value

    @pytest.mark.parametrize('caps', [[], [Cap('a'), Cap('b', 'c')]])
    def test_eq_list(self, caps):
        assert CapList(caps) == caps
        assert caps == CapList(caps)

    @pytest.mark.parametrize('caps', [
        [],
        [Cap('a'), Cap('b', 'c')],
    ])
    def test_ne_list(self, caps):
        assert not (CapList(caps) != caps)
        assert not (caps != CapList(caps))

    @pytest.mark.parametrize('caps,text', [
        ([], ''),
        ([Cap('a'), Cap('b', 'c')], 'a b=c'),
        ([Cap('a'), Cap('b', 'c')], 'a b=c '),
    ])
    def test_eq_str(self, caps, text):
        assert CapList(caps) == text
        assert text == CapList(caps)

    @pytest.mark.parametrize('caps,text', [
        ([], ''),
        ([Cap('a'), Cap('b', 'c')], 'a b=c'),
        ([Cap('a'), Cap('b', 'c')], 'a b=c '),
    ])
    def test_ne_str(self, caps, text):
        assert not (CapList(caps) != text)
        assert not (text != CapList(caps))

    @pytest.mark.parametrize('obj,other', [
        (CapList(), None),
        (CapList(), 0),
    ])
    def test_no_cmp(self, obj, other):
        assert obj != other
        assert other != obj

        assert not (obj == other)
        assert not (other == obj)

    @pytest.mark.parametrize('obj,text', [
        (CapList([Cap('foo')]), 'foo'),
        (CapList([Cap('foo'), Cap('bar')]), 'foo bar'),
        (CapList([Cap('foo'), Cap('bar=baz')]), 'foo bar=baz'),
    ])
    def test_str(self, obj, text):
        assert str(obj) == text
        assert text == str(obj)
Beispiel #10
0
 def test_parse(self, text, name, value):
     cap = Cap.parse(text)
     assert cap.name == name
     assert cap.value == value
Beispiel #11
0
 def test_ne_str(self, name, value, string):
     assert Cap(name, value) != string
     assert string != Cap(name, value)
Beispiel #12
0
 def test_ne(self, name, value, other_name, other_value):
     assert Cap(name, value) != Cap(other_name, other_value)
     assert Cap(other_name, other_value) != Cap(name, value)
Beispiel #13
0
 def test_eq_str(self, name, value, string):
     assert Cap(name, value) == string
     assert string == Cap(name, value)
Beispiel #14
0
 def test_eq(self, name, value):
     assert Cap(name, value) == Cap(name, value)
Beispiel #15
0
 def test_eq_str(self, name, value, string):
     """Test equals string"""
     assert Cap(name, value) == string
     assert string == Cap(name, value)
Beispiel #16
0
 def test_ne(self, name, value, other_name, other_value):
     """Test not-equals"""
     assert Cap(name, value) != Cap(other_name, other_value)
     assert Cap(other_name, other_value) != Cap(name, value)
Beispiel #17
0
class TestCap:
    @pytest.mark.parametrize('name,value,expected', [
        ('capname', 'somevalue', 'capname=somevalue'),
        ('capname', None, 'capname'),
    ])
    def test_str(self, name, value, expected):
        c = Cap(name, value)
        assert str(c) == expected

    @pytest.mark.parametrize('name,value', [
        ('a', 'b'),
        ('foo', 'bar'),
    ])
    def test_eq(self, name, value):
        assert Cap(name, value) == Cap(name, value)

    @pytest.mark.parametrize('name,value,string', [
        ('a', 'b', 'a=b'),
        ('foo', 'bar', 'foo=bar'),
    ])
    def test_eq_str(self, name, value, string):
        assert Cap(name, value) == string
        assert string == Cap(name, value)

    @pytest.mark.parametrize('name,value,other_name,other_value', [
        ('a', 'b', 'c', 'b'),
        ('a', 'b', 'a', 'c'),
        ('a', 'b', 'c', 'd'),
        ('foo', 'bar', 'baz', 'zing'),
        ('foo', 'bar', 'baz', None),
        ('foo', None, 'baz', None),
        ('foo', None, 'baz', 'zing'),
        ('foo', 'bar', 'foo', 'zing'),
        ('foo', 'bar', 'foo', None),
        ('foo', None, 'foo', 'zing'),
    ])
    def test_ne(self, name, value, other_name, other_value):
        assert Cap(name, value) != Cap(other_name, other_value)
        assert Cap(other_name, other_value) != Cap(name, value)

    @pytest.mark.parametrize('name,value,string', [
        ('a', 'b', 'c=b'),
        ('a', 'b', 'a=c'),
        ('a', 'b', 'c=d'),
        ('foo', 'bar', 'baz=zing'),
        ('foo', 'bar', 'foo=zing'),
        ('foo', 'bar', 'foo'),
        ('foo', 'bar', 'foo=baz'),
        ('foo', None, 'foo=baz'),
        ('foo', None, 'baz'),
    ])
    def test_ne_str(self, name, value, string):
        assert Cap(name, value) != string
        assert string != Cap(name, value)

    @pytest.mark.parametrize('obj,other', [
        (Cap('foo'), 1),
    ])
    def test_no_cmp(self, obj, other):
        assert obj != other
        assert other != obj

        assert not (obj == other)
        assert not (other == obj)

    @pytest.mark.parametrize('text,name,value', [
        ("vendor.example.org/cap-name", "vendor.example.org/cap-name", None),
    ])
    def test_parse(self, text, name, value):
        cap = Cap.parse(text)
        assert cap.name == name
        assert cap.value == value