def load_pdf_pictures_test(self):
        """
        Test loading of a Pdf and check size of generate pictures
        """
        # GIVEN: A Pdf-file
        test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')

        # WHEN: The Pdf is loaded
        controller = PdfController(plugin=self.mock_plugin)
        if not controller.check_available():
            raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
        controller.temp_folder = self.temp_folder
        controller.thumbnail_folder = self.thumbnail_folder
        document = PdfDocument(controller, test_file)
        loaded = document.load_presentation()

        # THEN: The load should succeed and pictures should be created and have been scales to fit the screen
        self.assertTrue(loaded, 'The loading of the PDF should succeed.')
        image = QtGui.QImage(os.path.join(self.temp_folder, 'pdf_test1.pdf', 'mainslide001.png'))
        # Based on the converter used the resolution will differ a bit
        if controller.gsbin:
            self.assertEqual(760, image.height(), 'The height should be 760')
            self.assertEqual(537, image.width(), 'The width should be 537')
        else:
            self.assertEqual(768, image.height(), 'The height should be 768')
            self.assertEqual(543, image.width(), 'The width should be 543')
Example #2
0
    def load_pdf_pictures(self, exe_path):
        """
        Test loading a Pdf and check the generated pictures' size
        """
        # GIVEN: A Pdf-file
        test_file_path = RESOURCE_PATH / 'presentations' / 'pdf_test1.pdf'

        # WHEN: The Pdf is loaded
        Settings().setValue('presentations/pdf_program', exe_path)
        controller = PdfController(plugin=self.mock_plugin)
        controller.temp_folder = self.temp_folder_path
        controller.thumbnail_folder = self.thumbnail_folder_path
        document = PdfDocument(controller, test_file_path)
        loaded = document.load_presentation()

        # THEN: The load should succeed and pictures should be created and have been scaled to fit the screen
        assert loaded is True, 'The loading of the PDF should succeed.'
        image = QtGui.QImage(os.path.join(str(self.temp_folder_path), 'pdf_test1.pdf', 'mainslide001.png'))
        # Based on the converter used the resolution will differ a bit
        if controller.gsbin:
            assert 1076 == image.height(), 'The height should be 1076'
            assert 760 == image.width(), 'The width should be 760'
        else:
            width, height = get_screen_resolution()
            # Calculate the width of the PDF based on the aspect ratio of the PDF
            width = int(round(height * 0.70703125, 0))
            assert image.height() == height, 'The height should be {height}'.format(height=height)
            assert image.width() == width, 'The width should be {width}'.format(width=width)
Example #3
0
    def test_load_pdf_pictures(self):
        """
        Test loading of a Pdf and check size of generate pictures
        """
        # GIVEN: A Pdf-file
        test_file_path = RESOURCE_PATH / 'presentations' / 'pdf_test1.pdf'

        # WHEN: The Pdf is loaded
        controller = PdfController(plugin=self.mock_plugin)
        if not controller.check_available():
            raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
        controller.temp_folder = self.temp_folder_path
        controller.thumbnail_folder = self.thumbnail_folder_path
        document = PdfDocument(controller, test_file_path)
        loaded = document.load_presentation()

        # THEN: The load should succeed and pictures should be created and have been scales to fit the screen
        assert loaded is True, 'The loading of the PDF should succeed.'
        image = QtGui.QImage(os.path.join(str(self.temp_folder_path), 'pdf_test1.pdf', 'mainslide001.png'))
        # Based on the converter used the resolution will differ a bit
        if controller.gsbin:
            assert 760 == image.height(), 'The height should be 760'
            assert 537 == image.width(), 'The width should be 537'
        else:
            assert 768 == image.height(), 'The height should be 768'
            assert 543 == image.width(), 'The width should be 543'
    def test_load_pdf_pictures(self):
        """
        Test loading of a Pdf and check size of generate pictures
        """
        # GIVEN: A Pdf-file
        test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations',
                                 'pdf_test1.pdf')

        # WHEN: The Pdf is loaded
        controller = PdfController(plugin=self.mock_plugin)
        if not controller.check_available():
            raise SkipTest(
                'Could not detect mudraw or ghostscript, so skipping PDF test')
        controller.temp_folder = self.temp_folder
        controller.thumbnail_folder = self.thumbnail_folder
        document = PdfDocument(controller, test_file)
        loaded = document.load_presentation()

        # THEN: The load should succeed and pictures should be created and have been scales to fit the screen
        self.assertTrue(loaded, 'The loading of the PDF should succeed.')
        image = QtGui.QImage(
            os.path.join(self.temp_folder, 'pdf_test1.pdf',
                         'mainslide001.png'))
        # Based on the converter used the resolution will differ a bit
        if controller.gsbin:
            self.assertEqual(760, image.height(), 'The height should be 760')
            self.assertEqual(537, image.width(), 'The width should be 537')
        else:
            self.assertEqual(768, image.height(), 'The height should be 768')
            self.assertEqual(543, image.width(), 'The width should be 543')
