Example #1
0
    def _getThumbnail (self, page, fname):
        """
        Метод создает превьюшку и возвращает относительный путь до нее (относительно корня страницы)
        """
        thumbmaker = PageThumbmaker()

        return thumbmaker.createThumbByMaxSize (
            page,
            fname,
            self._thumbsize).replace ("\\", "/")
Example #2
0
    def setUp(self):
        self.thumbmaker = PageThumbmaker()

        # Здесь будет создаваться вики
        self.path = mkdtemp(prefix=u'Абырвалг абыр')

        self.wikiroot = WikiDocument.create(self.path)

        factory = TextPageFactory()
        factory.create(self.wikiroot, u"Страница 1", [])
        factory.create(self.wikiroot, u"Страница 2", [])
        factory.create(self.wikiroot[u"Страница 2"], u"Страница 3", [])
        factory.create(self.wikiroot[u"Страница 2/Страница 3"], u"Страница 4",
                       [])
        factory.create(self.wikiroot[u"Страница 1"], u"Страница 5", [])
Example #3
0
    def setUp (self):
        self.thumbmaker = PageThumbmaker()

        # Здесь будет создаваться вики
        self.path = u"../test/testwiki"
        removeWiki (self.path)

        self.rootwiki = WikiDocument.create (self.path)

        TextPageFactory.create (self.rootwiki, u"Страница 1", [])
        TextPageFactory.create (self.rootwiki, u"Страница 2", [])
        TextPageFactory.create (self.rootwiki[u"Страница 2"], u"Страница 3", [])
        TextPageFactory.create (self.rootwiki[u"Страница 2/Страница 3"], u"Страница 4", [])
        TextPageFactory.create (self.rootwiki[u"Страница 1"], u"Страница 5", [])
Example #4
0
    def setUp (self):
        self.thumbmaker = PageThumbmaker()

        # Здесь будет создаваться вики
        self.path = mkdtemp (prefix=u'Абырвалг абыр')

        self.wikiroot = WikiDocument.create (self.path)

        factory = TextPageFactory()
        factory.create (self.wikiroot, u"Страница 1", [])
        factory.create (self.wikiroot, u"Страница 2", [])
        factory.create (self.wikiroot[u"Страница 2"], u"Страница 3", [])
        factory.create (self.wikiroot[u"Страница 2/Страница 3"], u"Страница 4", [])
        factory.create (self.wikiroot[u"Страница 1"], u"Страница 5", [])
Example #5
0
class PageThumbmakerTest (unittest.TestCase):
    def setUp (self):
        self.thumbmaker = PageThumbmaker()

        # Здесь будет создаваться вики
        self.path = u"../test/testwiki"
        removeWiki (self.path)

        self.rootwiki = WikiDocument.create (self.path)

        TextPageFactory.create (self.rootwiki, u"Страница 1", [])
        TextPageFactory.create (self.rootwiki, u"Страница 2", [])
        TextPageFactory.create (self.rootwiki[u"Страница 2"], u"Страница 3", [])
        TextPageFactory.create (self.rootwiki[u"Страница 2/Страница 3"], u"Страница 4", [])
        TextPageFactory.create (self.rootwiki[u"Страница 1"], u"Страница 5", [])
    

    def tearDown(self):
        removeWiki (self.path)
    

    def testThumbByWidthJpeg (self):
        images_dir = "../test/images"

        fname_in = "first.jpg"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        newwidth = 250
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByWidth (page, fname_in, newwidth)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)
    

    def testThumbByWidthPng (self):
        images_dir = "../test/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByWidth (page, fname_in, newwidth)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)
    

    def testThumbByHeightJpeg (self):
        images_dir = "../test/images"

        fname_in = "first.jpg"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        newwidth = 249
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByHeight (page, fname_in, newheight)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)
    

    def testThumbByHeightPng (self):
        images_dir = "../test/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        newwidth = 249
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByHeight (page, fname_in, newheight)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)
    

    def testThumbByMaxSizeJpeg1 (self):
        images_dir = "../test/images"

        fname_in = "first.jpg"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        maxsize = 250

        newwidth = 250
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByMaxSize (page, fname_in, maxsize)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)
    

    def testThumbByMaxSizeJpeg2 (self):
        images_dir = "../test/images"

        fname_in = "first_vertical.jpeg"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        maxsize = 250

        newwidth = 182
        newheight = 250

        thumb_fname = self.thumbmaker.createThumbByMaxSize (page, fname_in, maxsize)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)

    
    def testThumbByMaxSizePng (self):
        images_dir = "../test/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.rootwiki[u"Страница 1"]

        Attachment (page).attach ([os.path.join (images_dir, fname_in) ] )

        maxsize = 250

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByMaxSize (page, fname_in, maxsize)
        thumb_path = os.path.join (page.path, thumb_fname)

        (width, height) = getImageSize (thumb_path)
        
        self.assertTrue (os.path.exists (thumb_path), thumb_path)
        self.assertEqual (width, newwidth)
        self.assertEqual (height, newheight)
