def test_functions_available(self): v = VDF() self.assertEqual(v.functions_available(), ['bpr'], 'VDF class returning wrong availability') self.assertEqual(v.apply_vdf, None, 'VDF is missing term') self.assertEqual(v.apply_derivative, None, 'VDF is missing term') with self.assertRaises(ValueError): v.function = 'Cubic' with self.assertRaises(AttributeError): v.apply_vdf = isinstance
def test_functions_available(self): v = VDF() self.assertEqual(v.functions_available(), ["bpr", "conical"], "VDF class returning wrong availability") self.assertEqual(v.apply_vdf, None, "VDF is missing term") self.assertEqual(v.apply_derivative, None, "VDF is missing term") with self.assertRaises(ValueError): v.function = "Cubic" with self.assertRaises(AttributeError): v.apply_vdf = isinstance
def __check_attributes(self, instance, value): if instance == "rgap_target": if not isinstance(value, float): return False, value, "Relative gap needs to be a float" if isinstance(self.assignment, LinearApproximation): self.assignment.rgap_target = value elif instance == "max_iter": if not isinstance(value, int): return False, value, "Number of iterations needs to be an integer" if isinstance(self.assignment, LinearApproximation): self.assignment.max_iter = value elif instance == "vdf": v = value.lower() if v not in all_vdf_functions: return False, value, f"Volume-delay function {value} is not available" value = VDF() value.function = v elif instance == "classes": if isinstance(value, TrafficClass): value = [value] elif isinstance(value, list): for v in value: if not isinstance(v, TrafficClass): return False, value, "Traffic classes need to be proper AssignmentClass objects" else: raise ValueError("Traffic classes need to be proper AssignmentClass objects") elif instance == "vdf_parameters": if not self.__validate_parameters(value): return False, value, f"Parameter set is not valid: {value} " elif instance in ["time_field", "capacity_field"]: if not isinstance(value, str): return False, value, f"Value for {instance} is not string" elif instance == "cores": if not isinstance(value, int): return False, value, f"Value for {instance} is not integer" elif instance == "save_path_files": if not isinstance(value, bool): return False, value, f"Value for {instance} is not boolean" if instance not in self.__dict__: return False, value, f"trafficAssignment class does not have property {instance}" return True, value, ""