Esempio n. 1
0
 def test_output_name(self):
     test_file = 'inv_test_8asd89f78a9df.csv'
     args = self.parser.parse_args(
         ['--output-name', test_file, '--output-format', 'csv'] + get_sample_files('.pdf')
     )
     main(args)
     self.assertTrue(os.path.exists(test_file))
     os.remove(test_file)
Esempio n. 2
0
 def test_exclude_template(self):
     for path, subdirs, files in os.walk(pkg_resources.resource_filename(__name__, 'compare')):
         for file in files:
             if file.endswith("oyo.pdf"):
                 my_file = os.path.join(path, file)
     directory = os.path.dirname("tests/temp_test/")
     os.makedirs(directory)
     shutil.copy(
         'src/ninvoice2data/extract/templates/com/com.oyo.invoice.yml', 'tests/temp_test/'
     )
     args = self.parser.parse_args(
         ['--exclude-built-in-templates', '--template-folder', directory, my_file]
     )
     main(args)
     shutil.rmtree('tests/temp_test/')
Esempio n. 3
0
 def test_content_json(self):
     pdf_files = get_sample_files('.pdf')
     json_files = get_sample_files('.json')
     test_files = 'test_compare.json'
     for pfile in pdf_files:
         for jfile in json_files:
             if pfile[:-4] == jfile[:-5]:
                 args = self.parser.parse_args(
                     ['--output-name', test_files, '--output-format', 'json', pfile]
                 )
                 main(args)
                 compare_verified = self.compare_json_content(test_files, jfile)
                 print(compare_verified)
                 if not compare_verified:
                     self.assertTrue(False)
                 os.remove(test_files)
Esempio n. 4
0
    def test_copy_with_default_filename_format(self):
        copy_dir = os.path.join('tests', 'copy_test', 'pdf')
        filename_format = "{date} {invoice_number} {desc}.pdf"

        data = self.get_filename_format_test_data(filename_format)

        os.makedirs(copy_dir)

        sample_files = [v['input_fpath'] for k, v in data.items()]

        args = self.parser.parse_args(['--copy', copy_dir] + sample_files)
        main(args)

        self.assertTrue(
            all(os.path.exists(os.path.join(copy_dir, v['output_fname'])) for k, v in data.items())
        )

        shutil.rmtree(os.path.dirname(copy_dir), ignore_errors=True)
Esempio n. 5
0
    def test_copy(self):
        # folder = pkg_resources.resource_filename(__name__, 'pdfs')
        directory = os.path.dirname("tests/copy_test/pdf/")
        os.makedirs(directory)
        args = self.parser.parse_args(
            ['--copy', 'tests/copy_test/pdf'] + get_sample_files('.pdf')
        )
        main(args)
        i = 0
        for path, subdirs, files in os.walk(
            pkg_resources.resource_filename(__name__, 'copy_test/pdf')
        ):
            for file in files:
                if file.endswith(".pdf"):
                    i += 1

        shutil.rmtree('tests/copy_test/', ignore_errors=True)
        self.assertEqual(i, len(get_sample_files('.json')))
        '''
Esempio n. 6
0
 def test_debug(self):
     args = self.parser.parse_args(['--debug'] + get_sample_files('.pdf'))
     main(args)
Esempio n. 7
0
 def test_input(self):
     args = self.parser.parse_args(['--input-reader', 'pdftotext'] + get_sample_files('.pdf'))
     main(args)