def tst_invalid_domain(self):
     print("Testing invalid domain")
     dictionaryBad, unused = self.gen_dictionary_and_trajectory(
         "terrestrial")
     dictionaryBad['domain'] = "invalid"
     with self.assertRaises(ValueError) as ctx:
         trajectory_from_dictionary(dictionaryBad)
 def tst_invalid_object_id(self):
     print("Testing invalid object_id")
     dictionaryBad, unused = self.gen_dictionary_and_trajectory(
         "terrestrial")
     dictionaryBad['object_id'] = 2
     with self.assertRaises(ValueError) as ctx:
         trajectory_from_dictionary(dictionaryBad)
Exemple #3
0
def trajectory_from_json(json_string):
    """Returns a trajectory constructed from the given json string.
    Args:
       json: the json to convert into a trajectory
    """
    if sys.version_info[0] < 3:
        return trajectory_from_dictionary(json_loads_byteified(json_string))
    else:
        return trajectory_from_dictionary(json.loads(json_string))
    def tst_trajectory_from_invalid_timestamps(self, domain):
        print("Testing the conversion of a dictionary with invalid timestamps in the "+domain, " domain.")
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        #test a timestamp list that doesn't match length of coordinates by removing last timestamp
        dictionaryBad3 = dictionary.copy()
        dictionaryBad3['timestamps'] = dictionaryBad3['timestamps'][:-1]
        with self.assertRaises(ValueError) as ctx:
            trajectory_from_dictionary(dictionaryBad3)
    def tst_trajectory_from_invalid_point_properties(self, domain):
        print("Testing the conversion of a dictionary with invalid point properties in the "+domain+" domain.")
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        #test point properties lists don't match length of coordinates by removing last element of the altitude list
        dictionaryBad2 = dictionary.copy()
        dictionaryBad2['point_properties']['altitude']['values'] = dictionaryBad2['point_properties']['altitude']['values'][:-1]
        with self.assertRaises(ValueError) as ctx:
            trajectory_from_dictionary(dictionaryBad2)
    def tst_trajectory_from_invalid_coordinates(self, domain):
        print("Testing the conversion of a dictionary with invalid coordinates in the "+domain+" domain.")
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        #test coordinates don't match in length
        dictionaryBad1 = dictionary.copy()

        dictionaryBad1['coordinates'][0] = dictionaryBad1['coordinates'][0][:-1] #remove last element of coordinate 0
        with self.assertRaises(ValueError) as ctx:
            trajectory_from_dictionary(dictionaryBad1)
    def tst_trajectory_from_invalid_timestamps(self, domain):
        print(
            "Testing the conversion of a dictionary with invalid timestamps in the {} domain."
            .format(domain))
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        #test a timestamp list that doesn't match length of coordinates by removing last timestamp
        dictionaryBad3 = dictionary.copy()
        dictionaryBad3['timestamps'] = dictionaryBad3['timestamps'][:-1]
        with self.assertRaises(ValueError) as ctx:
            trajectory_from_dictionary(dictionaryBad3)
    def tst_trajectory_from_invalid_point_properties(self, domain):
        print(
            "Testing the conversion of a dictionary with invalid point properties in the "
            + domain + " domain.")
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        #test point properties lists don't match length of coordinates by removing last element of the altitude list
        dictionaryBad2 = dictionary.copy()
        dictionaryBad2['point_properties']['altitude'][
            'values'] = dictionaryBad2['point_properties']['altitude'][
                'values'][:-1]
        with self.assertRaises(ValueError) as ctx:
            trajectory_from_dictionary(dictionaryBad2)
    def tst_trajectory_from_invalid_coordinates(self, domain):
        print(
            "Testing the conversion of a dictionary with invalid coordinates in the "
            + domain + " domain.")
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        #test coordinates don't match in length
        dictionaryBad1 = dictionary.copy()

        dictionaryBad1['coordinates'][0] = dictionaryBad1['coordinates'][
            0][:-1]  #remove last element of coordinate 0
        with self.assertRaises(ValueError) as ctx:
            trajectory_from_dictionary(dictionaryBad1)
    def tst_trajectory_to_dictionary_to_trajectory(self, domain):
        print("Testing the conversion of a trajectory to a dictionary and back to a trajectory in the "+domain+" domain.")
        dictionaryUnused, trajectory = self.gen_dictionary_and_trajectory(domain)

        trajectoryFinal = trajectory_from_dictionary(dictionary_from_trajectory(trajectory))

        self.assertEqual(trajectory, trajectoryFinal,
                         msg="Error: The "+domain+" trajectory generated from the dictionary generated from a "
                         "trajectory does not match what was expected")
    def tst_trajectory_from_dictionary(self, domain):
        print("Testing the conversion of a dictionary to a trajectory in the "+domain+" domain.")
        dictionary, trajectoryExpected = self.gen_dictionary_and_trajectory(domain)

        trajectory = trajectory_from_dictionary(dictionary)

        self.assertEqual(trajectory, trajectoryExpected,
                         msg="Error: The "+domain+" trajectory generated from dictionary does not match what"
                         "was expected")
    def tst_trajectory_from_dictionary(self, domain):
        print(
            "Testing the conversion of a dictionary to a trajectory in the {} domain."
            .format(domain))
        dictionary, trajectoryExpected = self.gen_dictionary_and_trajectory(
            domain)

        trajectory = trajectory_from_dictionary(dictionary)

        self.assertEqual(
            trajectory,
            trajectoryExpected,
            msg=("Error: The {} trajectory generated from dictionary "
                 "does not match what was expected").format(domain))
    def tst_dictionary_to_trajectory_to_dictionary(self, domain):
        print(
            "Testing the conversion of a dictionary to a trajectory and back to a dictionary in the "
            + domain + " domain.")
        dictionary, unused = self.gen_dictionary_and_trajectory(domain)

        dictionaryFinal = dictionary_from_trajectory(
            trajectory_from_dictionary(dictionary))

        self.assertEqual(
            dictionary,
            dictionaryFinal,
            msg="Error: The " + domain +
            " dictionary generated from the trajectory generated from a "
            "dictionary does not match what was expected")
 def tst_invalid_object_id(self):
     print("Testing invalid object_id")
     dictionaryBad, unused = self.gen_dictionary_and_trajectory("terrestrial")
     dictionaryBad['object_id'] = 2
     with self.assertRaises(ValueError) as ctx:
         trajectory_from_dictionary(dictionaryBad)
 def tst_invalid_domain(self):
     print("Testing invalid domain")
     dictionaryBad, unused = self.gen_dictionary_and_trajectory("terrestrial")
     dictionaryBad['domain'] = "invalid"
     with self.assertRaises(ValueError) as ctx:
         trajectory_from_dictionary(dictionaryBad)