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_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')
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_check_invalid_value_type(self): cell = Cell() with self.assertRaises(TypeError): cell.set_value('', value_type='invalid')
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_error_set_None_value(self): cell = Cell() with self.assertRaises(ValueError): cell.set_value(None)
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_int_without_type(self): cell = Cell() cell.set_value(100) self.assertEqual(cell.value_type, 'float') self.assertEqual(cell.value, 100.)
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_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_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_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_error_set_invalid_odf_object(self): cell = Cell() with self.assertRaises(ValueError): cell.set_value(GenericWrapper())
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_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)