Exemple #1
0
    def test_constrain(self):

        # Try to constrain on a value equal to self
        a = SingleValuedVariant('foo', 'bar')
        b = SingleValuedVariant('foo', 'bar')

        changed = a.constrain(b)
        assert not changed
        t = SingleValuedVariant('foo', 'bar')
        assert a == t

        # Try to constrain on a value with a different value
        a = SingleValuedVariant('foo', 'bar')
        b = SingleValuedVariant('foo', 'baz')

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

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

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

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

        changed = a.constrain(b)
        assert not changed
        t = SingleValuedVariant('foo', 'bar')
        assert a == t

        # Implicit type conversion for variants of other types
        a = SingleValuedVariant('foo', 'True')
        mv = MultiValuedVariant('foo', 'True')
        bv = BoolValuedVariant('foo', 'True')
        for v in (mv, bv):
            assert not a.constrain(v)
Exemple #2
0
    def test_constrain(self):

        # Try to constrain on a value equal to self
        a = SingleValuedVariant('foo', 'bar')
        b = SingleValuedVariant('foo', 'bar')

        changed = a.constrain(b)
        assert not changed
        t = SingleValuedVariant('foo', 'bar')
        assert a == t

        # Try to constrain on a value with a different value
        a = SingleValuedVariant('foo', 'bar')
        b = SingleValuedVariant('foo', 'baz')

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

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

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

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

        changed = a.constrain(b)
        assert not changed
        t = SingleValuedVariant('foo', 'bar')
        assert a == t

        # Implicit type conversion for variants of other types
        a = SingleValuedVariant('foo', 'True')
        mv = MultiValuedVariant('foo', 'True')
        bv = BoolValuedVariant('foo', 'True')
        for v in (mv, bv):
            assert not a.constrain(v)
Exemple #3
0
    def test_initialization(self):

        # Basic properties
        a = SingleValuedVariant('foo', 'bar')
        assert repr(a) == "SingleValuedVariant('foo', 'bar')"
        assert str(a) == 'foo=bar'
        assert a.value == 'bar'
        assert 'bar' in a
        assert eval(repr(a)) == a

        # Raise if multiple values are passed
        with pytest.raises(ValueError):
            SingleValuedVariant('foo', 'bar, baz')

        # Check the copy
        b = a.copy()
        assert repr(a) == repr(b)
        assert str(a) == str(b)
        assert b.value == 'bar'
        assert 'bar' in b
        assert a == b
        assert a is not b
        assert hash(a) == hash(b)
        assert eval(repr(b)) == a
Exemple #4
0
    def test_initialization(self):

        # Basic properties
        a = SingleValuedVariant('foo', 'bar')
        assert repr(a) == "SingleValuedVariant('foo', 'bar')"
        assert str(a) == 'foo=bar'
        assert a.value == 'bar'
        assert 'bar' in a
        assert eval(repr(a)) == a

        # Raise if multiple values are passed
        with pytest.raises(ValueError):
            SingleValuedVariant('foo', 'bar, baz')

        # Check the copy
        b = a.copy()
        assert repr(a) == repr(b)
        assert str(a) == str(b)
        assert b.value == 'bar'
        assert 'bar' in b
        assert a == b
        assert a is not b
        assert hash(a) == hash(b)
        assert eval(repr(b)) == a