def test_inters_compatible(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, True)]) assert a.intersection(b) == Definition(['spam'], ['ni'], [(True, )])
def test_augmented(self): a = Definition(('spam', 'eggs'), ('ni',), [(True,), (False,)]) b = Definition(('ham', 'spam'), ('nini', 'ni',), [(True, True), (False, True)]) a |= b self.assertEqual(a, Definition(('spam', 'eggs', 'ham'), ('ni', 'nini'), [(True, False), (False, False), (True, True)]))
def test_inters_ignoring(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, False)]) assert a.intersection(b, ignore_conflicts=True) == \ Definition(['spam'], ['ni'], [(False,)])
def test_inters_augmented(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, True)]) a &= b assert a == Definition(['spam'], ['ni'], [(True, )])
def test_union_conflicting(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, False)]) with pytest.raises(ValueError, match=r"\[\('spam', 'ni'\)\]"): a.union(b)
def test_union_compatible(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, True)]) assert a.union(b) == \ Definition(('spam', 'eggs', 'ham'), ('ni', 'nini'), [(True, False), (False, False), (True, True)])
def test_union_ignoring(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, False)]) assert a.union(b, ignore_conflicts=True) == \ Definition(('spam', 'eggs', 'ham'), ('ni', 'nini'), [(True, False), (False, False), (True, True)])
def test_union_augmented(): a = Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )]) b = Definition(('ham', 'spam'), ( 'nini', 'ni', ), [(True, True), (False, True)]) a |= b assert a == Definition(('spam', 'eggs', 'ham'), ('ni', 'nini'), [(True, False), (False, False), (True, True)])
def test_fromfile(self, filename='examples/gewaesser.cxt'): d = Definition.fromfile(filename) self.assertEqual(d, (('Fluss', 'Bach', 'Kanal', 'Graben', 'See', 'Tuempel', 'Teich', 'Becken'), ('fliessend', 'stehend', 'natuerlich', 'kuenstlich', 'gross', 'klein'), [(True, False, True, False, True, False), (True, False, True, False, False, True), (True, False, False, True, True, False), (True, False, False, True, False, True), (False, True, True, False, True, False), (False, True, True, False, False, True), (False, True, False, True, True, False), (False, True, False, True, False, True)]))
def test_fromfile(filename='examples/gewaesser.cxt'): objects = ('Fluss', 'Bach', 'Kanal', 'Graben', 'See', 'Tuempel', 'Teich', 'Becken') properties = ('fliessend', 'stehend', 'natuerlich', 'kuenstlich', 'gross', 'klein') bools = [(True, False, True, False, True, False), (True, False, True, False, False, True), (True, False, False, True, True, False), (True, False, False, True, False, True), (False, True, True, False, True, False), (False, True, True, False, False, True), (False, True, False, True, True, False), (False, True, False, True, False, True)] assert Definition.fromfile(filename) == (objects, properties, bools)
def test_compatible(self): a = Definition(('spam', 'eggs'), ('ni',), [(True,), (False,)]) b = Definition(('ham', 'spam'), ('nini', 'ni',), [(True, True), (False, True)]) self.assertEqual(a.intersection(b), Definition(['spam'], ['ni'], [(True,)]))
def test_duplicate_property(self): with self.assertRaisesRegexp(ValueError, 'duplicate properties'): Definition((), ('spam', 'spam'), [])
def definition(): return Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])
def test_duplicate_property(): with pytest.raises(ValueError, match=r'duplicate properties'): Definition((), ('spam', 'spam'), [])
def test_duplicate_object(): with pytest.raises(ValueError, match=r'duplicate objects'): Definition(('spam', 'spam'), (), [])
def setUpClass(cls): cls.definition = Definition(('spam', 'eggs'), ('ni',), [(True,), (False,)])
def test_compatible(self): a = Definition(('spam', 'eggs'), ('ni',), [(True,), (False,)]) b = Definition(('ham', 'spam'), ('nini', 'ni',), [(True, True), (False, True)]) self.assertEqual(a.union(b), Definition(('spam', 'eggs', 'ham'), ('ni', 'nini'), [(True, False), (False, False), (True, True)]))
def test_duplicate_object(self): with self.assertRaisesRegexp(ValueError, 'duplicate objects'): Definition(('spam', 'spam'), (), [])
def test_conflicting(self): a = Definition(('spam', 'eggs'), ('ni',), [(True,), (False,)]) b = Definition(('ham', 'spam'), ('nini', 'ni',), [(True, True), (False, False)]) with self.assertRaisesRegexp(ValueError, "\[\('spam', 'ni'\)\]"): a.union(b)
def test_ignoring(self): a = Definition(('spam', 'eggs'), ('ni',), [(True,), (False,)]) b = Definition(('ham', 'spam'), ('nini', 'ni',), [(True, True), (False, False)]) self.assertEqual(a.union(b, ignore_conflicts=True), Definition(('spam', 'eggs', 'ham'), ('ni', 'nini'), [(True, False), (False, False), (True, True)]))