Example #1
0
    def test_from_block(self):
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        block = Block()
        block.from_list(self.BLOCK_DATA)
        table.from_block(block, 0)

        assert_list_equal(table.values, self.TABLE_VALUES)
Example #2
0
    def test_from_block(self):
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        block = Block()
        block.from_list(self.BLOCK_DATA)
        table.from_block(block, 0)

        assert_list_equal(table.values, self.TABLE_VALUES)
Example #3
0
    def test_to_block(self):
        block = Block()
        block.from_list([0] * len(self.BLOCK_DATA))
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        table.values = self.TABLE_VALUES
        table.to_block(block, 0)

        assert_list_equal(block.to_list(), self.BLOCK_DATA)
Example #4
0
    def test_to_block(self):
        block = Block()
        block.from_list([0] * len(self.BLOCK_DATA))
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        table.values = self.TABLE_VALUES
        table.to_block(block, 0)

        assert_list_equal(block.to_list(), self.BLOCK_DATA)
Example #5
0
 def test_from_yml_rep_errors(self):
     table = Table(num_rows=1, schema=self.TABLE_SCHEMA)
     for row, column_name, expected_error, expected_error_cause, yml_rep in self.BAD_YML_REPS:
         print(row, column_name, expected_error)
         with assert_raises(TableError) as cm:
             table.from_yml_rep(yml_rep)
         e = cm.exception
         assert_equal(e.entry, 0)
         assert_equal(e.field, column_name)
         assert_is_instance(e.cause, expected_error)
         if expected_error_cause:
             assert_is_instance(e.cause.cause, expected_error_cause)
Example #6
0
 def test_from_yml_rep_errors(self):
     table = Table(num_rows=1,
                   schema=self.TABLE_SCHEMA)
     for row, column_name, expected_error, expected_error_cause, yml_rep in self.BAD_YML_REPS:
         print row, column_name, expected_error
         with assert_raises(TableError) as cm:
             table.from_yml_rep(yml_rep)
         e = cm.exception
         assert_equal(e.entry, 0)
         assert_equal(e.field, column_name)
         assert_is_instance(e.cause, expected_error)
         if expected_error_cause:
             assert_is_instance(e.cause.cause, expected_error_cause)
Example #7
0
def eb_table_from_offset(offset,
                         single_column=None,
                         matrix_dimensions=None,
                         hidden_columns=None,
                         num_rows=None,
                         name=None):
    if hidden_columns is None:
        hidden_columns = []

    try:
        schema_specification = _EB_SCHEMA_MAP[offset]
    except KeyError:
        raise InvalidArgumentError(
            "Could not setup EbTable from unknown offset[{:#x}]".format(
                offset))

    if single_column:
        schema = single_column
    else:
        schema = EbRowTableEntry.from_schema_specification(
            schema_specification=schema_specification["entries"],
            hidden_columns=hidden_columns)

    if matrix_dimensions:
        matrix_width, matrix_height = matrix_dimensions
        return MatrixTable(schema=schema,
                           matrix_height=matrix_height,
                           name=name or schema_specification["name"],
                           size=schema_specification["size"])
    else:
        return Table(schema=schema,
                     name=name or schema_specification["name"],
                     size=schema_specification["size"],
                     num_rows=num_rows)
Example #8
0
 def test_to_yml_rep(self):
     table = Table(num_rows=len(self.TABLE_VALUES),
                   schema=self.TABLE_SCHEMA)
     table.values = self.TABLE_VALUES
     assert_dict_equal(table.to_yml_rep(), self.YML_REP)
Example #9
0
    def test_from_yml_rep(self):
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        table.from_yml_rep(self.YML_REP)

        assert_list_equal(table.values, self.TABLE_VALUES)
Example #10
0
 def test_to_yml_rep(self):
     table = Table(num_rows=len(self.TABLE_VALUES),
                   schema=self.TABLE_SCHEMA)
     table.values = self.TABLE_VALUES
     assert_dict_equal(table.to_yml_rep(), self.YML_REP)
Example #11
0
    def test_from_yml_rep(self):
        table = Table(num_rows=len(self.TABLE_VALUES),
                      schema=self.TABLE_SCHEMA)
        table.from_yml_rep(self.YML_REP)

        assert_list_equal(table.values, self.TABLE_VALUES)