def test_check_value_choice_of_one_with_none(self): subname = "testArg" subtypes = check.ChoiceOfOne([int, type(None)]) subvalues = {"int": ">0", "NoneType": None} subarg = None check.check_value(subname, subtypes, subvalues, subarg)
def test_check_value_choice_of_one_with_object(self): subname = "testArg" subtypes = check.ChoiceOfOne([int, TestObj]) subvalues = {"int": ">0", "test_check.TestObj": None} subarg = TestObj() check.check_value(subname, subtypes, subvalues, subarg)
def test_check_value_choice_of_one(self): subname = "testArg" subtypes = check.ChoiceOfOne([int, float]) subvalues = {"int": ">0", "float": "<0"} subarg = 1 check.check_value(subname, subtypes, subvalues, subarg)
def test_type_choice_of_one_fail(self): try: check.check_subtype("testArg", check.ChoiceOfOne([int, float]), "string") except AssertionError: pass else: self.fail("should have thrown AssertionError")
def test_check_value_choice_of_one_fail(self): subname = "testArg" subtypes = check.ChoiceOfOne([int, float]) subvalues = {"int": ">0", "float": "<0"} subarg = 50.3 # is float, but >0 try: check.check_value(subname, subtypes, subvalues, subarg) except AssertionError: pass else: self.fail("should have thrown AssertionError")
def test_type_choice_of_one_with_none(self): check.check_subtype("testArg", check.ChoiceOfOne([int, float, type(None)]), None)
def test_type_choice_of_one_object(self): obj = TestObj() self.assertEqual( check.check_subtype("testArg", check.ChoiceOfOne([int, TestObj]), obj), obj)
def test_type_choice_of_one(self): self.assertEqual( check.check_subtype("testArg", check.ChoiceOfOne([int, float]), 58.1), 58.1)
def test_choice_of_one_with_object(self): self.assertEqual( check.eval_subtype("one([int, cls('test_check.TestObj')])"), check.ChoiceOfOne([int, TestObj]))
def test_type_choice(self): self.assertEqual(check.eval_subtype("one([int, float])"), check.ChoiceOfOne([int, float]))