Example #5
0
    def load_pdf(self, exe_path):
        """
        Test loading a Pdf using the PdfController
        """
        # GIVEN: A Pdf-file
        test_file_path = RESOURCE_PATH / 'presentations' / 'pdf_test1.pdf'

        # WHEN: The Pdf is loaded
        Settings().setValue('presentations/pdf_program', exe_path)
        controller = PdfController(plugin=self.mock_plugin)
        controller.temp_folder = self.temp_folder_path
        controller.thumbnail_folder = self.thumbnail_folder_path
        document = PdfDocument(controller, test_file_path)
        loaded = document.load_presentation()

        # THEN: The load should succeed and we should be able to get a pagecount
        assert loaded is True, 'The loading of the PDF should succeed.'
        assert 3 == document.get_slide_count(), 'The pagecount of the PDF should be 3.'
    def load_pdf_test(self):
        """
        Test loading of a Pdf using the PdfController
        """
        # GIVEN: A Pdf-file
        test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations', 'pdf_test1.pdf')

        # WHEN: The Pdf is loaded
        controller = PdfController(plugin=self.mock_plugin)
        if not controller.check_available():
            raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
        controller.temp_folder = self.temp_folder
        controller.thumbnail_folder = self.thumbnail_folder
        document = PdfDocument(controller, test_file)
        loaded = document.load_presentation()

        # THEN: The load should succeed and we should be able to get a pagecount
        self.assertTrue(loaded, 'The loading of the PDF should succeed.')
        self.assertEqual(3, document.get_slide_count(), 'The pagecount of the PDF should be 3.')
Example #7
0
    def test_load_pdf(self):
        """
        Test loading of a Pdf using the PdfController
        """
        # GIVEN: A Pdf-file
        test_file_path = RESOURCE_PATH / 'presentations' / 'pdf_test1.pdf'

        # WHEN: The Pdf is loaded
        controller = PdfController(plugin=self.mock_plugin)
        if not controller.check_available():
            raise SkipTest('Could not detect mudraw or ghostscript, so skipping PDF test')
        controller.temp_folder = self.temp_folder_path
        controller.thumbnail_folder = self.thumbnail_folder_path
        document = PdfDocument(controller, test_file_path)
        loaded = document.load_presentation()

        # THEN: The load should succeed and we should be able to get a pagecount
        assert loaded is True, 'The loading of the PDF should succeed.'
        assert 3 == document.get_slide_count(), 'The pagecount of the PDF should be 3.'
