Пример #1
0
def test___eq__():
    """Test == operator."""
    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])
    a = AttributeStructure(color, size)
    o = ['s1', 's2']
    asys = AttributeSystem(a, o)

    s = State(asys)
    s1 = State(asys, {
        ('color', 's1'): ['R'],
        ('color', 's2'): ['B', 'G'],
        ('size', 's1'): ['M'],
        ('size', 's2'): ['L', 'S']})

    s2 = State(asys, {
        ('size', 's1'): ['M'],
        ('color', 's2'): ['B', 'G'],
        ('color', 's1'): ['R'],
        ('size', 's2'): ['L', 'S']})

    assert s1 == s2

    assert not s == s1
    s.set_ascription(('color', 's1'), ['R'])
    assert not s == s1
    s.set_ascription(('color', 's2'), ['B', 'G'])
    assert not s == s1
    s.set_ascription(('size', 's1'), ['M'])
    assert not s == s1
    s.set_ascription(('size', 's2'), ['L', 'S'])
    assert s == s1
    assert s == s1 == s2
Пример #2
0
def test_is_alternate_extension():
    """Test is_alternate_extension function."""
    from copy import deepcopy
    color, size = Attribute("color", ['R', 'G', 'B']), Attribute(
        "size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s.set_ascription(('color', 's1'), ['R', 'B'])
    s.set_ascription(('size', 's2'), ['M', 'L'])

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's1'), ['B'])
    s1.set_ascription(('size', 's1'), ['S', 'M'])
    s1.set_ascription(('color', 's2'), ['B', 'G'])
    s2 = deepcopy(s)
    s2.set_ascription(('size', 's1'), ['L'])
    s2.set_ascription(('size', 's2'), ['L'])
    s3 = deepcopy(s)
    s3.set_ascription(('color', 's1'), ['R'])

    aes = s.get_alternate_extensions(s1, s2, s3)
    ae_s5, ae_s6, ae_s4 = aes

    for ae in aes:
        print s.is_alternate_extension(ae, s1, s2, s3)

    color, size = Attribute("color", ['R', 'G', 'B']), Attribute(
        "size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's'), ['B', 'G'])
    s1.set_ascription(('size', 's'), ['S'])

    aes = s.get_alternate_extensions(s1)
    ae_s2, ae_s3 = aes

    for ae in aes:
        print s.is_alternate_extension(ae, s1)
Пример #3
0
def test_is_alternate_extension():
    """Test is_alternate_extension function."""
    from copy import deepcopy
    color, size = Attribute(
        "color", ['R', 'G', 'B']), Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s.set_ascription(('color', 's1'), ['R', 'B'])
    s.set_ascription(('size', 's2'), ['M', 'L'])

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's1'), ['B'])
    s1.set_ascription(('size', 's1'), ['S', 'M'])
    s1.set_ascription(('color', 's2'), ['B', 'G'])
    s2 = deepcopy(s)
    s2.set_ascription(('size', 's1'), ['L'])
    s2.set_ascription(('size', 's2'), ['L'])
    s3 = deepcopy(s)
    s3.set_ascription(('color', 's1'), ['R'])

    aes = s.get_alternate_extensions(s1, s2, s3)
    ae_s5, ae_s6, ae_s4 = aes

    for ae in aes:
        print s.is_alternate_extension(ae, s1, s2, s3)

    color, size = Attribute(
        "color", ['R', 'G', 'B']), Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's'), ['B', 'G'])
    s1.set_ascription(('size', 's'), ['S'])

    aes = s.get_alternate_extensions(s1)
    ae_s2, ae_s3 = aes

    for ae in aes:
        print s.is_alternate_extension(ae, s1)
Пример #4
0
def test_is_world():
    """Test is_world function."""
    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])
    a = AttributeStructure(color, size)
    o = ['s1', 's2']
    asys = AttributeSystem(a, o)

    ascr = {
        ('color', 's1'): ['R'],
        ('color', 's2'): ['B', 'G'],
        ('size', 's1'): ['M'],
        ('size', 's2'): ['L', 'S']}

    s = State(asys, ascr)

    assert not s.is_world()
    s.set_ascription(('color', 's2'), ['B'])
    s.set_ascription(('size', 's2'), ['L'])
    assert s.is_world()
