Exemplo n.º 1
0
 def test_column_declaration(self):
     """Test standard column declaration styles."""
     grid = DataGrid(name='grid',
                     fields=[
                         DataGrid.Column('name', options=dict(foobar=123)),
                         ('Subtype', 'subtype'),
                         DataGrid.Column('text', 'excerpt', 'TEXT')
                     ])
     d = dict(value='value')
     grid.update_params(d)
     get_field = d['get_field']
     # 'headers' and 'collist' only supported for backward compatibility
     assert d['headers'] == ['Name', 'Subtype', 'TEXT']
     assert d['collist'] == ['name', 'column-1', 'text']
     assert d['columns'][0].get_option('foobar') == 123
     assert grid.get_column('name').options['foobar'] == 123
     row = Foo('spa1', 'fact', 'thetext')
     assert 'spa1' == get_field(row, 'name')
     assert 'fact' == get_field(row, 'column-1')
     assert 'thetext...' == get_field(row, 'text')
Exemplo n.º 2
0
 def test_alternative_column_declaration(self):
     """Test alternative column declaration styles."""
     g = lambda: None
     grid = DataGrid(fields=[(g), ('t', g), ('t', g, dict(p=0)),
                             DataGrid.Column('n', g, 't', dict(p=0))])
     for i in range(4):
         name = i == 3 and 'n' or 'column-%d' % i
         c = grid[name]
         assert c.name == name
         title = i == 0 and name.capitalize() or 't'
         assert c.title == title
         assert c.getter == g
         options = i > 1 and dict(p=0) or dict()
         assert c.options == options