Exemple #1
0
 def test_invalid_bools(self):
     with self.assertRaises(ValueError):
         Context(('spam', 'eggs'), ('camelot', 'launcelot'),
                 [(True, False)])
     with self.assertRaises(ValueError):
         Context(('spam', 'eggs'), ('camelot', 'launcelot'),
                 [(True, False, False), (False, True)])
Exemple #2
0
def test_eq_mapping(lattice):
    other = Context(*lattice._context.definition()).lattice
    k, v = other._mapping.popitem()
    assert not other._eq(lattice)

    k = k.__class__.frommembers(['1sg', '3pl'])
    other._mapping[k] = v
    assert not other._eq(lattice)
Exemple #3
0
 def test_nonatomic(self):
     m = Context(('spam', 'eggs'), ('ham', ), [(True, ), (True, )]).lattice
     self.assertEqual([tuple(c) for c in m],
                      [(('spam', 'eggs'), ('ham', ))])
     t = Context(('spam', 'eggs'), ('ham', ), [(False, ),
                                               (False, )]).lattice
     self.assertEqual([tuple(c) for c in t], [((), ('ham', )),
                                              (('spam', 'eggs'), ())])
Exemple #4
0
def test_eq(lattice):
    assert lattice._eq(lattice)

    d = lattice._context.definition()
    assert lattice._eq(Context(*d).lattice)

    d.add_object('X', ['mysterious', 'child'])
    assert not lattice._eq(Context(*d).lattice)
    d.remove_object('X')

    d.move_object('3pl', 0)
    assert not lattice._eq(Context(*d).lattice)
Exemple #5
0
def test_init():
    c = Context(('spam', 'eggs'), ('camelot', 'launcelot'),
                [(True, False), (False, True)])

    assert c.objects == ('spam', 'eggs')
    assert c.properties == ('camelot', 'launcelot')
    assert c.bools == [(True, False), (False, True)]
Exemple #6
0
def test_eq_concepts(lattice):
    other = Context(*lattice._context.definition()).lattice
    c = other[16]

    for attname in ('index', 'dindex'):
        i = getattr(c, attname)
        setattr(c, attname, -1)
        assert not other._eq(lattice)
        setattr(c, attname, i)

    for attname in ('atoms', 'properties', 'objects'):
        t = tuple(getattr(c, attname))
        if attname == 'objects':
            setattr(c, attname, ('spam', ))
        else:
            setattr(c, attname, tuple(reversed(t)))
        assert not other._eq(lattice)
        setattr(c, attname, t)
Exemple #7
0
def context():
    source = '''
       |+1|-1|+2|-2|+3|-3|+sg|+pl|-sg|-pl|
    1sg| X|  |  | X|  | X|  X|   |   |  X|
    1pl| X|  |  | X|  | X|   |  X|  X|   |
    2sg|  | X| X|  |  | X|  X|   |   |  X|
    2pl|  | X| X|  |  | X|   |  X|  X|   |
    3sg|  | X|  | X| X|  |  X|   |   |  X|
    3pl|  | X|  | X| X|  |   |  X|  X|   |
    '''
    return Context.fromstring(source)
Exemple #8
0
def context():
    source = '''
       |+1|-1|+2|-2|+3|-3|+sg|+pl|-sg|-pl|
    1sg| X|  |  | X|  | X|  X|   |   |  X|
    1pl| X|  |  | X|  | X|   |  X|  X|   |
    2sg|  | X| X|  |  | X|  X|   |   |  X|
    2pl|  | X| X|  |  | X|   |  X|  X|   |
    3sg|  | X|  | X| X|  |  X|   |   |  X|
    3pl|  | X|  | X| X|  |   |  X|  X|   |
    '''
    return Context.fromstring(source)
Exemple #9
0
def lattice():
    source = '''
       |+1|-1|+2|-2|+3|-3|+sg|+pl|-sg|-pl|
    1sg| X|  |  | X|  | X|  X|   |   |  X|
    1pl| X|  |  | X|  | X|   |  X|  X|   |
    2sg|  | X| X|  |  | X|  X|   |   |  X|
    2pl|  | X| X|  |  | X|   |  X|  X|   |
    3sg|  | X|  | X| X|  |  X|   |   |  X|
    3pl|  | X|  | X| X|  |   |  X|  X|   |
    '''
    context = Context.fromstring(source)
    return context.lattice
Exemple #10
0
def lattice():
    source = '''
       |+1|-1|+2|-2|+3|-3|+sg|+pl|-sg|-pl|
    1sg| X|  |  | X|  | X|  X|   |   |  X|
    1pl| X|  |  | X|  | X|   |  X|  X|   |
    2sg|  | X| X|  |  | X|  X|   |   |  X|
    2pl|  | X| X|  |  | X|   |  X|  X|   |
    3sg|  | X|  | X| X|  |  X|   |   |  X|
    3pl|  | X|  | X| X|  |   |  X|  X|   |
    '''
    context = Context.fromstring(source)
    return context.lattice
