Exemplo n.º 1
0
 def test_equal(self):
     v1 = Color()
     v2 = Color()
     assert v1 == v2
     vrgba = Color(1, 2, 3, 4)
     vrgb = Color(1, 2, 3)
     assert not vrgb == vrgba  # Force use of __eq__
 def setup(self):
     self.acls = PoolColorArray
     random.seed(0)  # Fix seed for reproducibility
     # Use integer instead of float to avoid floating point imprecision in comparisons
     self.vg = lambda c=None: Color(
         random.randint(0, 100)
     ) if c is None else [Color(random.randint(0, 100)) for x in range(c)]
Exemplo n.º 3
0
 def test_initialize(self, arg):
     if isinstance(arg, dict):
         v1 = Color(**arg)
         v2 = Color(**arg)
     else:
         v1 = Color(*arg)
         v2 = Color(*arg)
     assert v1 == v2
Exemplo n.º 4
0
Arquivo: Rock.py Projeto: prixt/Q-Mok
    def value(self, val):
        self._value = val

        if val == WHITE:
            self.set_modulate(Color(1.0, 1.0, 1.0, 1))
            self.visible = True
        elif val == BLACK:
            self.set_modulate(Color(0.3, 0.3, 0.3, 1))
            self.visible = True
        elif val == UNKNOWN:
            self.set_modulate(Color(0.1, 0.8, 0.8, 1))
            self.visible = True
        elif val == EMPTY:
            self.visible = False
Exemplo n.º 5
0
 def test_properties_ro(self, args):
     v = Color(4.2)
     field, ret_type = args
     assert hasattr(v, field)
     field_val = getattr(v, field)
     assert type(field_val) == ret_type
     with pytest.raises(AttributeError):
         setattr(v, field, 0.5)
Exemplo n.º 6
0
 def test_methods(self, args):
     v = Color()
     # Don't test methods' validity but bindings one
     field, ret_type, params = args
     assert hasattr(v, field)
     method = getattr(v, field)
     assert callable(method)
     ret = method(*params)
     assert type(ret) == ret_type
Exemplo n.º 7
0
 def test_properties_rw(self, args):
     v = Color()
     field, ret_type = args
     assert hasattr(v, field)
     field_val = getattr(v, field)
     assert type(field_val) == ret_type
     if ret_type is float:
         vals = (0, 10, 10., 42.5)
     else:
         vals = (0, 10, 0xFF)
     for val in vals:
         setattr(v, field, val)
         field_val = getattr(v, field)
         assert field_val == val
Exemplo n.º 8
0
 def test_base(self):
     v = Color()
     assert type(v) == Color
Exemplo n.º 9
0
 def test_bad_instantiate(self, arg):
     with pytest.raises(TypeError):
         Color(*arg)
