def test_with_nonstr_sequence_arg_values_resolved(self): arg = [ ("partial", partial(int, "79")), ("evaluator", Evaluator(int, "97")), ("reference", Reference("number")) ] evaluator = Evaluator(dict, arg) self.assertEqual( {"partial": 79, "evaluator": 97, "reference": 101}, evaluator(self._assembler))
def test_with_dict_keyword_values_resolved(self): arg = { "partial": partial(int, "79"), "evaluator": Evaluator(int, "97"), "reference": Reference("number"), } evaluator = Evaluator(dict, keyword=arg) self.assertEqual( {"keyword": {"partial": 79, "evaluator": 97, "reference": 101}}, evaluator(self._assembler))
def test_with_nonstr_sequence_keyword_values_resolved(self): arg = [ ("partial", partial(int, "79")), ("evaluator", Evaluator(int, "97")), ("reference", Reference("number")) ] evaluator = Evaluator(dict, keyword=arg) self.assertEqual( {"keyword": [("partial", 79), ("evaluator", 97), ("reference", 101)]}, evaluator(self._assembler))
def test_with_partial_arg(self): evaluator = Evaluator(hex, partial(int, "79")) self.assertEqual("0x4f", evaluator(None))
def test_simple_evaluation(self): evaluator = Evaluator(int, "1001111", base=2) self.assertEqual(79, evaluator(None))
def test_initialization_support(self): evaluator = Evaluator(int) evaluator.args.append("1001111") evaluator.keywords.update(base=2) self.assertEqual(["1001111"], evaluator.args) self.assertEqual({"base": 2}, evaluator.keywords)
def test_accepts_keywords(self): evaluator = Evaluator(int, "1001111", base=2) self.assertEqual({"base": 2}, evaluator.keywords)
def test_accepts_args(self): evaluator = Evaluator(int, "79") self.assertEqual(["79"], evaluator.args)
def test_accepts_callable_factory(self): evaluator = Evaluator(int) self.assertTrue(evaluator.factory is int)
def setUp(self): # for InitializationSupportTest self._support = Evaluator(object)
def test_with_reference_keyword(self): evaluator = Evaluator(dict, test=Reference("test.dummy.ModuleClass")) d = evaluator(self._assembler) self.assertEqual(1, len(d)) self.assertTrue(isinstance(d["test"], dummy.ModuleClass)) self.assertEqual("test", d["test"].arg)
def test_with_reference_arg(self): evaluator = Evaluator( getattr, Reference("test.dummy.ModuleClass"), "arg") self.assertEqual("test", evaluator(self._assembler))
def test_with_evaluator_keyword(self): evaluator = Evaluator(dict, number=Evaluator(int, "79")) self.assertEqual({"number": 79}, evaluator(None))