Exemple #1
0
    def test_method(self):
        DummyC.method = m.TemplateMethod("method", DummyC)
        DummyC.method.add_instantiation(int, DummyC.dummy_c)
        DummyC.method.add_instantiation(float, DummyC.dummy_d)

        self.assertEqual(str(DummyC.method),
                         "<unbound TemplateMethod DummyC.method>")
        self.assertTrue(DummyC.method.is_instantiation(DummyC.dummy_c))
        if six.PY2:
            self.assertEqual(str(DummyC.method[int]),
                             "<unbound method DummyC.method[int]>")
        else:
            self.assertTrue(
                str(DummyC.method[int]).startswith(
                    "<function DummyC.method[int] at "),
                str(DummyC.method[int]))

        obj = DummyC()
        self.assertTrue(
            str(obj.method).startswith(
                "<bound TemplateMethod DummyC.method of "))
        self.assertIn("<bound method DummyC.method[int] of ",
                      str(obj.method[int]))
        self.assertEqual(obj.method[int](), (obj, 3))
        self.assertEqual(DummyC.method[int](obj), (obj, 3))
        self.assertEqual(obj.method[float](), (obj, 4))
        self.assertEqual(DummyC.method[float](obj), (obj, 4))
    def test_method(self):
        DummyC.method = m.TemplateMethod("method", DummyC)
        DummyC.method.add_instantiation(int, DummyC.dummy_c)
        DummyC.method.add_instantiation(float, DummyC.dummy_d)

        self.assertEquals(str(DummyC.method),
                          "<unbound TemplateMethod DummyC.method>")
        self.assertEquals(DummyC.method[int], DummyC.dummy_c)
        self.assertEquals(str(DummyC.method[int]),
                          "<unbound method DummyC.dummy_c>")

        obj = DummyC()
        self.assertTrue(
            str(obj.method).startswith(
                "<bound TemplateMethod DummyC.method of "))
        self.assertTrue(
            str(obj.method[int]).startswith(
                "<bound method DummyC.dummy_c of "))
        self.assertEquals(obj.method[int](), (obj, 3))
        self.assertEquals(DummyC.method[int](obj), (obj, 3))
        self.assertEquals(obj.method[float](), (obj, 4))
        self.assertEquals(DummyC.method[float](obj), (obj, 4))