Exemplo n.º 10
0
class TestColor:
    def test_base(self):
        v = Color()
        assert type(v) == Color

    @pytest.mark.parametrize(
        "arg",
        [
            (),
            (0xFF, ),
            (0xFF, 0x77),
            (0xFF, 0x77, 0x33),
            (0xFF, 0x77, 0x33, 0x11),
            {
                "r": 0xFF,
                "g": 0x77,
                "b": 0x33,
                "a": 0x11
            },
        ],
    )
    def test_initialize(self, arg):
        if isinstance(arg, dict):
            v1 = Color(**arg)
            v2 = Color(**arg)
        else:
            v1 = Color(*arg)
            v2 = Color(*arg)
        assert v1 == v2

    def test_equal(self):
        v1 = Color()
        v2 = Color()
        assert v1 == v2
        vrgba = Color(1, 2, 3, 4)
        vrgb = Color(1, 2, 3)
        assert not vrgb == vrgba  # Force use of __eq__

    @pytest.mark.parametrize("arg", [None, 0, "foo", Color(1, 2, 3, 5)])
    def test_bad_equal(self, arg):
        basis = Color(1, 2, 3, 4)
        assert basis != arg

    def test_repr(self):
        v = Color()
        assert repr(v) == "<Color(r=0.0, g=0.0, b=0.0, a=1.0)>"

    @pytest.mark.parametrize("arg", [(None, ), (1, None), (1, 2, None),
                                     ("dummy", ), (Node(), ), (Vector2(), )])
    def test_bad_instantiate(self, arg):
        with pytest.raises(TypeError):
            Color(*arg)

    @pytest.mark.parametrize(
        "args",
        [
            ["to_rgba32", int, ()],
            ["to_argb32", int, ()],
            ["gray", float, ()],
            ["inverted", Color, ()],
            ["contrasted", Color, ()],
            ["linear_interpolate", Color, (Color(0xAA, 0xBB, 0xCC), 2.2)],
            ["blend", Color, (Color(0xAA, 0xBB, 0xCC), )],
            ["to_html", str, (True, )],
        ],
        ids=lambda x: x[0],
    )
    def test_methods(self, args):
        v = Color()
        # Don't test methods' validity but bindings one
        field, ret_type, params = args
        assert hasattr(v, field)
        method = getattr(v, field)
        assert callable(method)
        ret = method(*params)
        assert type(ret) == ret_type

    @pytest.mark.parametrize(
        "arg",
        [
            (Color(0, 0, 0), Color(1, 0, 0)),
            (Color(0, 1, 0), Color(1, 0, 0)),
            (Color(1, 0, 0), Color(1, 0, 1)),
        ],
        ids=lambda x: x[0],
    )
    def test_lt(self, arg):
        small, big = arg
        assert small < big

    @pytest.mark.parametrize(
        "args",
        [
            ("r", float),
            ("r8", int),
            ("g", float),
            ("g8", int),
            ("b", float),
            ("b8", int),
            ("a", float),
            ("a8", int),
        ],
        ids=lambda x: x[0],
    )
    def test_properties_rw(self, args):
        v = Color()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert type(field_val) == ret_type
        if ret_type is float:
            vals = (0, 10, 10., 42.5)
        else:
            vals = (0, 10, 0xFF)
        for val in vals:
            setattr(v, field, val)
            field_val = getattr(v, field)
            assert field_val == val

    @pytest.mark.parametrize("args", [("h", float), ("s", float),
                                      ("v", float)],
                             ids=lambda x: x[0])
    def test_properties_ro(self, args):
        v = Color(4.2)
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert type(field_val) == ret_type
        with pytest.raises(AttributeError):
            setattr(v, field, 0.5)

    @pytest.mark.parametrize(
        "args",
        [
            ("r", "Nan"),
            ("r8", "Nan"),
            ("g", "Nan"),
            ("g8", "Nan"),
            ("b", "Nan"),
            ("b8", "Nan"),
            ("a", "Nan"),
            ("a8", "Nan"),
        ],
        ids=lambda x: x[0],
    )
    def test_bad_properties(self, args):
        v = Color()
        field, bad_value = args
        with pytest.raises(TypeError):
            setattr(v, field, bad_value)
Exemplo n.º 11
0
 def test_repr(self):
     v = Color()
     assert repr(v) == "<Color(r=0.0, g=0.0, b=0.0, a=1.0)>"
Exemplo n.º 12
0
 def test_bad_equal(self, arg):
     basis = Color(1, 2, 3, 4)
     assert basis != arg
Exemplo n.º 13
0
 def test_bad_properties(self, args):
     v = Color()
     field, bad_value = args
     with pytest.raises(TypeError):
         setattr(v, field, bad_value)
