forked from larandvit/ebcdic-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_system_311_calls_for_service_requests_all_strings.py
107 lines (84 loc) · 6.02 KB
/
test_system_311_calls_for_service_requests_all_strings.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
import os
import os.path as path
import subprocess
import unittest
import test_system_common as common
APPARGUMENT_INPUTFILE_SAMPLE_VALUE = r'test_data\311_calls_for_service_requests_all_strings\311_calls_for_service_requests_sample.dat'
APPARGUMENT_INPUTFILE_FULL_VALUE = r'test_data\311_calls_for_service_requests_all_strings\311_calls_for_service_requests.dat'
APPARGUMENT_OUTPUTFOLDER_VALUE =r'test_data\311_calls_for_service_requests_all_strings\output'
APPARGUMENT_LAYPOUTFILE_VALUE =r'layout_repository\311_calls_for_service_requests_all_strings.json'
APPARGUMENT_LOGFOLDER_VALUE =r'test_data\311_calls_for_service_requests_all_strings\log'
VALIDATION_SAMPLE_FOLDER_VALUE = r'test_data\311_calls_for_service_requests_all_strings\validate'
PERFORMANCE_LOGFILE_VALUE =r'test_data\311_calls_for_service_requests_all_strings\performance_log\ebcdic_converter_performance.log'
DATA_SEGMENTS = ["main"]
class TestEbcdicConverter(unittest.TestCase):
@classmethod
def setUpClass(self):
print("\n\nPreparing data... 311 calls for service requests all strings")
codePath = path.dirname(__file__)
self.testEnvironment = common.Setup.getSetupEnvironmentDesctiption(codePath)
self.testType = common.Setup.getSetupTestType(codePath)
inputFile = APPARGUMENT_INPUTFILE_SAMPLE_VALUE
if self.testType==common.TestType.Performance:
inputFile = APPARGUMENT_INPUTFILE_FULL_VALUE
self.appArguments = common.AppArguments(codePath)
self.appArguments.addArgumentValue(self.appArguments.APPARGUMENT_INPUTFILE, inputFile)
self.appArguments.addArgumentValue(self.appArguments.APPARGUMENT_OUTPUTFOLDER, APPARGUMENT_OUTPUTFOLDER_VALUE)
self.appArguments.addArgumentValue(self.appArguments.APPARGUMENT_LAYPOUTFILE, APPARGUMENT_LAYPOUTFILE_VALUE)
self.appArguments.addArgumentValue(self.appArguments.APPARGUMENT_LOGFOLDER, APPARGUMENT_LOGFOLDER_VALUE)
self.appArguments.addArgumentValue(self.appArguments.VALIDATION_SAMPLE_FOLDER, VALIDATION_SAMPLE_FOLDER_VALUE)
self.appArguments.addArgumentValue(self.appArguments.PERFORMANCE_LOGFILE, PERFORMANCE_LOGFILE_VALUE)
#create folder structure
folders = [self.appArguments.APPARGUMENT_OUTPUTFOLDER, self.appArguments.APPARGUMENT_LOGFOLDER, self.appArguments.VALIDATION_SAMPLE_FOLDER, self.appArguments.PERFORMANCE_LOGFILE]
for folderKey in folders:
folderPath = self.appArguments.getArgumentValue(folderKey)
if folderKey==self.appArguments.PERFORMANCE_LOGFILE:
folderPath = path.dirname(folderPath)
if not path.exists(folderPath):
os.mkdir(folderPath)
#delete any already existing output converted files
for segmentName in DATA_SEGMENTS:
filePath = self.appArguments.getOutputFilePath(segmentName)
if path.exists(filePath):
os.remove(filePath)
self.runStats = common.RunStats()
self.runStats.storeCompletedProcess(subprocess.run(args=["python.exe", self.appArguments.getAppArgument(),
self.appArguments.getArgument(self.appArguments.APPARGUMENT_INPUTFILE),
self.appArguments.getArgument(self.appArguments.APPARGUMENT_OUTPUTFOLDER),
self.appArguments.getArgument(self.appArguments.APPARGUMENT_LAYPOUTFILE),
self.appArguments.getArgument(self.appArguments.APPARGUMENT_LOGFOLDER)
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT))
print(self.runStats.getOutput())
if self.testType==common.TestType.Performance:
print()
print("-----------No tests completed. Just reporting performance-----------")
def tearDown(self):
# release resources
pass
@classmethod
def tearDownClass(self):
#store performance info
#write in performance log if no run-time error
self.runStats.savePerformanceLog(self.appArguments, self.testEnvironment)
@unittest.skipIf(common.Setup.getSetupTestType(path.dirname(__file__))==common.TestType.Performance, "Don't run to get performance")
def test_01_ReturnCode(self):
self.assertEqual(self.runStats.getReturnCode(), 0, "Converter returns other than 0 return code")
@unittest.skipIf(common.Setup.getSetupTestType(path.dirname(__file__))==common.TestType.Performance, "Don't run to get performance")
def test_02_NumberRecords(self):
segmentRecordCount = {"main":1000}
for segmentName in DATA_SEGMENTS:
self.assertEqual(self.runStats.getNumberRecords(segmentName), segmentRecordCount[segmentName], "Wrong number of converted records")
@unittest.skipIf(common.Setup.getSetupTestType(path.dirname(__file__))==common.TestType.Performance, "Don't run to get performance")
def test_03_CompareContent(self):
for segmentName in DATA_SEGMENTS:
lineNumber = 0
with open(self.appArguments.getOutputFilePath(segmentName), 'r', encoding="utf-8") as convertedFile:
with open(self.appArguments.getValidationSampleFilePath(segmentName), 'r', encoding="utf-8") as validationSampleFile:
for convertedLine in convertedFile:
validationLine = validationSampleFile.readline()
lineNumber += 1
self.assertEqual(convertedLine, validationLine, "Content doesn't match in line: " + str(lineNumber))
if __name__=="__main__":
unittest.main()