Пример #5
0
def test_is_world():
    """Test is_world function."""
    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])
    a = AttributeStructure(color, size)
    o = ['s1', 's2']
    asys = AttributeSystem(a, o)

    ascr = {
        ('color', 's1'): ['R'],
        ('color', 's2'): ['B', 'G'],
        ('size', 's1'): ['M'],
        ('size', 's2'): ['L', 'S']
    }

    s = State(asys, ascr)

    assert not s.is_world()
    s.set_ascription(('color', 's2'), ['B'])
    s.set_ascription(('size', 's2'), ['L'])
    assert s.is_world()
Пример #6
0
def test_set_ascription():
    """Test set_ascription function."""
    def test_TypeError(state, ascription, valueset):
        """Test set_ascription for TypeErrors with given params."""
        with pytest.raises(TypeError) as excinfo:
            state.set_ascription(ascription, valueset)

    def test_ValueError(state, ascription, valueset):
        """Test set_ascription for ValueErrors with given params."""
        with pytest.raises(ValueError) as excinfo:
            state.set_ascription(ascription, valueset)

    def test_KeyError(state, ascription, valueset):
        """Test set_ascription for KeyErrors with given params."""
        with pytest.raises(KeyError) as excinfo:
            state.set_ascription(ascription, valueset)

    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    # test bad ao_pair types/values
    test_TypeError(s, [], ['R'])
    test_ValueError(s, (), ['R'])
    test_ValueError(s, (1, 2, 3), ['R'])
    test_ValueError(s, (1, 2), ['R'])
    test_ValueError(s, (1, ''), ['R'])
    test_ValueError(s, ('', 1), ['R'])
    # test bad types for ValueSet
    test_TypeError(s, ('color', 's1'), None)
    test_TypeError(s, ('color', 's1'), ())
    test_TypeError(s, ('color', 's1'), 'a')
    test_TypeError(s, ('color', 's1'), object)
    # test empty ValueSet catching
    test_ValueError(s, ('color', 's1'), [])
    test_ValueError(s, ('color', 's1'), set([]))
    test_ValueError(s, ('color', 's1'), ValueSet([]))
    # test bad ao-pair keys
    test_KeyError(s, ('color', 'bad object'), ['R'])
    test_KeyError(s, ('bad label', 's2'), ['R'])
    # test nonsubset valuesets
    test_ValueError(s, ('color', 's2'), ['a'])
    test_ValueError(s, ('color', 's2'), [1])

    s.set_ascription(('color', 's2'), ['R'])
    assert s[('color', 's2')] == ValueSet(['R'])
    # check reversion to superset is possible
    s.set_ascription(('color', 's2'), ['R', 'G'])
    assert s[('color', 's2')] == ValueSet(['R', 'G'])
    s.set_ascription(('size', 's1'), ['M', 'S'])
    assert s[('size', 's1')] == ValueSet(['S', 'M'])
