def test_replace_display_form(self): cell = Cell() cell.set_value(100.) cell.display_form = "100,00" self.assertEqual(cell.plaintext(), "100,00") cell.display_form = "200,00" self.assertEqual(cell.plaintext(), "200,00")
def test_set_new_string(self): cell = Cell(value_type='string') cell.append_text('test') self.assertEqual(cell.plaintext(), 'test') self.assertEqual(cell.value, 'test')
def test_set_cell_row_index_error(self): with self.assertRaises(IndexError): self.table[10, 0] = Cell()
def test_error_set_invalid_odf_object(self): cell = Cell() with self.assertRaises(ValueError): cell.set_value(GenericWrapper())
def test_set_time_value(self): cell = Cell() cell.set_value('PT0H05M00,0000S', 'time') self.assertEqual(cell.value_type, 'time') self.assertEqual(cell.value, 'PT0H05M00,0000S')
def test_init_no_args(self): cell = Cell() self.assertEqual(cell.value_type, None) self.assertEqual(cell.value, None) self.assertEqual(cell.plaintext(), "")
def test_set_float_with_type(self): cell = Cell() cell.set_value('100', 'float') self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, 100.)
def test_set_false_boolean_without_type(self): cell = Cell() cell.set_value(False) self.assertEqual(cell.value_type, 'boolean') self.assertEqual(cell.value, False)
def test_constructor_with_style_name(self): cell = Cell(style_name='astyle') self.assertEqual('astyle', cell.style_name)
def test_float_as_string(self): cell = Cell(1.0, 'string') self.assertEqual(cell.value_type, 'string') self.assertEqual(cell.value, '1.0')
def test_float_no_type(self): cell = Cell(1.0) self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, 1.0)
def test_float_with_type(self): cell = Cell(1.0, 'currency') self.assertEqual(cell.value_type, 'currency') self.assertEqual(cell.value, 1.0)
def test_string(self): cell = Cell('text') self.assertEqual(cell.value_type, 'string') self.assertEqual(cell.value, 'text')
def test_init_type_without_value(self): cell = Cell(value_type='float') self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, None) self.assertEqual(cell.plaintext(), "")
def test_init_value_without_type(self): cell = Cell(value=100) self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, 100.)
def test_append_two_strings(self): cell = Cell('test1') cell.append_text('test2') self.assertEqual(cell.plaintext(), 'test1test2') self.assertEqual(cell.value, 'test1test2')
def test_boolean_true(self): cell = Cell(True) self.assertEqual(cell.value_type, 'boolean') self.assertEqual(cell.value, True)
def test_replace_two_paragraphs_by_new_string(self): cell = Cell('test1') cell.append(Paragraph('test2')) cell.set_value('new content') self.assertEqual('new content', cell.value)
def test_boolean_false(self): cell = Cell(False) self.assertEqual(cell.value_type, 'boolean') self.assertEqual(cell.value, False)
def test_set_int_without_type(self): cell = Cell() cell.set_value(100) self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, 100.)
def test_time_value(self): cell = Cell('PT0H05M00,0000S', 'time') self.assertEqual(cell.value_type, 'time') self.assertEqual(cell.value, 'PT0H05M00,0000S')
def test_error_set_None_value(self): cell = Cell() with self.assertRaises(ValueError): cell.set_value(None)
def test_date_value(self): cell = Cell('2011-01-29T12:00:01', 'date') self.assertEqual(cell.value_type, 'date') self.assertEqual(cell.value, '2011-01-29T12:00:01')
def test_wrapped_object(self): cell = Cell(Paragraph('text')) self.assertEqual(cell.value_type, 'string') self.assertEqual(cell.value, 'text') self.assertEqual(cell[0].kind, 'Paragraph')
def test_set_content_validation_name(self): cell = Cell() cell.content_validation_name = 'validation' self.assertEqual(cell.content_validation_name, 'validation') self.assertEqual(cell.get_attr(CN('table:content-validation-name')), 'validation', 'wrong tag name')
def test_Cell_is_kind_of_Cell(self): cell = Cell() covered_cell = Cell() self.assertEqual(covered_cell.kind, cell.kind)
def test_set_cell_neg_row_index(self): self.table[-1, 0] = Cell('Textcell') cell = self.table[3, 0] self.assertEqual(cell.plaintext(), "Textcell")
def test_is_covered(self): cell = Cell() self.assertFalse(cell.covered)
def test_check_invalid_value_type(self): cell = Cell() with self.assertRaises(TypeError): cell.set_value('', value_type='invalid')
def test_uncover_cell(self): cell = Cell() cell._set_covered(False) self.assertFalse(cell.covered) self.assertEqual(cell.TAG, Cell.TAG)
def test_append_text_accept_style_name(self): cell = Cell('Text') cell.append_text('Text', style_name='test') self.assertEqual(cell.value, 'TextText')
def test_cover_cell(self): cell = Cell() cell._set_covered(True) self.assertTrue(cell.covered) self.assertEqual(cell.TAG, CoveredCell.TAG) self.assertEqual('Cell', cell.kind)
def test_append_two_paragraphs(self): cell = Cell('test1') cell.append(Paragraph('test2')) self.assertEqual(cell.plaintext(), 'test1\ntest2') self.assertEqual(cell.value, 'test1\ntest2')
def test_cover_cell_and_remove_unwanted_tags(self): cell = Cell() cell._set_span((2, 2)) cell._set_covered(True) self.assertIsNone(cell.get_attr(CN('table:number-rows-spanned'))) self.assertIsNone(cell.get_attr(CN('table:number-colums-spanned')))
def test_append_text_error(self): cell = Cell(1.) with self.assertRaises(TypeError): cell.append_text('test')
def test_has_xmlnode(self): cell = Cell() self.assertIsNotNone(cell.xmlnode)
def test_set_float_without_type(self): cell = Cell() # set type explicit else type is string cell.set_value(100.) self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, 100.0)
def test_get_style_name(self): cell = Cell() self.assertIsNone(cell.style_name)
def test_set_true_boolean_with_type(self): cell = Cell() cell.set_value(True, 'boolean') self.assertEqual(cell.value_type, 'boolean') self.assertEqual(cell.value, True)
def test_set_style_name(self): cell = Cell() cell.style_name = 'STYLE' self.assertEqual(cell.style_name, 'STYLE') self.assertEqual(cell.get_attr(CN('table:style-name')), 'STYLE', 'wrong tag name')
def test_set_currency(self): cell = Cell() cell.set_value(100., currency='EUR') self.assertEqual(cell.currency, 'EUR') self.assertEqual(cell.value_type, 'currency') self.assertEqual(cell.value, 100.)
def test_get_content_validation_name(self): cell = Cell() self.assertIsNone(cell.content_validation_name)
def test_set_date_value(self): cell = Cell() cell.set_value('2011-01-29T12:00:00', 'date') self.assertEqual(cell.value_type, 'date') self.assertEqual(cell.value, '2011-01-29T12:00:00')
def test_has_TAG(self): cell = Cell() self.assertEqual(cell.TAG, CN('table:table-cell'))
def test_error_display_form_for_string(self): cell = Cell('cell with string') with self.assertRaises(TypeError): cell.display_form = "raise Error"
def test_set_protected(self): cell = Cell() cell.protected = True self.assertTrue(cell.protected)
def test_setting_cell_by_address(self): self.table['A1'] = Cell('Textcell') cell = self.table[0, 0] self.assertEqual(cell.plaintext(), "Textcell")
def test_set_span(self): cell = Cell() cell._set_span(( 2, 3) ) self.assertEqual(cell.span, (2, 3))
def test_set_cell_column_index_error(self): with self.assertRaises(IndexError): self.table[0, 10] = Cell()
def test_check_valid_value_types(self): cell = Cell() for t in ('float', 'percentage', 'currency', 'date', 'time', 'boolean', 'string'): cell.set_value(1., t) self.assertEqual(cell.value_type, t)
def test_set_cell_neg_column_index(self): self.table[0, -1] = Cell('Textcell') cell = self.table[0, 3] self.assertEqual(cell.plaintext(), "Textcell")
def test_set_value_type(self): cell = Cell() cell.set_value('a string') self.assertEqual(cell.value_type, 'string') self.assertEqual(cell.get_attr(CN('office:value-type')), 'string', 'wrong tag name')