forked from COVESA/vss-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_contants.py
112 lines (96 loc) · 5.72 KB
/
test_contants.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
import unittest
from vspec.model.constants import VSSType, VSSDataType, Unit, StringStyle
class TestConstantsNode(unittest.TestCase):
def test_string_styles(self):
"""
Test correct parsing of string styles
"""
self.assertEqual(StringStyle.NONE, StringStyle.from_str("none"))
self.assertEqual(StringStyle.CAMEL_CASE, StringStyle.from_str("camelCase"))
self.assertEqual(StringStyle.CAMEL_BACK, StringStyle.from_str("camelBack"))
self.assertEqual(StringStyle.CAPITAL_CASE, StringStyle.from_str("capitalcase"))
self.assertEqual(StringStyle.CONST_CASE, StringStyle.from_str("constcase"))
self.assertEqual(StringStyle.LOWER_CASE, StringStyle.from_str("lowercase"))
self.assertEqual(StringStyle.PASCAL_CASE, StringStyle.from_str("pascalcase"))
self.assertEqual(StringStyle.SENTENCE_CASE, StringStyle.from_str("sentencecase"))
self.assertEqual(StringStyle.SNAKE_CASE, StringStyle.from_str("snakecase"))
self.assertEqual(StringStyle.TITLE_CASE, StringStyle.from_str("titlecase"))
self.assertEqual(StringStyle.TRIM_CASE, StringStyle.from_str("trimcase"))
self.assertEqual(StringStyle.UPPER_CASE, StringStyle.from_str("uppercase"))
self.assertEqual(StringStyle.ALPHANUM_CASE, StringStyle.from_str("alphanumcase"))
def test_invalid_string_styles(self):
with self.assertRaises(Exception): StringStyle.from_str("not_a_valid_case")
def test_units(self):
"""
Test correct parsing of units
"""
self.assertEqual(Unit.MILLIMETER, Unit.from_str("mm"))
self.assertEqual(Unit.CENTIMETER, Unit.from_str("cm"))
self.assertEqual(Unit.METER, Unit.from_str("m"))
self.assertEqual(Unit.KILOMETER, Unit.from_str("km"))
self.assertEqual(Unit.KILOMETERPERHOUR, Unit.from_str("km/h"))
self.assertEqual(Unit.METERSPERSECONDSQUARED, Unit.from_str("m/s^2"))
self.assertEqual(Unit.LITER, Unit.from_str("l"))
self.assertEqual(Unit.DEGREECELSIUS, Unit.from_str("celsius"))
self.assertEqual(Unit.DEGREE, Unit.from_str("degrees"))
self.assertEqual(Unit.DEGREEPERSECOND, Unit.from_str("degrees/s"))
self.assertEqual(Unit.KILOWATT, Unit.from_str("kW"))
self.assertEqual(Unit.KILOWATTHOURS, Unit.from_str("kWh"))
self.assertEqual(Unit.KILOGRAM, Unit.from_str("kg"))
self.assertEqual(Unit.VOLT, Unit.from_str("V"))
self.assertEqual(Unit.AMPERE, Unit.from_str("A"))
self.assertEqual(Unit.SECOND, Unit.from_str("s"))
self.assertEqual(Unit.MINUTE, Unit.from_str("min"))
self.assertEqual(Unit.WEEKS, Unit.from_str("weeks"))
self.assertEqual(Unit.MONTHS, Unit.from_str("months"))
self.assertEqual(Unit.YEARS, Unit.from_str("years"))
self.assertEqual(Unit.UNIXTIMESTAMP, Unit.from_str("UNIX Timestamp"))
self.assertEqual(Unit.PASCAL, Unit.from_str("Pa"))
self.assertEqual(Unit.KILOPASCAL, Unit.from_str("kPa"))
self.assertEqual(Unit.PERCENT, Unit.from_str("percent"))
self.assertEqual(Unit.CUBICCENTIMETERS, Unit.from_str("cm^3"))
self.assertEqual(Unit.HORSEPOWER, Unit.from_str("PS"))
self.assertEqual(Unit.STARS, Unit.from_str("stars"))
self.assertEqual(Unit.GRAMSPERSECOND, Unit.from_str("g/s"))
self.assertEqual(Unit.GRAMSPERKILOMETER, Unit.from_str("g/km"))
self.assertEqual(Unit.KILOWATTHOURSPER100KILOMETERS, Unit.from_str("kWh/100km"))
self.assertEqual(Unit.LITERPER100KILOMETERS, Unit.from_str("l/100km"))
self.assertEqual(Unit.LITERPERHOUR, Unit.from_str("l/h"))
self.assertEqual(Unit.MILESPERGALLON, Unit.from_str("mpg"))
self.assertEqual(Unit.POUND, Unit.from_str("lbs"))
self.assertEqual(Unit.NEWTONMETER, Unit.from_str("Nm"))
self.assertEqual(Unit.REVOLUTIONSPERMINUTE, Unit.from_str("rpm"))
self.assertEqual(Unit.INCH, Unit.from_str("inch"))
self.assertEqual(Unit.RATIO, Unit.from_str("ratio"))
def test_invalid_unit(self):
with self.assertRaises(Exception): Unit.from_str("not_a_valid_case")
def test_vss_types(self):
"""
Test correct parsing of VSS Types
"""
self.assertEqual(VSSType.BRANCH, VSSType.from_str("branch"))
self.assertEqual(VSSType.ATTRIBUTE, VSSType.from_str("attribute"))
self.assertEqual(VSSType.SENSOR, VSSType.from_str("sensor"))
self.assertEqual(VSSType.ACTUATOR, VSSType.from_str("actuator"))
def test_invalid_vss_types(self):
with self.assertRaises(Exception): VSSType.from_str("not_a_valid_case")
def test_vss_data_types(self):
"""
Test correct parsing of VSS Data Types
"""
self.assertEqual(VSSDataType.INT8, VSSDataType.from_str("int8"))
self.assertEqual(VSSDataType.UINT8, VSSDataType.from_str("uint8"))
self.assertEqual(VSSDataType.INT16, VSSDataType.from_str("int16"))
self.assertEqual(VSSDataType.UINT16, VSSDataType.from_str("uint16"))
self.assertEqual(VSSDataType.INT32, VSSDataType.from_str("int32"))
self.assertEqual(VSSDataType.UINT32, VSSDataType.from_str("uint32"))
self.assertEqual(VSSDataType.INT64, VSSDataType.from_str("int64"))
self.assertEqual(VSSDataType.UINT64, VSSDataType.from_str("uint64"))
self.assertEqual(VSSDataType.BOOLEAN, VSSDataType.from_str("boolean"))
self.assertEqual(VSSDataType.FLOAT, VSSDataType.from_str("float"))
self.assertEqual(VSSDataType.DOUBLE, VSSDataType.from_str("double"))
self.assertEqual(VSSDataType.STRING, VSSDataType.from_str("string"))
def test_invalid_vss_data_types(self):
with self.assertRaises(Exception): VSSDataType.from_str("not_a_valid_case")
if __name__ == '__main__':
unittest.main()