Exemplo n.º 14
0
class TestColor:

    def test_base(self):
        v = Color()
        assert type(v) == Color

    @pytest.mark.parametrize('arg', [
        (),
        (0xFF,),
        (0xFF, 0x77),
        (0xFF, 0x77, 0x33),
        (0xFF, 0x77, 0x33, 0x11),
        {'r': 0xFF, 'g': 0x77, 'b': 0x33, 'a': 0x11},
    ])
    def test_initialize(self, arg):
        if isinstance(arg, dict):
            v1 = Color(**arg)
            v2 = Color(**arg)
        else:
            v1 = Color(*arg)
            v2 = Color(*arg)
        assert v1 == v2

    def test_equal(self):
        v1 = Color()
        v2 = Color()
        assert v1 == v2
        vrgba = Color(1, 2, 3, 4)
        vrgb = Color(1, 2, 3)
        assert not vrgb == vrgba  # Force use of __eq__

    @pytest.mark.parametrize('arg', [
        None,
        0,
        'foo',
        Color(1, 2, 3, 5),
    ])
    def test_bad_equal(self, arg):
        basis = Color(1, 2, 3, 4)
        assert basis != arg

    def test_repr(self):
        v = Color()
        assert repr(v) == '<Color(r=0.0, g=0.0, b=0.0, a=1.0)>'

    @pytest.mark.parametrize('arg', [
        (None, ),
        (1, None),
        (1, 2, None),
        ('dummy', ),
        (Node(), ),
        (Vector2(), )
    ])
    def test_bad_instantiate(self, arg):
        with pytest.raises(TypeError):
            Color(*arg)

    @pytest.mark.parametrize('args', [
        ['to_32', int, ()],
        ['to_ARGB32', int, ()],
        ['gray', float, ()],
        ['inverted', Color, ()],
        ['contrasted', Color, ()],
        ['linear_interpolate', Color, (Color(0xAA, 0xBB, 0xCC), 2.2)],
        ['blend', Color, (Color(0xAA, 0xBB, 0xCC), )],
        ['to_html', str, (True, )],
    ], ids=lambda x: x[0])
    def test_methods(self, args):
        v = Color()
        # Don't test methods' validity but bindings one
        field, ret_type, params = args
        assert hasattr(v, field)
        method = getattr(v, field)
        assert callable(method)
        ret = method(*params)
        assert type(ret) == ret_type

    @pytest.mark.parametrize('arg', [
        (Color(0, 0, 0), Color(1, 0, 0)),
        (Color(0, 1, 0), Color(1, 0, 0)),
        (Color(1, 0, 0), Color(1, 0, 1)),
    ], ids=lambda x: x[0])
    def test_lt(self, arg):
        small, big = arg
        assert small < big

    @pytest.mark.parametrize('args', [
        ('r', float),
        ('r8', int),
        ('g', float),
        ('g8', int),
        ('b', float),
        ('b8', int),
        ('a', float),
        ('a8', int),
    ], ids=lambda x: x[0])
    def test_properties_rw(self, args):
        v = Color()
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert type(field_val) == ret_type
        if ret_type is float:
            vals = (0, 10, 10., 42.5)
        else:
            vals = (0, 10, 0xFF)
        for val in vals:
            setattr(v, field, val)
            field_val = getattr(v, field)
            assert field_val == val

    @pytest.mark.parametrize('args', [
        ('h', float),
        ('s', float),
        ('v', float),
    ], ids=lambda x: x[0])
    def test_properties_ro(self, args):
        v = Color(4.2)
        field, ret_type = args
        assert hasattr(v, field)
        field_val = getattr(v, field)
        assert type(field_val) == ret_type
        with pytest.raises(AttributeError):
            setattr(v, field, 0.5)

    @pytest.mark.parametrize('args', [
        ('r', 'Nan'),
        ('r8', 'Nan'),
        ('g', 'Nan'),
        ('g8', 'Nan'),
        ('b', 'Nan'),
        ('b8', 'Nan'),
        ('a', 'Nan'),
        ('a8', 'Nan'),
    ], ids=lambda x: x[0])
    def test_bad_properties(self, args):
        v = Color()
        field, bad_value = args
        with pytest.raises(TypeError):
            setattr(v, field, bad_value)