X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/12b5230d8fdb3ad995e867fb5d58a69e8a627e68..e2acc67a478455184e5e714e63a61e78ad37d787:/tests/test_picture.py?ds=inline diff --git a/tests/test_picture.py b/tests/test_picture.py index 00b03ce..afa4da8 100644 --- a/tests/test_picture.py +++ b/tests/test_picture.py @@ -1,58 +1,56 @@ -# -*- coding: utf-8 -*- -# # This file is part of Librarian, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. # +from os import path +import unittest from librarian import picture, dcparser from tests.utils import get_all_fixtures, get_fixture -from os import path -def test_wlpictureuri(): - uri = picture.WLPictureURI('http://wolnelektury.pl/katalog/obraz/angelus-novus') +class PictureTests(unittest.TestCase): + def test_wlpictureuri(self): + uri = picture.WLPictureURI('http://wolnelektury.pl/katalog/obraz/angelus-novus') - -def check_load(xml_file): - pi = dcparser.parse(xml_file, picture.PictureInfo) - assert pi is not None - assert isinstance(pi, picture.PictureInfo) + def check_load(self, xml_file): + pi = dcparser.parse(xml_file, picture.PictureInfo) + self.assertIsNotNone(pi) + self.assertIsInstance(pi, picture.PictureInfo) - -def test_load(): - for fixture in get_all_fixtures('picture', '*.xml'): - yield check_load, fixture - - -def test_wlpicture(): - wlp = picture.WLPicture.from_file(open(get_fixture('picture', 'angelus-novus.xml'))) - pi = wlp.picture_info - - # from nose.tools import set_trace; set_trace() - assert pi.type[0] == u"Image" - assert pi.mime_type == u'image/jpeg' == wlp.mime_type - assert wlp.slug == 'angelus-novus' - - assert path.exists(wlp.image_path) + def test_load(self): + for fixture in get_all_fixtures('picture', '*.xml'): + with self.subTest(fixture=fixture): + self.check_load(fixture) + + def test_wlpicture(self): + with open(get_fixture('picture', 'angelus-novus.xml')) as f: + wlp = picture.WLPicture.from_file(f) + pi = wlp.picture_info + + self.assertEqual(pi.type[0], "Image") + self.assertEqual(pi.mime_type, 'image/jpeg') + self.assertEqual(wlp.mime_type, 'image/jpeg') + self.assertEqual(wlp.slug, 'angelus-novus') + self.assertTrue(path.exists(wlp.image_path)) - f = wlp.image_file('r') - f.close() - - -def test_picture_parts(): - wlp = picture.WLPicture.from_file(open(get_fixture('picture', 'angelus-novus.xml'))) - parts = list(wlp.partiter()) - expect_parts = 4 - assert len(parts) == expect_parts, "there should be %d parts of the picture" % expect_parts - motifs = set() - names = set() - - print parts - for p in parts: - for m in p['themes']: - motifs.add(m) - for p in parts: - if p['object']: - names.add(p['object']) - - assert motifs == {u'anioł historii', u'spojrzenie'}, "missing motifs, got: %s" % motifs - assert names == {u'obraz cały', u'skrzydło'}, 'missing objects, got: %s' % names + f = wlp.image_file() + f.close() + + + def test_picture_parts(self): + with open(get_fixture('picture', 'angelus-novus.xml')) as f: + wlp = picture.WLPicture.from_file(f) + parts = list(wlp.partiter()) + expect_parts = 4 + self.assertEqual(len(parts), expect_parts, "there should be %d parts of the picture" % expect_parts) + motifs = set() + names = set() + + for p in parts: + for m in p['themes']: + motifs.add(m) + for p in parts: + if p['object']: + names.add(p['object']) + + self.assertEqual(motifs, {'anioł historii', 'spojrzenie'}, "missing motifs, got: %s" % motifs) + self.assertEqual(names, {'obraz cały', 'skrzydło'}, 'missing objects, got: %s' % names)