File: test_models_report_attribute.py

package info (click to toggle)
python-pbcommand 2.1.1%2Bgit20231020.28d1635-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,016 kB
  • sloc: python: 7,676; makefile: 220; sh: 73
file content (49 lines) | stat: -rw-r--r-- 1,243 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import logging

import pytest

from pbcommand.models.report import Attribute, PbReportError

log = logging.getLogger(__name__)


class TestAttribute:

    def test_attribute_null_id(self):
        """Can't create an attribute without an id."""
        def _test():
            a = Attribute(None, 1)

        with pytest.raises(PbReportError):
            _test()

    def test_attribute_int_id(self):
        """Test exception of handling Attribute with int ids"""
        def _test():
            a = Attribute(1, 12345)

        with pytest.raises(PbReportError):
            _test()

    def test_to_dict(self):
        """
        Test attribute to_dict function
        """
        a = Attribute('bob', 123, "Bob is the name")
        d = a.to_dict()
        assert 'bob' == d['id']
        assert 123 == d['value']
        assert 'Bob is the name' == d['name']

    def test_eq(self):
        a = Attribute('a', 1234, "My Attribute")
        b = Attribute('b', 1234, "My B Attribute")
        c = Attribute('a', 1234, "My Attribute")
        assert a == c
        assert a != b
        assert b != c

    def test_repr(self):
        a = Attribute('a', 1234, "My Attribute")
        log.info(repr(a))
        assert repr(a) is not None