Пример #7
0
def test_set_ascription():
    """Test set_ascription function."""
    def test_TypeError(state, ascription, valueset):
        """Test set_ascription for TypeErrors with given params."""
        with pytest.raises(TypeError) as excinfo:
            state.set_ascription(ascription, valueset)

    def test_ValueError(state, ascription, valueset):
        """Test set_ascription for ValueErrors with given params."""
        with pytest.raises(ValueError) as excinfo:
            state.set_ascription(ascription, valueset)

    def test_KeyError(state, ascription, valueset):
        """Test set_ascription for KeyErrors with given params."""
        with pytest.raises(KeyError) as excinfo:
            state.set_ascription(ascription, valueset)

    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    # test bad ao_pair types/values
    test_TypeError(s, [], ['R'])
    test_ValueError(s, (), ['R'])
    test_ValueError(s, (1, 2, 3), ['R'])
    test_ValueError(s, (1, 2), ['R'])
    test_ValueError(s, (1, ''), ['R'])
    test_ValueError(s, ('', 1), ['R'])
    # test bad types for ValueSet
    test_TypeError(s, ('color', 's1'), None)
    test_TypeError(s, ('color', 's1'), ())
    test_TypeError(s, ('color', 's1'), 'a')
    test_TypeError(s, ('color', 's1'), object)
    # test empty ValueSet catching
    test_ValueError(s, ('color', 's1'), [])
    test_ValueError(s, ('color', 's1'), set([]))
    test_ValueError(s, ('color', 's1'), ValueSet([]))
    # test bad ao-pair keys
    test_KeyError(s, ('color', 'bad object'), ['R'])
    test_KeyError(s, ('bad label', 's2'), ['R'])
    # test nonsubset valuesets
    test_ValueError(s, ('color', 's2'), ['a'])
    test_ValueError(s, ('color', 's2'), [1])

    s.set_ascription(('color', 's2'), ['R'])
    assert s[('color', 's2')] == ValueSet(['R'])
    # check reversion to superset is possible
    s.set_ascription(('color', 's2'), ['R', 'G'])
    assert s[('color', 's2')] == ValueSet(['R', 'G'])
    s.set_ascription(('size', 's1'), ['M', 'S'])
    assert s[('size', 's1')] == ValueSet(['S', 'M'])
Пример #8
0
def test___eq__():
    """Test == operator."""
    color = Attribute("color", ['R', 'G', 'B'])
    size = Attribute("size", ['S', 'M', 'L'])
    a = AttributeStructure(color, size)
    o = ['s1', 's2']
    asys = AttributeSystem(a, o)

    s = State(asys)
    s1 = State(
        asys, {
            ('color', 's1'): ['R'],
            ('color', 's2'): ['B', 'G'],
            ('size', 's1'): ['M'],
            ('size', 's2'): ['L', 'S']
        })

    s2 = State(
        asys, {
            ('size', 's1'): ['M'],
            ('color', 's2'): ['B', 'G'],
            ('color', 's1'): ['R'],
            ('size', 's2'): ['L', 'S']
        })

    assert s1 == s2

    assert not s == s1
    s.set_ascription(('color', 's1'), ['R'])
    assert not s == s1
    s.set_ascription(('color', 's2'), ['B', 'G'])
    assert not s == s1
    s.set_ascription(('size', 's1'), ['M'])
    assert not s == s1
    s.set_ascription(('size', 's2'), ['L', 'S'])
    assert s == s1
    assert s == s1 == s2
