示例#1
0
    def test_constructValidTrafficReading_directionRLeft_directionLeftToRightFalse(
            self):

        test_data = ["2020-05-25", "17:34:12", "35.87", "R-Left", "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,R-Left,class-2-1")
        self.assertEqual(result.validationLevel, ValidationLevel.FULL)

        self.assertEqual(result.directionLeftToRight, False)
示例#2
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))
示例#3
0
    def test_constructValidTrafficReading_stationNotInDatabase_constructReadingWithInvalidDataValidationLevel(
            self):

        test_data = ["2020-05-25", "17:34:12", "35.87", "L-Right", "class-2-1"]
        result = constructValidatedTrafficReading(
            test_data, STATION_C_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.INVALID_DATA)

        #As the data has a valid format, it should still be populated, even if its value is invalid.
        self.assertEqual(result.sourceRoadPosition, STATION_C_ROAD_POSITION)
示例#4
0
    def test_constructValidTrafficReading_roadPositionHasNoSideSuffix_dataStillValid(
            self):

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

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

        self.assertEqual(result.sourceRoadPosition, STATION_B_ROAD_POSITION)
示例#5
0
    def test_constructValidTrafficReading_speedIsNaN_constructReadingWithInvalidDataValidationLevel(
            self):

        test_data = ["2020-05-25", "17:34:12", "NaN", "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,NaN,L-Right,class-2-1")
        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.assertTrue(
            math.isnan(result.speed),
            "result.speed should be nan, but is " + str(result.speed) + ".")
示例#6
0
    def test_constructValidTrafficReading_dateAfterValidationDate_constructReadingWithInvalidDataValidationLevel(
            self):

        test_data = ["2020-11-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-11-25,17:34:12,35.87,L-Right,class-2-1")
        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.dateTime,
            datetime.strptime("2020-11-25 17:34:12", "%Y-%m-%d %H:%M:%S"))
示例#7
0
    def test_constructValidTrafficReading_speedExceedsMax_constructReadingWithInvalidDataValidationLevel(
            self):

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

        self.assertEqual(result.rawSourceData,
                         "2020-05-25,17:34:12,229.17,L-Right,class-2-1")
        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.speed, 229.17)
示例#8
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)
示例#9
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)
示例#10
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))