-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
78 lines (59 loc) · 3.14 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Unit tests for PDF OCR Inspector."""
# imports
import inspector
import os
import pandas as pd
import unittest
# Classes
class TestInspectorParser(unittest.TestCase):
def setUp(self) -> None:
self.script_name = 'Roger'
self.script_version = '0.42'
self.parser = inspector.InspectorParser(self.script_name, self.script_version)
def test_parser_instance(self):
self.assertIsInstance(self.parser, inspector.InspectorParser)
self.assertIsInstance(self.parser.script_name, str)
self.assertIsInstance(self.parser.script_version, str)
self.assertEqual(self.parser.script_name, self.script_name)
self.assertEqual(self.parser.script_version, self.script_version)
# TODO: create tests for set_logger function and update_file_metrics method.
class TestPDFFileList(unittest.TestCase):
def setUp(self) -> None:
self.test_dir = os.path.join(os.getcwd(), 'test_dir')
self.pdf_file_list = inspector.PDFFileList(self.test_dir)
def tearDown(self) -> None:
self.pdf_file_list = None
def test_file_list_instance(self):
self.assertIsInstance(self.pdf_file_list, inspector.PDFFileList)
self.assertIsInstance(self.pdf_file_list.file_names, list)
self.assertIsInstance(self.pdf_file_list.total_characters, list)
self.assertIsInstance(self.pdf_file_list.total_bad_characters, list)
self.assertIsInstance(self.pdf_file_list.percentage_bad_characters, list)
self.assertIsInstance(self.pdf_file_list.directory, str)
self.assertIsInstance(self.pdf_file_list.verbose, bool)
def test_file_names(self):
self.assertEqual(len(self.pdf_file_list.file_names), 3)
self.assertIn(os.path.join(self.test_dir, 'one.pdf'), self.pdf_file_list.file_names)
self.assertIn(os.path.join(self.test_dir, 'two.pdf'), self.pdf_file_list.file_names)
self.assertIn(os.path.join(self.test_dir, 'three.pdf'), self.pdf_file_list.file_names)
self.assertNotIn(os.path.join(self.test_dir, 'one.txt'), self.pdf_file_list.file_names)
self.assertNotIn(os.path.join(self.test_dir, 'two.txt'), self.pdf_file_list.file_names)
self.assertNotIn(os.path.join(self.test_dir, 'three.txt'), self.pdf_file_list.file_names)
self.assertNotIn(os.path.join(self.test_dir, 'bad_files.txt'), self.pdf_file_list.file_names)
def test_scan_files(self):
self.pdf_file_list.scan_files()
self.assertEqual(len(self.pdf_file_list.file_names), 3)
self.assertEqual(len(self.pdf_file_list.total_characters), 3)
self.assertEqual(len(self.pdf_file_list.total_bad_characters), 3)
self.assertEqual(len(self.pdf_file_list.percentage_bad_characters), 3)
def test_generate_dataframe(self):
self.pdf_file_list.scan_files()
self.assertIsInstance(self.pdf_file_list.generate_dataframe(), pd.DataFrame)
class TestScriptFunctions(unittest.TestCase):
def setUp(self) -> None:
self.path = os.path.join(os.getcwd(), 'test_dir')
def test_get_path(self):
path = inspector.get_path(self.path)
self.assertTrue(os.path.isdir(path))
if __name__ == '__main__':
unittest.main()