Esempio n. 1
0
    def test_initialization(self):
        # Basic properties - True value
        for v in (True, 'True', 'TRUE', 'TrUe'):
            a = BoolValuedVariant('foo', v)
            assert repr(a) == "BoolValuedVariant('foo', {0})".format(repr(v))
            assert str(a) == '+foo'
            assert a.value is True
            assert True in a
            assert eval(repr(a)) == a

        # Copy - True value
        b = a.copy()
        assert repr(a) == repr(b)
        assert str(a) == str(b)
        assert b.value is True
        assert True in b
        assert a == b
        assert a is not b
        assert hash(a) == hash(b)
        assert eval(repr(b)) == a

        # Basic properties - False value
        for v in (False, 'False', 'FALSE', 'FaLsE'):
            a = BoolValuedVariant('foo', v)
            assert repr(a) == "BoolValuedVariant('foo', {0})".format(repr(v))
            assert str(a) == '~foo'
            assert a.value is False
            assert False in a
            assert eval(repr(a)) == a

        # Copy - True value
        b = a.copy()
        assert repr(a) == repr(b)
        assert str(a) == str(b)
        assert b.value is False
        assert False in b
        assert a == b
        assert a is not b
        assert eval(repr(b)) == a

        # Invalid values
        for v in ('bar', 'bar,baz'):
            with pytest.raises(ValueError):
                BoolValuedVariant('foo', v)
Esempio n. 2
0
    def test_initialization(self):
        # Basic properties - True value
        for v in (True, 'True', 'TRUE', 'TrUe'):
            a = BoolValuedVariant('foo', v)
            assert repr(a) == "BoolValuedVariant('foo', {0})".format(repr(v))
            assert str(a) == '+foo'
            assert a.value is True
            assert True in a
            assert eval(repr(a)) == a

        # Copy - True value
        b = a.copy()
        assert repr(a) == repr(b)
        assert str(a) == str(b)
        assert b.value is True
        assert True in b
        assert a == b
        assert a is not b
        assert hash(a) == hash(b)
        assert eval(repr(b)) == a

        # Basic properties - False value
        for v in (False, 'False', 'FALSE', 'FaLsE'):
            a = BoolValuedVariant('foo', v)
            assert repr(a) == "BoolValuedVariant('foo', {0})".format(repr(v))
            assert str(a) == '~foo'
            assert a.value is False
            assert False in a
            assert eval(repr(a)) == a

        # Copy - True value
        b = a.copy()
        assert repr(a) == repr(b)
        assert str(a) == str(b)
        assert b.value is False
        assert False in b
        assert a == b
        assert a is not b
        assert eval(repr(b)) == a

        # Invalid values
        for v in ('bar', 'bar,baz'):
            with pytest.raises(ValueError):
                BoolValuedVariant('foo', v)
Esempio n. 3
0
    def test_constrain(self):
        # Try to constrain on a value equal to self
        a = BoolValuedVariant('foo', 'True')
        b = BoolValuedVariant('foo', True)

        changed = a.constrain(b)
        assert not changed
        t = BoolValuedVariant('foo', True)
        assert a == t

        # Try to constrain on a value with a different value
        a = BoolValuedVariant('foo', True)
        b = BoolValuedVariant('foo', False)

        with pytest.raises(UnsatisfiableVariantSpecError):
            b.constrain(a)

        # Try to constrain on a value with a different value
        a = BoolValuedVariant('foo', True)
        b = BoolValuedVariant('fee', True)

        with pytest.raises(ValueError):
            b.constrain(a)

        # Try to constrain on the same value
        a = BoolValuedVariant('foo', True)
        b = a.copy()

        changed = a.constrain(b)
        assert not changed
        t = BoolValuedVariant('foo', True)
        assert a == t

        # Try to constrain on other values
        a = BoolValuedVariant('foo', 'True')
        sv = SingleValuedVariant('foo', 'True')
        mv = MultiValuedVariant('foo', 'True')
        for v in (sv, mv):
            assert not a.constrain(v)
Esempio n. 4
0
    def test_constrain(self):
        # Try to constrain on a value equal to self
        a = BoolValuedVariant('foo', 'True')
        b = BoolValuedVariant('foo', True)

        changed = a.constrain(b)
        assert not changed
        t = BoolValuedVariant('foo', True)
        assert a == t

        # Try to constrain on a value with a different value
        a = BoolValuedVariant('foo', True)
        b = BoolValuedVariant('foo', False)

        with pytest.raises(UnsatisfiableVariantSpecError):
            b.constrain(a)

        # Try to constrain on a value with a different value
        a = BoolValuedVariant('foo', True)
        b = BoolValuedVariant('fee', True)

        with pytest.raises(ValueError):
            b.constrain(a)

        # Try to constrain on the same value
        a = BoolValuedVariant('foo', True)
        b = a.copy()

        changed = a.constrain(b)
        assert not changed
        t = BoolValuedVariant('foo', True)
        assert a == t

        # Try to constrain on other values
        a = BoolValuedVariant('foo', 'True')
        sv = SingleValuedVariant('foo', 'True')
        mv = MultiValuedVariant('foo', 'True')
        for v in (sv, mv):
            assert not a.constrain(v)