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_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. 3
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/invoice2data/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. 4
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("invoice2data/test/temp_test/")
     os.makedirs(directory)
     shutil.copy('invoice2data/extract/templates/com/com.oyo.invoice.yml',
                 'invoice2data/test/temp_test/')
     args = self.parser.parse_args([
         '--exclude-built-in-templates', '--template-folder', directory,
         my_file
     ])
     main(args)
     shutil.rmtree('invoice2data/test/temp_test/')
Esempio n. 5
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. 6
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. 7
0
 def test_output_format_date_xml(self):
     pdf_files = get_sample_files('free_fiber.pdf')
     test_file = 'test_compare.xml'
     for pfile in pdf_files:
         args = self.parser.parse_args([
             '--output-name', test_file, '--output-format', 'xml',
             '--output-date-format', '%d/%m/%Y', pfile
         ])
         main(args)
         with open(test_file) as xml_test_file:
             xmldatatest = minidom.parse(xml_test_file)
         dates = xmldatatest.getElementsByTagName('date')
         compare_verified = (dates[0].firstChild.data == '02/07/2015')
         print(compare_verified)
         if not compare_verified:
             self.assertTrue(False, 'Unexpected date format')
         os.remove(test_file)
Esempio n. 8
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. 9
0
 def test_output_format_date_json(self):
     pdf_files = get_sample_files('free_fiber.pdf')
     test_file = 'test_compare.json'
     for pfile in pdf_files:
         args = self.parser.parse_args([
             '--output-name', test_file, '--output-format', 'json',
             '--output-date-format', "%d/%m/%Y", pfile
         ])
         main(args)
         with open(test_file) as json_test_file:
             jdatatest = json.load(json_test_file)
         compare_verified = (jdatatest[0]['date']
                             == '02/07/2015') and (jdatatest[0]['date_due']
                                                   == '05/07/2015')
         print(compare_verified)
         if not compare_verified:
             self.assertTrue(False, 'Unexpected date format')
         os.remove(test_file)
Esempio n. 10
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. 11
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. 12
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. 13
0
 def test_output_format_date_csv(self):
     pdf_files = get_sample_files('free_fiber.pdf')
     test_file = 'test_compare.csv'
     for pfile in pdf_files:
         args = self.parser.parse_args([
             '--output-name', test_file, '--output-format', 'csv',
             '--output-date-format', '%d/%m/%Y', pfile
         ])
         main(args)
         with open(test_file) as csv_test_file:
             csvdatatest = csv.DictReader(csv_test_file, delimiter=',')
             for row in csvdatatest:
                 compare_verified = (row['date']
                                     == '02/07/2015') and (row['date_due']
                                                           == '05/07/2015')
                 print(compare_verified)
                 if not compare_verified:
                     self.assertTrue(False, 'Unexpected date format')
         os.remove(test_file)
Esempio n. 14
0
    def __init__(self, popfield, excludeDefaultFolder, templateFolder,
                 fieldDict, gui, factx):
        self.parser = create_parser()
        self.fieldValueDict = fieldDict
        self.gui = gui
        self.factx = factx
        self.popfield = popfield
        self.outputFile = '.load/invoice2data_output.json'
        self.parseList = [
            '--output-format', 'json', '--output-name', self.outputFile,
            '--exclude-built-in-templates', '--template-folder',
            templateFolder, self.gui.fileName[0]
        ]
        if not excludeDefaultFolder:
            self.parseList.remove('--exclude-built-in-templates')
        if templateFolder is None:
            self.parseList.remove('--template-folder')
            self.parseList.remove(templateFolder)

        main(self.parser.parse_args(self.parseList))

        self.set_values()
Esempio n. 15
0
 def test_input(self):
     args = self.parser.parse_args(['--input-reader', 'pdftotext'] + get_sample_files('.pdf'))
     main(args)
Esempio n. 16
0
 def test_debug(self):
     args = self.parser.parse_args(['--debug'] + get_sample_files('.pdf'))
     main(args)
Esempio n. 17
0
 def test_debug(self):
     args = self.parser.parse_args(['--debug'] + get_sample_files('.pdf'))
     main(args)
Esempio n. 18
0
 def test_input(self):
     args = self.parser.parse_args(['--input-reader', 'pdftotext'] +
                                   get_sample_files('.pdf'))
     main(args)