def test_can_specify_css_class(): column_with_css = Column(css_class="rho") column_no_css = Column() assert column_with_css.has_css_class == True assert column_with_css.css_class == "rho" assert column_no_css.has_css_class == False assert column_no_css.css_class == None
def test_can_link(): cell = Fake().has_attr(value="pi") linked_column = Column(link=lambda cell: cell.value.upper()) unlinked_column = Column() assert linked_column.has_link == True assert linked_column.link(cell) == u"PI" assert unlinked_column.has_link == False assert unlinked_column.link(cell) == None
def test_can_be_named_by_binding(): table = Fake() column = Column() column.bind_to(table, "epsilon") assert column.name == "epsilon"
def test_raises_if_rebound(): table_a = Fake() table_b = Fake() column = Column() column.bind_to(table_a, "beta") assert_raises(AttributeError, column.bind_to, table_b, "gamma")
def test_can_be_bound(): table = Fake() column = Column() column.bind_to(table, "alpha") assert column.is_bound == True assert column.bound_to == (table, "alpha")
def test_sortable_by_order_of_creation(): a, b, c = Column(), Column(), Column() assert sorted([b, a, c]) == [a, b, c]
def test_renders_name_to_unicode(): assert unicode(Column('zeta')) == u"zeta"
def test_value_can_be_wrapped(): cell = Fake().has_attr(value="abc") column = Column(value=lambda cell: cell.value.upper()) assert column.render(cell) == u"ABC"
def test_renders_values_to_unicode(): bool_cell = Fake().has_attr(value=True) int_cell = Fake().has_attr(value=123) assert Column().render(bool_cell) == u"True" assert Column().render(int_cell) == u"123"
def test_can_be_explicitly_named(): column = Column(name="delta") assert column.name == "delta"
class TestTable(Table): name = Column() weapon = Column()