Example #8
0
    def test_constructor(self):
        """
        Test the Constructor from the PdfController
        """
        # GIVEN: No presentation controller
        controller = None

        # WHEN: The presentation controller object is created
        controller = PdfController(plugin=self.mock_plugin)

        # THEN: The name of the presentation controller should be correct
        assert 'Pdf' == controller.name, 'The name of the presentation controller should be correct'
    def test_load_pdf(self):
        """
        Test loading of a Pdf using the PdfController
        """
        # GIVEN: A Pdf-file
        test_file = os.path.join(TEST_RESOURCES_PATH, 'presentations',
                                 'pdf_test1.pdf')

        # WHEN: The Pdf is loaded
        controller = PdfController(plugin=self.mock_plugin)
        if not controller.check_available():
            raise SkipTest(
                'Could not detect mudraw or ghostscript, so skipping PDF test')
        controller.temp_folder = self.temp_folder
        controller.thumbnail_folder = self.thumbnail_folder
        document = PdfDocument(controller, test_file)
        loaded = document.load_presentation()

        # THEN: The load should succeed and we should be able to get a pagecount
        self.assertTrue(loaded, 'The loading of the PDF should succeed.')
        self.assertEqual(3, document.get_slide_count(),
                         'The pagecount of the PDF should be 3.')
Example #10
0
    def test_process_check_binary_gs(self, mocked_check_binary_exists):
        """
        Test that the correct output from gs is detected
        """
        # GIVEN: A mocked check_binary_exists that returns gs output
        gs_output = (b'GPL Ghostscript 9.19 (2016-03-23)\nCopyright (C) 2016 Artifex Software, Inc.  All rights reserv'
                     b'ed.\nUsage: gs [switches] [file1.ps file2.ps ...]')
        mocked_check_binary_exists.return_value = gs_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mutool should be detected
        assert 'gs' == ret, 'mutool should have been detected'
Example #11
0
    def test_process_check_binary_gs(self, mocked_check_binary_exists):
        """
        Test that the correct output from gs is detected
        """
        # GIVEN: A mocked check_binary_exists that returns gs output
        gs_output = (b'GPL Ghostscript 9.19 (2016-03-23)\nCopyright (C) 2016 Artifex Software, Inc.  All rights reserv'
                     b'ed.\nUsage: gs [switches] [file1.ps file2.ps ...]')
        mocked_check_binary_exists.return_value = gs_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mutool should be detected
        self.assertEqual('gs', ret, 'mutool should have been detected')
Example #12
0
    def test_process_check_binary_old_motool(self, mocked_check_binary_exists):
        """
        Test that the output from the old mutool is not accepted
        """
        # GIVEN: A mocked check_binary_exists that returns old mutool output
        old_mutool_output = (b'usage: mutool <command> [options]\n\tclean\t-- rewrite pdf file\n\textract\t-- extract '
                             b'font and image resources\n\tinfo\t-- show information about pdf resources\n\tposter\t-- '
                             b'split large page into many tiles\n\tshow\t-- show internal pdf objects')
        mocked_check_binary_exists.return_value = old_mutool_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mutool should be detected
        assert ret is None, 'old mutool should not be accepted!'
Example #13
0
    def test_process_check_binary_old_motool(self, mocked_check_binary_exists):
        """
        Test that the output from the old mutool is not accepted
        """
        # GIVEN: A mocked check_binary_exists that returns old mutool output
        old_mutool_output = (b'usage: mutool <command> [options]\n\tclean\t-- rewrite pdf file\n\textract\t-- extract '
                             b'font and image resources\n\tinfo\t-- show information about pdf resources\n\tposter\t-- '
                             b'split large page into many tiles\n\tshow\t-- show internal pdf objects')
        mocked_check_binary_exists.return_value = old_mutool_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mutool should be detected
        self.assertIsNone(ret, 'old mutool should not be accepted!')
Example #14
0
    def on_program_path_edit_path_changed(self, new_path):
        """
        Handle the `pathEditChanged` signal from program_path_edit

        :param pathlib.Path new_path: File path to the new program
        :rtype: None
        """
        if new_path:
            if not PdfController.process_check_binary(new_path):
                critical_error_message_box(
                    UiStrings().Error,
                    translate(
                        'PresentationPlugin.PresentationTab',
                        'The program is not ghostscript or mudraw which is required.'
                    ))
