コード例 #1
0
    def test_get_processor_method(self):
        class Dummy(object):
            def fake_callback(self):
                pass

        view = Dummy()

        # Test no callback given
        dt = Datatable([], '/')
        f = dt.get_processor_method(Column('Fake', sources=['fake']), i=0)
        self.assertEqual(f, None)

        class DT(Datatable):
            def fake_callback(self):
                pass

        column = Column('Fake', sources=['fake'], processor='fake_callback')

        # Test callback found on self
        dt = DT([], '/')
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, dt.fake_callback)

        # Test callback found on callback_target
        dt = Datatable([], '/', callback_target=view)
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, view.fake_callback)
コード例 #2
0
    def test_get_processor_method_returns_direct_callable(self):
        def fake_callback():
            pass

        column = Column('Fake', sources=[], processor=fake_callback)

        # Test no callback given
        dt = Datatable([], '/')
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, fake_callback)
コード例 #3
0
    def test_get_processor_method_finds_implied_callback(self):
        class DummyNamed(object):
            def get_column_fake_data(self):
                pass

        class DummyIndexed(object):
            def get_column_0_data(self):
                pass

        class DummyBoth(object):
            def get_column_fake_data(self):
                pass

            def get_column_0_data(self):
                pass

        column = Column('Fake', sources=[])
        column.name = 'fake'

        # Test implied named callback found first
        view = DummyNamed()
        dt = Datatable([], '/', callback_target=view)
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, view.get_column_fake_data)

        # Test implied named callback found first
        view = DummyIndexed()
        dt = Datatable([], '/', callback_target=view)
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, view.get_column_0_data)

        # Test implied named callback found first
        view = DummyBoth()
        dt = Datatable([], '/', callback_target=view)
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, view.get_column_fake_data)

        class DTNamed(Datatable):
            def get_column_fake_data(self):
                pass

        class DTIndexed(Datatable):
            def get_column_0_data(self):
                pass

        class DTBoth(Datatable):
            def get_column_fake_data(self):
                pass

            def get_column_0_data(self):
                pass

        # Test implied named callback found first
        dt = DTNamed([], '/')
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, dt.get_column_fake_data)

        # Test implied named callback found first
        dt = DTIndexed([], '/')
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, dt.get_column_0_data)

        # Test implied named callback found first
        dt = DTBoth([], '/')
        f = dt.get_processor_method(column, i=0)
        self.assertEqual(f, dt.get_column_fake_data)