From 7ae8445b43e3426f24aeef29960271abd644b8df Mon Sep 17 00:00:00 2001 From: vkresch Date: Fri, 17 Jan 2020 10:52:02 +0100 Subject: [PATCH] Added test for units --- osi_sensorviewconfiguration.proto | 4 +++- tests/test_units.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/test_units.py diff --git a/osi_sensorviewconfiguration.proto b/osi_sensorviewconfiguration.proto index 04e62d9f5..dda00adec 100644 --- a/osi_sensorviewconfiguration.proto +++ b/osi_sensorviewconfiguration.proto @@ -122,7 +122,9 @@ message SensorViewConfiguration // that the simulation environment has to provide. // Viewing range: [- \c #field_of_view_horizontal/2, \c // #field_of_view_horizontal/2] azimuth in the sensor frame as defined in \c - // Spherical3d. Unit: rad + // Spherical3d. + // + // Unit: rad optional double field_of_view_horizontal = 5; // Field of View in vertical orientation of the sensor. diff --git a/tests/test_units.py b/tests/test_units.py new file mode 100644 index 000000000..2bcd4ac9d --- /dev/null +++ b/tests/test_units.py @@ -0,0 +1,28 @@ +import re +import glob +import unittest + +PROTO_FILES = glob.glob("*.proto") + +class TestUnits(unittest.TestCase): + """ Test class for units documentation. """ + + def test_no_brackets(self): + ''' Test to check if units have the right syntax. ''' + + NOT_VALID_BRACKETS = [r'\(', r'\)', r'\[', r'\]', r'\{', r'\}'] + + for file in PROTO_FILES: + with open(file, "rt") as fin, self.subTest(file=file): + for i, line in enumerate(fin, start=1): + found = re.search('Unit:', line, re.IGNORECASE) + + if found: + comment_list = line.split() + 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')") + self.assertEqual(comment_list[1], 'Unit:', file + " in line " + str(i) + f": '{comment_list[1]}' do not match 'Unit:'. (Example: '// Unit: m')") + self.assertGreaterEqual(len(comment_list), 3, file + " in line " + str(i) + ": No unit defined. (Example: '// Unit: m')") + + for unit in comment_list: + for brackets in NOT_VALID_BRACKETS: + self.assertNotRegex(unit, brackets, file + " in line " + str(i) + ": Invalid brackets around units.")