Пример #1
0
    def testSingleArgBoundColumn(self):

        storage = {}
        model = object()

        def get_col_fn(unit_test, expected_model):
            get_col_fn.call_count = 0

            def column_fn(self, t):
                # check that argument passed in is the model
                get_col_fn.call_count += 1
                unit_test.assertEqual(expected_model, self)
                return 100 * t

            return column_fn

        # Setup a function to memoize
        column_fn = get_col_fn(self, model)

        # Setup the Column
        column = Column(column_fn, True)

        # Setup the ColumnBinding, maps a column to it's storage
        # and provides a callable interface
        column_binding = BoundColumnCall(column, storage, model)

        # Call the column
        self.assertEqual(get_col_fn.call_count, 0)
        column_binding(2)
        self.assertEqual(get_col_fn.call_count, 1)
        self.assertEqual({(2, ): 200}, storage)

        # Call column again
        column_binding(3)
        self.assertEqual(get_col_fn.call_count, 2)
        self.assertEqual({(2, ): 200, (3, ): 300}, storage)

        # subsequent calls should have no effect
        for i in xrange(1, 10):
            column_binding(2)
            column_binding(3)
            self.assertEqual(get_col_fn.call_count, 2)
            self.assertEqual({(2, ): 200, (3, ): 300}, storage)

        # Call column again
        column_binding(4)
        self.assertEqual(get_col_fn.call_count, 3)
        self.assertEqual({(2, ): 200, (3, ): 300, (4, ): 400}, storage)
Пример #2
0
 def testIsAutoCallColumn(self):
     col = Column(lambda x: x, True)
     self.assertTrue(Column.is_column(col))
     self.assertTrue(Column.is_auto_call(col))
Пример #3
0
 def testGetMetadata(self):
     col = Column(lambda x: x, True)
     metadata = Column.get_metadata(col)
     self.assertIsInstance(metadata, ColumnMetadata, \
                           'Expected column metadata')
Пример #4
0
 def testIsColumn(self):
     col = Column(lambda x: x, False)
     self.assertTrue(Column.is_column(col))
     self.assertFalse(Column.is_auto_call(col))