def test_do_magick_convert_without_kwargs(self, run, _do_magick_command):
     _do_magick_command.return_value = ['convert']
     pdf_compress.do_magick_convert(
         FilePath('test.tif'),
         FilePath('test.tiff'),
     )
     run.assert_called_with(
         ['convert', '-units', 'PixelsPerInch', '-compress', 'Group4',
          '-monochrome', 'test.tif', 'test.tiff']
     )
    def test_option_border(self):
        tiff = copy(tmp_tiff1)

        info_before = pdf_compress.do_magick_identify(FilePath(tiff))
        check_output(['pdf-compress.py', 'convert', '--deskew', '--trim',
                      '--border', tiff])
        info_after = pdf_compress.do_magick_identify(FilePath(tiff))

        self.assertEqual(info_before['width'], 300)
        self.assertEqual(info_after['width'], 311)

        self.assertEqual(info_after['height'], 442)
        self.assertEqual(info_before['height'], 430)
 def run(self, margin, *dimensions):
     with patch('PyPDF2.PdfFileReader') as reader, \
          patch('PyPDF2.PdfFileWriter'), \
          patch('PyPDF2.pdf.PageObject.createBlankPage') as blank, \
          patch('jfscripts.pdf_compress.open'):
         reader.return_value.pages = self.mock_pdf2_pages(*dimensions)
         pdf_compress.unify_page_size(
             FilePath('test.pdf'),
             FilePath('out.pdf'),
             margin
         )
     return {
         'reader': reader,
         'blank': blank,
     }
 def test_with_real_pdf(self):
     tmp = copy(tmp_pdf)
     self.assertExists(tmp)
     path = FilePath(tmp)
     check_output(['pdf-compress.py', 'convert', tmp])
     result = ('0.tiff', '1.tiff', '2.tiff')
     for test_file in result:
         self.assertExists(path.base + '-00' + test_file, test_file)
 def test_do_magick_convert_kwargs(self, run, _do_magick_command):
     _do_magick_command.return_value = ['convert']
     pdf_compress.do_magick_convert(
         FilePath('test.tif'),
         FilePath('test.pdf'),
         threshold='60%',
         enlighten_border=False,
         border=True,
         resize=True,
         trim=True,
         deskew=True,
     )
     run.assert_called_with(
         ['convert', '-units', 'PixelsPerInch', '-resize', '200%',
          '-deskew', '40%', '-threshold', '60%', '-trim', '+repage',
          '-border', '5%', '-bordercolor', '#FFFFFF', '-compress', 'Group4',
          '-monochrome', 'test.tif', 'test.pdf']
     )
 def test_do_magick_identify(self, check_output):
     check_output.side_effect = [
         bytes('2552'.encode('utf-8')),
         bytes('3656'.encode('utf-8')),
         bytes('256'.encode('utf-8')),
     ]
     result = pdf_compress.do_magick_identify(FilePath('test.pdf'))
     self.assertEqual(result, {'width': 2552, 'height': 3656,
                               'colors': 256})
 def test_join_ocr(self):
     png1 = copy(tmp_png1)
     png2 = copy(tmp_png2)
     check_output(['pdf-compress.py', 'join', '--ocr', png1, png2])
     self.assertExists(
         os.path.join(
             list_files.common_path((png1, png2)),
             FilePath(png1).basename + '_magick.pdf',
         )
     )
 def test_do_pdfimages(self):
     state = get_state()
     with mock.patch('subprocess.run') as mock_run:
         pdf_compress.do_pdfimages(FilePath('test.pdf'), state)
         args = mock_run.call_args[0][0]
         self.assertEqual(args[0], 'pdfimages')
         self.assertEqual(args[1], '-tiff')
         self.assertEqual(args[2], 'test.pdf')
         self.assertIn('test.pdf', args[2])
         # test_magick_901ca3ae-c5ad-11e8-9796-5c514fcf0a5d
         self.assertEqual(len(args[3]), 48)
         self.assertTrue(args[3].startswith('test_'))
 def test_unify_margin(self):
     pdf = copy(tmp_pdf)
     run(['pdf-compress.py', 'unify', '--margin', '10', pdf])
     result = FilePath(pdf).new(append='_unifed')
     self.assertExists(str(result))
 def test_option_ocr_input_jpg(self):
     jpg = copy(tmp_ocr)
     check_output(['pdf-compress.py', 'convert', '--ocr', jpg])
     result = FilePath(jpg).new(extension='pdf')
     self.assertExists(str(result))
 def test_real_backup_do_backup(self):
     tmp = copy(tmp_tiff1)
     check_output(['pdf-compress.py', 'convert', '--backup', tmp])
     backup = FilePath(tmp).new(append='_backup', extension='tiff')
     self.assertExists(str(backup))
 def test_do_tesseract_one_language(self, run):
     pdf_compress.do_tesseract(FilePath('test.tiff'), languages=['deu'])
     self.assertEqual(
         run.call_args[0][0],
         ['tesseract', '-l', 'deu', 'test.tiff', 'test', 'pdf'],
     )
 def test_do_tesseract(self, run):
     pdf_compress.do_tesseract(FilePath('test.tiff'))
     self.assertEqual(
         run.call_args[0][0],
         ['tesseract', '-l', 'deu+eng', 'test.tiff', 'test', 'pdf'],
     )
 def test_subcommand_samples(self, do_magick_convert):
     state = get_state()
     pdf_compress.subcommand_samples(FilePath('test.jpg'), state)
     self.assertEqual(do_magick_convert.call_count, 29)