Пример #1
0
 def test_unpack_pdf_should_not_write_to_a_directory_with_existing_files(self, arg_dict):
     self.use_target_path(arg_dict, sample.TEST_TIFFS)
     action = unpack_pdf.process_args(arg_dict)    
     try:
         unpack_pdf.Runner.setup(action)
         unpack_pdf.Runner.execute(action)
     except FileExistsError:
         assert os.path.exists(action.target_dir)
Пример #2
0
 def test_process_args(self, arg_dict):
     """
     The ``UnpackPDF`` class's ``process_args`` method should correctly
     take an input pdf, and create an action that will pass the contents
     of the pdf into a default subdirectory in the same directory as the 
     pdf file.
     """
     action = unpack_pdf.process_args(arg_dict)
     assert isinstance(action, unpack_pdf.UnpackPDF)
Пример #3
0
 def test_unpack_pdf_runner_executes_entire_process(self, arg_dict):
     action = unpack_pdf.process_args(arg_dict)
     try:
         unpack_pdf.Runner.setup(action)
         unpack_pdf.Runner.execute(action)
     except FileNotFoundError as e:
         pytest.fail()
     finally:
         unpack_pdf.Runner.cleanup(action)
Пример #4
0
 def test_process_args(self, arg_dict):
     """
     The ``UnpackPDF`` class's ``process_args`` method should correctly
     take an input pdf, and create an action that will pass the contents
     of the pdf into a default subdirectory in the same directory as the 
     pdf file.
     """
     action = unpack_pdf.process_args(arg_dict)
     assert isinstance(action, unpack_pdf.UnpackPDF)
Пример #5
0
 def test_unpack_pdf_runner_executes_entire_process(self, arg_dict):
     action = unpack_pdf.process_args(arg_dict)
     try:
         unpack_pdf.Runner.setup(action)
         unpack_pdf.Runner.execute(action)
     except FileNotFoundError as e:
         pytest.fail()
     finally:
         unpack_pdf.Runner.cleanup(action)
Пример #6
0
 def test_unpack_pdf_should_not_write_to_a_directory_with_existing_files(
         self, arg_dict):
     self.use_target_path(arg_dict, sample.TEST_TIFFS)
     action = unpack_pdf.process_args(arg_dict)
     try:
         unpack_pdf.Runner.setup(action)
         unpack_pdf.Runner.execute(action)
     except FileExistsError:
         assert os.path.exists(action.target_dir)
Пример #7
0
 def test_unpack_pdf_runner_unpacks_a_pdf_to_a_directory(self, arg_dict):
     action = unpack_pdf.process_args(arg_dict)
     try:
         unpack_pdf.Runner.setup(action)
         unpack_pdf.Runner.execute(action)
         if not os.path.isdir(arg_dict['output']):
             pytest.fail()
     except:
         pytest.fail()
     finally:
         unpack_pdf.Runner.cleanup(action)
Пример #8
0
 def test_unpack_pdf_runner_unpacks_a_pdf_to_a_directory(self, arg_dict):
     action = unpack_pdf.process_args(arg_dict)
     try:
         unpack_pdf.Runner.setup(action)
         unpack_pdf.Runner.execute(action)
         if not os.path.isdir(arg_dict['output']):
             pytest.fail()
     except:
         pytest.fail()
     finally:
         unpack_pdf.Runner.cleanup(action)
Пример #9
0
 def test_action_setup_should_reject_non_existent_output_directory(self, arg_dict):
     """
     The UnpackPDF class's ``setup`` method should fail when the 
     output directory does not exist.
     """
     self.use_source_file(
         arg_dict, os.path.join(sample.SAMPLE_ROOT, 'does_not_exist.pdf')
     )
     self.use_target_path(arg_dict, sample.SAMPLE_ROOT)
     action = unpack_pdf.process_args(arg_dict)
     with pytest.raises(FileNotFoundError):
         unpack_pdf.Runner.setup(action)
Пример #10
0
    def test_unpack_pdf_cleanup_should_remove_files_and_directory(self, arg_dict):
        """
        An UnpackPDF object's setup function should make the target directory
        if it does not exist.
        """
        action = unpack_pdf.process_args(arg_dict)
        try:
            unpack_pdf.Runner.setup(action)
        finally:
            unpack_pdf.Runner.cleanup(action)

        assert not os.path.exists(action.target_dir)
Пример #11
0
 def test_action_setup_should_reject_non_existent_output_directory(
         self, arg_dict):
     """
     The UnpackPDF class's ``setup`` method should fail when the 
     output directory does not exist.
     """
     self.use_source_file(
         arg_dict, os.path.join(sample.SAMPLE_ROOT, 'does_not_exist.pdf'))
     self.use_target_path(arg_dict, sample.SAMPLE_ROOT)
     action = unpack_pdf.process_args(arg_dict)
     with pytest.raises(FileNotFoundError):
         unpack_pdf.Runner.setup(action)
Пример #12
0
    def test_unpack_pdf_cleanup_should_remove_files_and_directory(
            self, arg_dict):
        """
        An UnpackPDF object's setup function should make the target directory
        if it does not exist.
        """
        action = unpack_pdf.process_args(arg_dict)
        try:
            unpack_pdf.Runner.setup(action)
        finally:
            unpack_pdf.Runner.cleanup(action)

        assert not os.path.exists(action.target_dir)
Пример #13
0
    def test_unpack_pdf_generates_correct_terminal_command(self, arg_dict):
        """
        An ``UnpackPDF`` object should be a valid python subprocess.
        """
        action = unpack_pdf.process_args(arg_dict)
        target_path = arg_dict['output']
        terminal_command = [
            'gs', '-q', '-dNOPAUSE', '-dBATCH', '-sDEVICE=tiff24nc',
            '-sCompression=lzw', '-r300x300',
            f'-sOutputFile={target_path}_Page_%04d.tiff', arg_dict['input']
        ]

        assert action.as_subprocess() == terminal_command
Пример #14
0
 def test_unpack_pdf_generates_correct_terminal_command(self, arg_dict):
     """
     An ``UnpackPDF`` object should be a valid python subprocess.
     """
     action = unpack_pdf.process_args(arg_dict)
     target_path = arg_dict['output']
     terminal_command = [
         'gs', '-q', '-dNOPAUSE', '-dBATCH',   '-sDEVICE=tiff24nc', 
         '-sCompression=lzw',     '-r300x300', 
         f'-sOutputFile={target_path}_Page_%04d.tiff',
         arg_dict['input']
     ]
     
     assert action.as_subprocess() == terminal_command
Пример #15
0
    def test_unpack_pdf_setup(self, arg_dict):
        """
        An UnpackPDF object's setup function should make the target directory
        if it does not exist.
        """
        action = unpack_pdf.process_args(arg_dict)
        try:
            unpack_pdf.Runner.setup(action)
            if not os.path.isdir(arg_dict['output']):
                pytest.fail()
        except:
            pytest.fail()
        finally:
            unpack_pdf.Runner.cleanup(action)

        assert action.target_dir == arg_dict['output']
Пример #16
0
    def test_unpack_pdf_setup(self, arg_dict):
        """
        An UnpackPDF object's setup function should make the target directory
        if it does not exist.
        """
        action = unpack_pdf.process_args(arg_dict)
        try:
            unpack_pdf.Runner.setup(action)
            if not os.path.isdir(arg_dict['output']):
                pytest.fail()
        except:
            pytest.fail()
        finally:
            unpack_pdf.Runner.cleanup(action)

        assert action.target_dir == arg_dict['output']