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)])
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'), ())])
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)
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)]
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)
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)
def test_duplicate_property(): with pytest.raises(ValueError, match=r'duplicate properties'): Context(('spam', 'eggs'), ('ham', 'ham'), [(True, False), (False, True)])
def test_empty_properies(): with pytest.raises(ValueError, match=r'empty properties'): Context(('spam',), (), [(False,)])
def test_duplicate_object(): with pytest.raises(ValueError, match=r'duplicate objects'): Context(('spam', 'spam'), ('ham', 'eggs'), [(True, False), (False, True)])
def test_eq(self): self.assertTrue(self.context == Context( self.context.objects, self.context.properties, self.context.bools))
def test_ne(context): assert context != Context(('spam', 'eggs'), ('camelot', 'launcelot'), [(True, False), (False, True)])
def test_object_property_overlap(self): with self.assertRaises(ValueError): Context(('spam', 'eggs'), ('eggs', 'ham'), [(True, False), (False, True)])
def test_eq_false(context): d = context.definition() d.move_object('3pl', 0) assert not context == Context(*d)
def test_empty_relation(self): with self.assertRaises(ValueError): Context((), ('spam', ), [(False, )]) with self.assertRaises(ValueError): Context(('spam', ), (), [(False, )])
def test_ne_true(context): d = context.definition() d.move_object('3pl', 0) assert context != Context(*d)
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, )
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'), ())]
def test_minimum(): l = Context(('spam', ), ('ham', ), [(True, )]).lattice assert len(l) == 1 assert l.infimum is l.supremum assert l.atoms == ()
def test_duplicate_object(self): with self.assertRaises(ValueError): Context(('spam', 'spam'), ('ham', 'eggs'), [(True, False), (False, True)])
def test_ne(self): self.assertTrue(self.context != Context(('spam', 'eggs'), ( 'camelot', 'launcelot'), [(True, False), (False, True)]))
def test_object_property_overlap(): with pytest.raises(ValueError, match=r'overlap'): Context(('spam', 'eggs'), ('eggs', 'ham'), [(True, False), (False, True)])
def test_trivial(self): l = Context(('spam', ), ('ham', ), [(False, )]).lattice self.assertEqual(len(l), 2) self.assertIsNot(l.infimum, l.supremum) self.assertEqual(l.atoms, (l.supremum, ))
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)])
def test_empty_relation(): with pytest.raises(ValueError): Context((), ('spam', ), [(False, )]) with pytest.raises(ValueError): Context(('spam', ), (), [(False, )])
def test_eq_true(context): assert context == Context(context.objects, context.properties, context.bools)
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)])
def test_empty_objects(): with pytest.raises(ValueError, match=r'empty objects'): Context((), ('spam',), [(False,)])
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)])
def test_ne_false(context): assert not context != Context(context.objects, context.properties, context.bools)
def test_minimum(self): l = Context(('spam', ), ('ham', ), [(True, )]).lattice self.assertEqual(len(l), 1) self.assertIs(l.infimum, l.supremum) self.assertEqual(l.atoms, ())