-
Notifications
You must be signed in to change notification settings - Fork 3
/
split_test.py
126 lines (103 loc) · 3.1 KB
/
split_test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
# encoding: utf-8
import os
import pytest
from tool import Tool
INPUT_FILE_NULL = None
INPUT_FILE_INVALID = 'invalid.pdf'
INPUT_FILE_VALID = 'sample.pdf'
FILE_IMAGE_PNG = 'sample.png'
FOLDERS = [
'C:/dms/reports/',
'C:/dms/notes/',
]
DIRECTORIES_COUNT = len(FOLDERS)
PAGES_COUNT = 6
FILES_COUNT = 4
def test_wand_pdf_to_png():
from wand.image import Image
with open(FILE_IMAGE_PNG, 'wb') as out:
with Image(filename=INPUT_FILE_VALID, resolution=300) as img:
img.compression_quality = 100
img.format = 'png'
img.save(file=out)
with open(FILE_IMAGE_PNG, 'rb') as test:
assert test.read()
# 1. Input
def test_empty_input_file():
#
# 1. Assert exception if input.file == null or empty
#
with pytest.raises(ValueError, match=r'Source is not set'):
tool = Tool()
def test_null_input_file():
#
# 1. Assert exception if input.file == null or empty
#
with pytest.raises(ValueError, match=r'Source is not set'):
tool = Tool(INPUT_FILE_NULL)
def test_not_PDF_input_file():
#
# 2. Assert exception if input.file != filetype pdf
#
with pytest.raises(ValueError, match=r'Is not PDF .*'):
tool = Tool(INPUT_FILE_INVALID)
def test_PDF_input_file():
#
# 2. Assert exception if input.file == filetype pdf
#
tool = Tool(INPUT_FILE_VALID)
assert tool
def test_input_file_page_count():
#
# 3. Assert exception if input.pdf.page.size != 6
#
tool = Tool(INPUT_FILE_VALID)
assert tool.pages_count == PAGES_COUNT
assert len(tool.pages) == PAGES_COUNT
def test_input_file_qrcodes_count():
#
# 4. Assert exception if input.file.qrcode.count < 1
#
tool = Tool(INPUT_FILE_VALID)
assert len(tool.qrcodes)
def test_input_file_each_qrcode_is_valid_path():
#
# 5. Assert exception for each if input.file.qrcode != file path format
#
tool = Tool(INPUT_FILE_VALID)
for qrcode in tool.qrcodes:
assert qrcode in FOLDERS
# # 2. Output
def test_each_output_directories_fullpath_is_one_of_input_qrcode_value():
#
# 1. Assert for each output.directories.fullpath is one of input.qrcode.value[]
#
tool = Tool(INPUT_FILE_VALID)
for each in tool.files:
assert each.folder in FOLDERS
def test_output_directories_count():
#
# 2. Assert output.directories.count == 3
#
directories = []
tool = Tool(INPUT_FILE_VALID)
for each in tool.files:
if each.folder not in directories:
directories.append(each.folder)
assert len(directories) == DIRECTORIES_COUNT
def test_output_files_count():
#
# 3. Assert output.files.count == 4
#
directories = []
tool = Tool(INPUT_FILE_VALID)
assert len(tool.files) == FILES_COUNT
def test_output_files_name():
#
# 4. Assert each output.file.name == input.file.name+_+uuid
#
input_file_name = INPUT_FILE_VALID.split('.').pop(0)
tool = Tool(INPUT_FILE_VALID)
for each in tool.files:
assert (each.file_name == '{}_{}.pdf'.format(input_file_name, each.uuid))