def __init__(self, Table, **config): '''Private constructor for a View object - use the Table.view() method to create Views. A View object represents a specific transform (configuration or pivot, filter, sort, etc) configuration on an underlying Table. A View receives all updates from the Table from which it is derived, and can be serialized to JSON or trigger a callback when it is updated. View objects are immutable, and will remain in memory and actively process updates until its delete() method is called. ''' self._name = "py_" + str(random()) self._table = Table self._config = ViewConfig(**config) self._sides = self.sides() date_validator = self._table._accessor._date_validator if self._sides == 0: self._view = make_view_zero(self._table._table, self._name, COLUMN_SEPARATOR_STRING, self._config, date_validator) elif self._sides == 1: self._view = make_view_one(self._table._table, self._name, COLUMN_SEPARATOR_STRING, self._config, date_validator) else: self._view = make_view_two(self._table._table, self._name, COLUMN_SEPARATOR_STRING, self._config, date_validator) self._column_only = self._view.is_column_only() self._callbacks = self._table._callbacks self._delete_callbacks = _PerspectiveCallBackCache()
def test_make_view_two(self): accessor = _PerspectiveAccessor([{"a": 1, "b": 2}, {"a": 3, "b": 4}]) view_config = ViewConfig({"row_pivots": ["a"], "column_pivots": ["b"]}) tbl = make_table(None, accessor, None, 4294967295, '', t_op.OP_INSERT, False, False) view = make_view_two(tbl, "view2", "|", view_config, accessor._date_validator) assert view.num_rows() == 3