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)
def test_content_json(self): for path, subdirs, files in os.walk( pkg_resources.resource_filename(__name__, 'compare')): for file in files: if file.endswith(".json"): cmp_file = os.path.join(path, file) test_files = 'inv_test.json' args = self.parser.parse_args( ['--output-name', test_files, '--output-format', 'json'] + self._get_test_file_path()) main(args) # self.assertTrue(filecmp.cmp(test_files, cmp_file, shallow=False)) os.remove(test_files)
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/')
def test_copy(self): # folder = pkg_resources.resource_filename(__name__, 'pdfs') directory = os.path.dirname("invoice2data/test/copy_test/pdf/") os.makedirs(directory) args = self.parser.parse_args(['--copy', 'invoice2data/test/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('invoice2data/test/copy_test/', ignore_errors=True) self.assertEqual(i, len(get_sample_files('.json'))) '''
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)
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()
def test_debug(self): args = self.parser.parse_args(['--debug'] + self._get_test_file_path()) main(args)
def test_input(self): args = self.parser.parse_args(['--input-reader', 'pdftotext'] + self._get_test_file_path()) main(args)
def test_debug(self): args = self.parser.parse_args(['--debug'] + get_sample_files('.pdf')) main(args)
def test_input(self): args = self.parser.parse_args(['--input-reader', 'pdftotext'] + get_sample_files('.pdf')) main(args)