Beispiel #1
0
    def test_constructValidTrafficReading_subclassInvalidForClass_constructReadingWithInvalidDataValidationLevel(
            self):

        test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-3-4"]
        result = constructValidatedTrafficReading(
            test_data, STATION_A_ROAD_POSITION_STRING,
            TEST_VALIDATION_DATE_TIMESTAMP)

        self.assertEqual(result.rawSourceData,
                         "2020-05-25,17:34:12,35.87,L-Right,class-3-4")
        self.assertEqual(result.validationLevel, ValidationLevel.INVALID_DATA)

        #As the data has a valid format, it should still be populated, even if its value is invalid.
        self.assertEqual(result.vehicleClass, VehicleClass(main=3, sub=4))
Beispiel #2
0
    def test_constructValidatedTrafficReading_allDataValid_constructCorrectReadingWithFullValidationLevel(
            self):

        test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-2-1"]
        result = constructValidatedTrafficReading(
            test_data, STATION_A_ROAD_POSITION_STRING,
            TEST_VALIDATION_DATE_TIMESTAMP)

        self.assertEqual(result.rawSourceData,
                         "2020-05-25,17:34:12,35.87,L-Right,class-2-1")
        self.assertEqual(result.validationLevel, ValidationLevel.FULL)

        self.assertEqual(
            result.dateTime,
            datetime.strptime("2020-05-25 17:34:12", "%Y-%m-%d %H:%M:%S"))
        self.assertEqual(result.speed, 35.87)
        self.assertEqual(result.directionLeftToRight, True)
        self.assertEqual(result.vehicleClass, VehicleClass(main=2, sub=1))
        self.assertEqual(result.sourceRoadPosition, STATION_A_ROAD_POSITION)
Beispiel #3
0
    def test_constructValidTrafficReading_invalidTimeFormat_constructReadingWithInvalidFormatValidationLevel(
            self):

        test_data = ["2020-05-25", "17:34:70", "35.87", "L-Right", "class-2-1"]
        result = constructValidatedTrafficReading(
            test_data, STATION_A_ROAD_POSITION_STRING,
            TEST_VALIDATION_DATE_TIMESTAMP)

        self.assertEqual(result.rawSourceData,
                         "2020-05-25,17:34:70,35.87,L-Right,class-2-1")
        self.assertEqual(result.validationLevel,
                         ValidationLevel.INVALID_FORMAT)

        self.assertIsNone(result.dateTime)

        #The other, valid, fields should still be populated.
        self.assertEqual(result.speed, 35.87)
        self.assertEqual(result.directionLeftToRight, True)
        self.assertEqual(result.vehicleClass, VehicleClass(main=2, sub=1))
        self.assertEqual(result.sourceRoadPosition, STATION_A_ROAD_POSITION)
Beispiel #4
0
    def test_constructValidTrafficReading_invalidSourceRoadPosition_constructReadingWithInvalidFormatValidationLevel(
            self):

        test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-2-1"]
        result = constructValidatedTrafficReading(
            test_data, "completely and utterly invalid",
            TEST_VALIDATION_DATE_TIMESTAMP)

        self.assertEqual(result.rawSourceData,
                         "2020-05-25,17:34:12,35.87,L-Right,class-2-1")
        self.assertEqual(result.validationLevel,
                         ValidationLevel.INVALID_FORMAT)

        self.assertIsNone(result.sourceRoadPosition)

        #The other, valid, fields should still be populated.
        self.assertEqual(
            result.dateTime,
            datetime.strptime("2020-05-25 17:34:12", "%Y-%m-%d %H:%M:%S"))
        self.assertEqual(result.speed, 35.87)
        self.assertEqual(result.directionLeftToRight, True)
        self.assertEqual(result.vehicleClass, VehicleClass(main=2, sub=1))