Example #15
0
    def test_process_check_binary_mudraw(self, mocked_check_binary_exists):
        """
        Test that the correct output from mudraw is detected
        """
        # GIVEN: A mocked check_binary_exists that returns mudraw output
        mudraw_output = (b'usage: mudraw [options] input [pages]\n\t-o -\toutput filename (%d for page number)n\t\tsupp'
                         b'orted formats: pgm, ppm, pam, png, pbmn\t-p -\tpasswordn\t-r -\tresolution in dpi (default: '
                         b'72)n\t-w -\twidth (in pixels) (maximum width if -r is specified)n\t-h -\theight (in pixels) '
                         b'(maximum height if -r is specified)')
        mocked_check_binary_exists.return_value = mudraw_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mudraw should be detected
        self.assertEqual('mudraw', ret, 'mudraw should have been detected')
Example #16
0
    def test_process_check_binary_mudraw(self, mocked_check_binary_exists):
        """
        Test that the correct output from mudraw is detected
        """
        # GIVEN: A mocked check_binary_exists that returns mudraw output
        mudraw_output = (b'usage: mudraw [options] input [pages]\n\t-o -\toutput filename (%d for page number)n\t\tsupp'
                         b'orted formats: pgm, ppm, pam, png, pbmn\t-p -\tpasswordn\t-r -\tresolution in dpi (default: '
                         b'72)n\t-w -\twidth (in pixels) (maximum width if -r is specified)n\t-h -\theight (in pixels) '
                         b'(maximum height if -r is specified)')
        mocked_check_binary_exists.return_value = mudraw_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mudraw should be detected
        assert 'mudraw' == ret, 'mudraw should have been detected'
Example #17
0
    def test_process_check_binary_new_motool(self, mocked_check_binary_exists):
        """
        Test that the correct output from the new mutool is detected
        """
        # GIVEN: A mocked check_binary_exists that returns new mutool output
        new_mutool_output = (b'usage: mutool <command> [options]\n\tdraw\t-- convert document\n\trun\t-- run javascript'
                             b'\n\tclean\t-- rewrite pdf file\n\textract\t-- extract font and image resources\n\tinfo\t'
                             b'-- show information about pdf resources\n\tpages\t-- show information about pdf pages\n'
                             b'\tposter\t-- split large page into many tiles\n\tshow\t-- show internal pdf objects\n\t'
                             b'create\t-- create pdf document\n\tmerge\t-- merge pages from multiple pdf sources into a'
                             b'new pdf\n')
        mocked_check_binary_exists.return_value = new_mutool_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mutool should be detected
        assert 'mutool' == ret, 'mutool should have been detected'
Example #18
0
    def test_process_check_binary_new_motool(self, mocked_check_binary_exists):
        """
        Test that the correct output from the new mutool is detected
        """
        # GIVEN: A mocked check_binary_exists that returns new mutool output
        new_mutool_output = (b'usage: mutool <command> [options]\n\tdraw\t-- convert document\n\trun\t-- run javascript'
                             b'\n\tclean\t-- rewrite pdf file\n\textract\t-- extract font and image resources\n\tinfo\t'
                             b'-- show information about pdf resources\n\tpages\t-- show information about pdf pages\n'
                             b'\tposter\t-- split large page into many tiles\n\tshow\t-- show internal pdf objects\n\t'
                             b'create\t-- create pdf document\n\tmerge\t-- merge pages from multiple pdf sources into a'
                             b'new pdf\n')
        mocked_check_binary_exists.return_value = new_mutool_output

        # WHEN: Calling process_check_binary
        ret = PdfController.process_check_binary('test')

        # THEN: mutool should be detected
        self.assertEqual('mutool', ret, 'mutool should have been detected')