def test_policy_functin_values_delitem(self, value): pf = PolicyFunction(value) values = [x.strip() for x in value.split(',')] for i in range(len(values)): pv = PolicyValue.fromString(i) del pf[pv] assert pf[pv] == PolicyValue.fromString(values[i])
def test_policy_functin_values_getitem(self, value): pf = PolicyFunction(value) if value == PolicyFunction.PASS_EVERYTHING: rnd = random.randint(0, 150) assert pf[PolicyValue(rnd)].value == rnd return values = [x.strip() for x in value.split(',')] for i in range(len(values)): pv = PolicyValue.fromString(i) assert pf[pv] == PolicyValue.fromString(values[i])
def fromString(cls, string: str): # pylint: disable=invalid-name """fromString. Method to get a route object from the string representation :param string: String representation of the route :type string: str """ res = ast.literal_eval(string) return cls(ipaddress.ip_network(res["addr"]), res["path"], res["nh"], policy_value=PolicyValue.fromString(res["policy_value"]))
def test_policy_value_fromStr(self, value): pl = PolicyValue.fromString(value) assert id(pl) is not None assert isinstance(pl, PolicyValue) assert pl.value == int(value) if value != "inf" else math.inf