Пример #9
0
def test_get_alternate_extensions():
    """Test get_alternate_extensions function."""
    from copy import deepcopy
    color, size = Attribute("color", ['R', 'G', 'B']), Attribute(
        "size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s.set_ascription(('color', 's1'), ['R', 'B'])
    s.set_ascription(('size', 's2'), ['M', 'L'])

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's1'), ['B'])
    s1.set_ascription(('size', 's1'), ['S', 'M'])
    s1.set_ascription(('color', 's2'), ['B', 'G'])
    s2 = deepcopy(s)
    s2.set_ascription(('size', 's1'), ['L'])
    s2.set_ascription(('size', 's2'), ['L'])
    s3 = deepcopy(s)
    s3.set_ascription(('color', 's1'), ['R'])

    aes = s.get_alternate_extensions(s1, s2, s3)
    ae_s5, ae_s6, ae_s4 = aes

    s4 = State(asys)
    s4.set_ascription(('color', 's1'), ['B'])
    s4.set_ascription(('color', 's2'), ['B', 'G', 'R'])
    s4.set_ascription(('size', 's1'), ['L'])
    s4.set_ascription(('size', 's2'), ['M'])

    s5 = State(asys)
    s5.set_ascription(('color', 's1'), ['B'])
    s5.set_ascription(('color', 's2'), ['R'])
    s5.set_ascription(('size', 's1'), ['M', 'S'])
    s5.set_ascription(('size', 's2'), ['L', 'M'])

    s6 = State(asys)
    s6.set_ascription(('color', 's1'), ['B'])
    s6.set_ascription(('color', 's2'), ['R'])
    s6.set_ascription(('size', 's1'), ['L', 'M', 'S'])
    s6.set_ascription(('size', 's2'), ['M'])

    assert ae_s4 == s4
    assert ae_s5 == s5
    assert ae_s6 == s6

    color, size = Attribute("color", ['R', 'G', 'B']), Attribute(
        "size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's'), ['B', 'G'])
    s1.set_ascription(('size', 's'), ['S'])

    aes = s.get_alternate_extensions(s1)
    ae_s2, ae_s3 = aes

    s2 = deepcopy(s)
    s2.set_ascription(('color', 's'), ['R'])
    s2.set_ascription(('size', 's'), ['S', 'M', 'L'])
    s3 = deepcopy(s)
    s3.set_ascription(('color', 's'), ['R', 'B', 'G'])
    s3.set_ascription(('size', 's'), ['L', 'M'])

    assert ae_s2 == s2
    assert ae_s3 == s3
Пример #10
0
def test_get_alternate_extensions():
    """Test get_alternate_extensions function."""
    from copy import deepcopy
    color, size = Attribute(
        "color", ['R', 'G', 'B']), Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s1', 's2']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s.set_ascription(('color', 's1'), ['R', 'B'])
    s.set_ascription(('size', 's2'), ['M', 'L'])

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's1'), ['B'])
    s1.set_ascription(('size', 's1'), ['S', 'M'])
    s1.set_ascription(('color', 's2'), ['B', 'G'])
    s2 = deepcopy(s)
    s2.set_ascription(('size', 's1'), ['L'])
    s2.set_ascription(('size', 's2'), ['L'])
    s3 = deepcopy(s)
    s3.set_ascription(('color', 's1'), ['R'])

    aes = s.get_alternate_extensions(s1, s2, s3)
    ae_s5, ae_s6, ae_s4 = aes

    s4 = State(asys)
    s4.set_ascription(('color', 's1'), ['B'])
    s4.set_ascription(('color', 's2'), ['B', 'G', 'R'])
    s4.set_ascription(('size', 's1'), ['L'])
    s4.set_ascription(('size', 's2'), ['M'])

    s5 = State(asys)
    s5.set_ascription(('color', 's1'), ['B'])
    s5.set_ascription(('color', 's2'), ['R'])
    s5.set_ascription(('size', 's1'), ['M', 'S'])
    s5.set_ascription(('size', 's2'), ['L', 'M'])

    s6 = State(asys)
    s6.set_ascription(('color', 's1'), ['B'])
    s6.set_ascription(('color', 's2'), ['R'])
    s6.set_ascription(('size', 's1'), ['L', 'M', 'S'])
    s6.set_ascription(('size', 's2'), ['M'])

    assert ae_s4 == s4
    assert ae_s5 == s5
    assert ae_s6 == s6

    color, size = Attribute(
        "color", ['R', 'G', 'B']), Attribute("size", ['S', 'M', 'L'])

    a = AttributeStructure(color, size)
    o = ['s']

    asys = AttributeSystem(a, o)
    s = State(asys)

    s1 = deepcopy(s)
    s1.set_ascription(('color', 's'), ['B', 'G'])
    s1.set_ascription(('size', 's'), ['S'])

    aes = s.get_alternate_extensions(s1)
    ae_s2, ae_s3 = aes

    s2 = deepcopy(s)
    s2.set_ascription(('color', 's'), ['R'])
    s2.set_ascription(('size', 's'), ['S', 'M', 'L'])
    s3 = deepcopy(s)
    s3.set_ascription(('color', 's'), ['R', 'B', 'G'])
    s3.set_ascription(('size', 's'), ['L', 'M'])

    assert ae_s2 == s2
    assert ae_s3 == s3