Example #6
0
class PageThumbmakerTest(BaseWxTestCase):
    def setUp(self):
        super().setUp()
        self.thumbmaker = PageThumbmaker()

        # Здесь будет создаваться вики
        self.path = mkdtemp(prefix='Абырвалг абыр')

        self.wikiroot = WikiDocument.create(self.path)

        factory = TextPageFactory()
        factory.create(self.wikiroot, "Страница 1", [])
        factory.create(self.wikiroot, "Страница 2", [])
        factory.create(self.wikiroot["Страница 2"], "Страница 3", [])
        factory.create(self.wikiroot["Страница 2/Страница 3"],
                       "Страница 4",
                       [])
        factory.create(self.wikiroot["Страница 1"], "Страница 5", [])

    def tearDown(self):
        super().tearDown()
        removeDir(self.path)

    def testThumbByWidthJpeg(self):
        images_dir = "../test/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 250
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByWidth(page,
                                                         fname_in,
                                                         newwidth)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByWidthPng(self):
        images_dir = "../test/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByWidth(page,
                                                         fname_in,
                                                         newwidth)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByHeightJpeg(self):
        images_dir = "../test/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 249
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByHeight(page,
                                                          fname_in,
                                                          newheight)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByHeightPng(self):
        images_dir = "../test/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 249
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByHeight(page,
                                                          fname_in,
                                                          newheight)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByMaxSizeJpeg1(self):
        images_dir = "../test/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 250
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByMaxSize(page,
                                                           fname_in,
                                                           maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByMaxSizeJpeg2(self):
        images_dir = "../test/images"

        fname_in = "first_vertical.jpeg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 182
        newheight = 250

        thumb_fname = self.thumbmaker.createThumbByMaxSize(page,
                                                           fname_in,
                                                           maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByMaxSizePng(self):
        images_dir = "../test/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByMaxSize(page,
                                                           fname_in,
                                                           maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)
Example #7
0
class PageThumbmakerTest(BaseWxTestCase):
    def setUp(self):
        super().setUp()
        self.thumbmaker = PageThumbmaker()

        # Здесь будет создаваться вики
        self.path = mkdtemp(prefix='Абырвалг абыр')

        self.wikiroot = WikiDocument.create(self.path)

        factory = TextPageFactory()
        factory.create(self.wikiroot, "Страница 1", [])
        factory.create(self.wikiroot, "Страница 2", [])
        factory.create(self.wikiroot["Страница 2"], "Страница 3", [])
        factory.create(self.wikiroot["Страница 2/Страница 3"], "Страница 4",
                       [])
        factory.create(self.wikiroot["Страница 1"], "Страница 5", [])

    def tearDown(self):
        super().tearDown()
        removeDir(self.path)

    def testThumbByWidthJpeg(self):
        images_dir = "testdata/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 250
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByWidth(
            page, fname_in, newwidth)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByWidthPng(self):
        images_dir = "testdata/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByWidth(
            page, fname_in, newwidth)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByHeightJpeg(self):
        images_dir = "testdata/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 249
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByHeight(
            page, fname_in, newheight)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByHeightPng(self):
        images_dir = "testdata/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        newwidth = 249
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByHeight(
            page, fname_in, newheight)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByMaxSizeJpeg1(self):
        images_dir = "testdata/images"

        fname_in = "first.jpg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 250
        newheight = 182

        thumb_fname = self.thumbmaker.createThumbByMaxSize(
            page, fname_in, maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByMaxSizeJpeg2(self):
        images_dir = "testdata/images"

        fname_in = "first_vertical.jpeg"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 182
        newheight = 250

        thumb_fname = self.thumbmaker.createThumbByMaxSize(
            page, fname_in, maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)

    def testThumbByMaxSizePng(self):
        images_dir = "testdata/images"

        fname_in = "outwiker_1.1.0_02.png"
        page = self.wikiroot["Страница 1"]

        Attachment(page).attach([os.path.join(images_dir, fname_in)])

        maxsize = 250

        newwidth = 250
        newheight = 215

        thumb_fname = self.thumbmaker.createThumbByMaxSize(
            page, fname_in, maxsize)
        thumb_path = os.path.join(page.path, thumb_fname)

        (width, height) = getImageSize(thumb_path)

        self.assertTrue(os.path.exists(thumb_path), thumb_path)
        self.assertEqual(width, newwidth)
        self.assertEqual(height, newheight)