Skip to content

Commit eee2663

Browse files
vkreschjdsika
authored andcommitted
Added test for units (#370)
1 parent 8aff9ad commit eee2663

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

osi_sensorviewconfiguration.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ message SensorViewConfiguration
122122
// that the simulation environment has to provide.
123123
// Viewing range: [- \c #field_of_view_horizontal/2, \c
124124
// #field_of_view_horizontal/2] azimuth in the sensor frame as defined in \c
125-
// Spherical3d. Unit: rad
125+
// Spherical3d.
126+
//
127+
// Unit: rad
126128
optional double field_of_view_horizontal = 5;
127129

128130
// Field of View in vertical orientation of the sensor.

tests/test_units.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import re
2+
import glob
3+
import unittest
4+
5+
PROTO_FILES = glob.glob("*.proto")
6+
7+
class TestUnits(unittest.TestCase):
8+
""" Test class for units documentation. """
9+
10+
def test_no_brackets(self):
11+
''' Test to check if units have the right syntax. '''
12+
13+
NOT_VALID_BRACKETS = [r'\(', r'\)', r'\[', r'\]', r'\{', r'\}']
14+
15+
for file in PROTO_FILES:
16+
with open(file, "rt") as fin, self.subTest(file=file):
17+
for i, line in enumerate(fin, start=1):
18+
found = re.search('Unit:', line, re.IGNORECASE)
19+
20+
if found:
21+
comment_list = line.split()
22+
self.assertEqual(comment_list[0], '//', file + " in line " + str(i) + ": Unit must be on a separate line or have a space between //. (Example: '// Unit: m')")
23+
self.assertEqual(comment_list[1], 'Unit:', file + " in line " + str(i) + f": '{comment_list[1]}' do not match 'Unit:'. (Example: '// Unit: m')")
24+
self.assertGreaterEqual(len(comment_list), 3, file + " in line " + str(i) + ": No unit defined. (Example: '// Unit: m')")
25+
26+
for unit in comment_list:
27+
for brackets in NOT_VALID_BRACKETS:
28+
self.assertNotRegex(unit, brackets, file + " in line " + str(i) + ": Invalid brackets around units.")

0 commit comments

Comments
 (0)