def testParser(self): """basic parser test""" f = self.getFile("""\ # comment /album1/sub1; test; desc1 /album2; test /album1/sub1 photo_a1; title; desc ### photo_a2; title; desc http://www.danlann.org photo_a3; title photo_a4 """) self.load(f) check(self.interpreter, self.gallery) self.assertEquals(len(self.gallery.subalbums), 1) a1 = self.gallery.subalbums[0].subalbums[0] self.assertEquals(a1.gallery, self.gallery) self.assertEquals(a1.dir, 'album1/sub1') self.assertEquals(len(a1.photos), 0) a2 = self.gallery.subalbums[0] self.assertEquals(a2.gallery, self.gallery) self.assertEquals(a2.dir, 'album2') self.assertEquals(len(a2.photos), 4)
def testReferences(self): """references""" f = self.getFile("""\ /album1; test; desc1 /album3 /album2 photo_a1; title; desc ### photo_a2; title; desc http://www.danlann.org /album2; album 2; this album no 2. /album3 photo_a3; title photo_a4 /album3; album 3 photo_a3; title photo_a4 """) self.load(f) check(self.interpreter, self.gallery) self.assertEquals(len(self.gallery.subalbums), 1) a1 = self.gallery.subalbums[0] a3, a2 = a1.subalbums self.assertEquals(a1.dir, 'album1') self.assertEquals(a2.dir, 'album2') self.assertEquals(a3.dir, 'album3')
def parse(self): """ Parse gallery data. """ interpreter = parser.interpreter(self.gallery) # read album files for fn in self.albums: log.debug('parsing album file %s' % fn) f = open(fn) parser.load(f, interpreter) f.close() # check gallery data instance parser.check(interpreter, self.gallery)