def test_row_cell_value(): # *_cell_value() correctly mangles attrnames that are Python reserved words. row = Row(Table()) row.from_ = 'foo' eq_(row.get_cell_value('from'), 'foo') row.set_cell_value('from', 'bar') eq_(row.get_cell_value('from'), 'bar')
def test_can_edit_prop_has_priority_over_fset_checks(): # When a row has a cen_edit_* property, it's the result of that property that is used, not the # result of a fset check. class TestRow(Row): @property def bar(self): pass @bar.setter def bar(self, value): pass can_edit_bar = False row = TestRow(Table()) assert not row.can_edit_cell('bar')
def test_sort_table_also_tries_attributes_without_underscores(): # When determining a sort key, after having unsuccessfully tried the attribute with the, # underscore, try the one without one. table = Table() row1 = Row(table) row1._foo = 'a' # underscored attr must be checked first row1.foo = 'b' row1.bar = 'c' row2 = Row(table) row2._foo = 'b' row2.foo = 'a' row2.bar = 'b' table.append(row1) table.append(row2) table.sort_by('foo') assert table[0] is row1 assert table[1] is row2 table.sort_by('bar') assert table[0] is row2 assert table[1] is row1
def test_allow_edit_when_attr_is_property_with_fset(): # When a row has a property that has a fset, by default, make that cell editable. class TestRow(Row): @property def foo(self): pass @property def bar(self): pass @bar.setter def bar(self, value): pass row = TestRow(Table()) assert row.can_edit_cell('bar') assert not row.can_edit_cell('foo') assert not row.can_edit_cell('baz') # doesn't exist, can't edit
def table_with_header(): table = Table() table.append(TestRow(table, 1)) header = TestRow(table, 0) table.header = header return table, header
def table_with_footer(): table = Table() table.append(TestRow(table, 0)) footer = TestRow(table, 1) table.footer = footer return table, footer
def test_in(): # When a table is in a list, doing "in list" with another instance returns false, even if # they're the same as lists. table = Table() some_list = [table] assert Table() not in some_list