Exemple #11
0
def test_invalid_bools_2():
    with pytest.raises(ValueError, match=r'bools is not 2 items of length 2'):
        Context(('spam', 'eggs'), ('camelot', 'launcelot'),
                [(True, False, False), (False, True)])
Exemple #12
0
def test_object_property_overlap():
    with pytest.raises(ValueError, match=r'overlap'):
        Context(('spam', 'eggs'), ('eggs', 'ham'),
                [(True, False), (False, True)])
Exemple #13
0
def test_duplicate_property():
    with pytest.raises(ValueError, match=r'duplicate properties'):
        Context(('spam', 'eggs'), ('ham', 'ham'),
                [(True, False), (False, True)])
Exemple #14
0
def test_duplicate_object():
    with pytest.raises(ValueError, match=r'duplicate objects'):
        Context(('spam', 'spam'), ('ham', 'eggs'),
                [(True, False), (False, True)])
Exemple #15
0
def test_minimum():
    l = Context(('spam', ), ('ham', ), [(True, )]).lattice
    assert len(l) == 1
    assert l.infimum is l.supremum
    assert l.atoms == ()
Exemple #16
0
def test_ne_true(context):
    d = context.definition()
    d.move_object('3pl', 0)
    assert context != Context(*d)
Exemple #17
0
def test_eq_false(context):
    d = context.definition()
    d.move_object('3pl', 0)
    assert not context == Context(*d)
Exemple #18
0
def test_invalid_bools():
    with pytest.raises(ValueError):
        Context(('spam', 'eggs'), ('camelot', 'launcelot'), [(True, False)])
    with pytest.raises(ValueError):
        Context(('spam', 'eggs'), ('camelot', 'launcelot'),
                [(True, False, False), (False, True)])
Exemple #19
0
 def setUpClass(cls, source=None):
     if source is None:
         source = cls.source
     cls.context = Context.fromstring(source)
Exemple #20
0
 def test_eq(self):
     self.assertTrue(self.context == Context(
         self.context.objects, self.context.properties, self.context.bools))
Exemple #21
0
 def test_ne(self):
     self.assertTrue(self.context != Context(('spam', 'eggs'), (
         'camelot', 'launcelot'), [(True, False), (False, True)]))
Exemple #22
0
def test_nonatomic():
    m = Context(('spam', 'eggs'), ('ham', ), [(True, ), (True, )]).lattice
    assert [tuple(c) for c in m] == [(('spam', 'eggs'), ('ham', ))]
    t = Context(('spam', 'eggs'), ('ham', ), [(False, ), (False, )]).lattice
    assert [tuple(c) for c in t] == [((), ('ham', )), (('spam', 'eggs'), ())]
Exemple #23
0
def test_trivial():
    l = Context(('spam', ), ('ham', ), [(False, )]).lattice
    assert len(l) == 2
    assert l.infimum is not l.supremum
    assert l.atoms == (l.supremum, )
Exemple #24
0
 def test_empty_relation(self):
     with self.assertRaises(ValueError):
         Context((), ('spam', ), [(False, )])
     with self.assertRaises(ValueError):
         Context(('spam', ), (), [(False, )])
Exemple #25
0
 def test_init(self):
     c = Context(('spam', 'eggs'), ('camelot', 'launcelot'),
                 [(True, False), (False, True)])
     self.assertEqual(c.objects, ('spam', 'eggs'))
     self.assertEqual(c.properties, ('camelot', 'launcelot'))
     self.assertEqual(c.bools, [(True, False), (False, True)])
Exemple #26
0
def test_eq_true(context):
    assert context == Context(context.objects, context.properties,
                              context.bools)
Exemple #27
0
def test_ne(context):
    assert context != Context(('spam', 'eggs'),
                              ('camelot', 'launcelot'), [(True, False),
                                                         (False, True)])
Exemple #28
0
def test_empty_objects():
    with pytest.raises(ValueError, match=r'empty objects'):
        Context((), ('spam',), [(False,)])
Exemple #29
0
def test_empty_properies():
    with pytest.raises(ValueError, match=r'empty properties'):
        Context(('spam',), (), [(False,)])
Exemple #30
0
def test_ne_false(context):
    assert not context != Context(context.objects, context.properties,
                                  context.bools)
Exemple #31
0
 def test_duplicate_object(self):
     with self.assertRaises(ValueError):
         Context(('spam', 'spam'), ('ham', 'eggs'), [(True, False),
                                                     (False, True)])
Exemple #32
0
 def setUpClass(cls, source=None):
     if source is None:
         source = cls.source
     cls.context = Context.fromstring(source)
Exemple #33
0
def test_empty_relation():
    with pytest.raises(ValueError):
        Context((), ('spam', ), [(False, )])
    with pytest.raises(ValueError):
        Context(('spam', ), (), [(False, )])