forked from fmoessbauer/drace
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathReportConverterUnitTest.py
108 lines (89 loc) · 3.28 KB
/
ReportConverterUnitTest.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
#
# DRace-GUI: A graphical report generator for DRace
#
# Copyright 2019 Siemens AG
#
# Authors:
# <Philip Harr> <[email protected]>
#
# SPDX-License-Identifier: MIT
#
## \package draceGUIUnitTest
## \brief Unit tests for draceGUI
import unittest
import pathlib
import ReportConverter as gui
SCRIPTPATH = pathlib.Path(pathlib.Path(__file__).resolve().parents[0])
STRREPORTPATH = SCRIPTPATH / 'test_files/output/index.html'
class TestMethods(unittest.TestCase):
def testFilesAvaliable(self):
paths = list()
paths.append(pathlib.Path(STRREPORTPATH))
paths.append(SCRIPTPATH / 'test_files/output/legend.png')
paths.append(SCRIPTPATH / 'test_files/output/js/jquery.min.js')
paths.append(SCRIPTPATH / 'test_files/output/js/prism.js')
paths.append(SCRIPTPATH / 'test_files/output/js/materialize.min.js')
paths.append(SCRIPTPATH / 'test_files/output/css/style.css')
paths.append(SCRIPTPATH / 'test_files/output/css/prism.css')
paths.append(SCRIPTPATH / 'test_files/output/css/materialize.min.css')
try:
import matplotlib
paths.append(SCRIPTPATH / 'test_files/output/topStackBarchart.png')
paths.append(SCRIPTPATH / 'test_files/output/errorTimes.png')
except ImportError:
pass
flag = 0
for element in paths:
if not element.is_file():
print(str(element) + ' is not available')
flag = 1
self.assertEqual(flag, 0)
#checj if determine language works
def testDetermineLanguage(self):
languageMap = {
'test.h': 'cpp',
'test.cpp':'cpp',
'test.c':'c',
'test.cs':'csharp',
'test.css':'css',
'test.html':'markup',
'test.js':'javascript',
'test':'cpp'
}
testObject = gui.SourceCodeManagement()
for key, value in languageMap.items():
self.assertEqual(value, testObject.determineLanguage(key))
# check if all placeholders were removed
def testPlaceholdersGone(self):
plcPath = SCRIPTPATH / 'test_files/placeholders.txt'
with open(str(plcPath), 'r') as placeholderFile:
allLines = placeholderFile.readlines()
#retrieve all placeholders
lines = list()
start = False
for line in allLines:
line = line.replace('\n','')
line = line.replace(' ', '')
if start and line != '':
if line[0]=='*':
lines.append(line)
if line == 'Placeholders:':
start = True
with open(str(STRREPORTPATH), 'r') as html:
strReport = html.read()
for tag in lines:
if tag in strReport:
self.fail()
self.assertEqual(1,1)
def testSymbolCorrection(self):
testStr = '&<>&"\\&`'
if gui.adjText(testStr) == '&<>&"/&'':
self.assertEqual(1,1)
else:
self.fail()
def testCodeReturn(self):
path = pathlib.Path(SCRIPTPATH / 'ReportConverter.py')
scm = gui.SourceCodeManagement()._returnCode(path, justExistance=1)
self.assertEqual(0, scm)
if __name__ == '__main__':
unittest.main()