def test__init__1(self): m = Messages(messages) p = Translations(polish) msg = r"%s is not an instance of %s" % (repr('foo'), repr( table_.Table)) with self.assertRaisesRegex(TypeError, msg): link_.Link(('foo', p), ('t', 'm')) with self.assertRaisesRegex(TypeError, msg): link_.Link((m, 'foo'), ('t', 'm')) msg = 'missing one of alternative arguments: column, resolver' with self.assertRaisesRegex(TypeError, msg): link_.Link((m, p), ('t', 'm'))
def test__keywrap__2(self): docs = (tableclass(Document))() pages = (tableclass(Page))() dct = join_.JoinTypeDict() rel = link_.Link((docs,pages), ('pages','doc'), column = 0) self.assertIsInstance(dct.__keywrap__(rel), ref_.Ref) self.assertIs(dct.__keywrap__(rel).obj, rel)
def test__opposite_keys__2(self): m = Messages(messages) p = Translations(polish) link = link_.Link((m, p), ('t', 's'), column='msgid') self.assertEqual(list(link.opposite_keys(link_.SOURCE, 0)), ['hello.world']) self.assertEqual(list(link.opposite_keys(link_.SOURCE, 1)), ['vibek.is.hungry']) self.assertEqual(list(link.opposite_keys(link_.SOURCE, 2)), ['weather.is.awful'])
def test__opposite_keys__3(self): m = Messages(messages) p = Translations(polish) link = link_.Link( (m, p), ('t', 's'), resolver=linkresolver_.SourceColumnBasedLinkResolver(m, 'msgid')) self.assertEqual(list(link.opposite_keys(link_.SOURCE, 0)), ['hello.world']) self.assertEqual(list(link.opposite_keys(link_.SOURCE, 1)), ['vibek.is.hungry']) self.assertEqual(list(link.opposite_keys(link_.SOURCE, 2)), ['weather.is.awful']) self.assertEqual(list(link.opposite_keys(link_.SOURCE, 3)), [])
def test__init__4(self): source = Messages() target = Translations() link = link_.Link((source, target), ('t', 's'), False, column='msgid') self.assertIs(link.source_table, source) self.assertIs(link.target_table, target) self.assertIsInstance(link._resolver, linkresolver_.SourceColumnBasedLinkResolver) self.assertEqual( link._resolver, linkresolver_.SourceColumnBasedLinkResolver(source, 0)) self.assertFalse('t' in source.relations) self.assertFalse('s' in target.relations)
def test__opposite_keys__4(self): m = Messages(messages) p = Translations(polish) link = link_.Link( (m, p), ('t', 's'), resolver=linkresolver_.SourceColumnBasedLinkResolver(m, 'msgid')) self.assertEqual(list(link.opposite_keys(link_.TARGET, 'hello.world')), [0]) self.assertEqual( list(link.opposite_keys(link_.TARGET, 'vibek.is.hungry')), [1]) self.assertEqual( list(link.opposite_keys(link_.TARGET, 'weather.is.awful')), [2]) self.assertEqual(list(link.opposite_keys(link_.TARGET, 'untranslated')), []) # no real link self.assertEqual(list(link.opposite_keys(link_.TARGET, 'bleah')), [])
def test__init__3(self): source = Messages() target = Translations() link = link_.Link((source, target), ('t', 's'), column='msgid') self.assertIs(link.source_table, source) self.assertIs(link.target_table, target) self.assertIsInstance(link._resolver, linkresolver_.SourceColumnBasedLinkResolver) self.assertEqual( link._resolver, linkresolver_.SourceColumnBasedLinkResolver(source, 0)) self.assertIsInstance(source.relations['t'], endpoint_.Endpoint) self.assertIs(source.relations['t'].relation, link) self.assertIs(source.relations['t'].side, link_.SOURCE) self.assertIsInstance(target.relations['s'], endpoint_.Endpoint) self.assertIs(target.relations['s'].relation, link) self.assertIs(target.relations['s'].side, link_.TARGET)
def test__eq__1(self): m = Messages(messages) p = Translations(polish) self.assertTrue( link_.Link((m, p), ( 't', 's'), column=0) == link_.Link((m, p), ('t', 's'), column=0)) self.assertFalse( link_.Link((p, m), ( 't', 's'), column=0) == link_.Link((m, p), ('t', 's'), column=0)) self.assertFalse( link_.Link((m, p), ( 't', 's'), column=1) == link_.Link((m, p), ('t', 's'), column=0))
def test__rows_2(self): University = declare( DataType, 'University', ('fullname', 'city'), plural = 'Universities' ) UE = entityclass(University) db = db1.clone() db.t_universities = tableclass(University)() db.tables.insert(-1,db.t_universities) db.l_header_university = link_.Link( (db.t_headers, db.t_universities), ('university', 'header'), column = 'university') db.t_universities['UTH'] = UE(('Uniwersytet Techniczno-Humanistyczny w Radomiu', 'Radom')) db.t_universities['PW'] = UE(('Politechnika Warszawska', 'Warszawa')) db.t_universities['UJ'] = UE(('Uniwersytet Jagielloński', 'Kraków')) q = join_.Join(db.t_documents) e = [ [0, 0, 0, 0, 'PW', 0], [0, 0, 1, 0, 'PW', 1], [0, 1, 2, 0, 'PW', 0], [1, 2, 3, 1, 'UTH', 0], [1, 2, 4, 1, 'UTH', 1] ] for i in range(len(e)): for j in range(len(e[i])): k = e[i][j] e[i][j] = db.tables[j].getrecord(k) r = q.rows() self.assertEqual(next(r), e[0]) self.assertEqual(next(r), e[1]) self.assertEqual(next(r), e[2]) self.assertEqual(next(r), e[3]) self.assertEqual(next(r), e[4]) with self.assertRaises(StopIteration): next(r)