def test_equality(): c1 = ReadOnlyCell(None, None, 10, None) c2 = ReadOnlyCell(None, None, 10, None) assert c1 is not c2 assert c1 == c2 c3 = ReadOnlyCell(None, None, 5, None) assert c3 != c1
def DummyCell(dummy_sheet): dummy_sheet.parent._number_formats.add('d-mmm-yy') style = StyleArray([0, 0, 0, 164, 0, 0, 0, 0, 0]) dummy_sheet.parent._cell_styles.add(style) cell = ReadOnlyCell(dummy_sheet, None, None, "23596", 'n', 1) return cell
def test_read_only(dummy_sheet): cell = ReadOnlyCell(sheet=dummy_sheet, row=None, column=None, value='1') assert cell.value == 1 with pytest.raises(AttributeError): cell.value = 10 with pytest.raises(AttributeError): cell.style = 1
def _get_row(self, element, min_col=1, max_col=None, row_counter=None): """Return cells from a particular row""" col_counter = min_col data_only = getattr(self.parent, 'data_only', False) for cell in safe_iterator(element, CELL_TAG): coordinate = cell.get('r') if coordinate: row, column = coordinate_to_tuple(coordinate) else: row, column = row_counter, col_counter if max_col is not None and column > max_col: break if min_col <= column: if col_counter < column: for col_counter in range(max(col_counter, min_col), column): # pad row with missing cells yield EMPTY_CELL data_type = cell.get('t', 'n') style_id = int(cell.get('s', 0)) value = None formula = cell.findtext(FORMULA_TAG) if formula is not None and not data_only: data_type = 'f' value = "=%s" % formula elif data_type == 'inlineStr': child = cell.find(INLINE_TAG) if child is not None: richtext = Text.from_tree(child) value = richtext.content else: value = cell.findtext(VALUE_TAG) or None yield ReadOnlyCell(self, row, column, value, data_type, style_id) col_counter = column + 1 if max_col is not None: for _ in range(max(min_col, col_counter), max_col + 1): yield EMPTY_CELL
def test_numeric(dummy_sheet, value, expected): cell = ReadOnlyCell(dummy_sheet, None, None, value, 'n') v = cell.value assert v == expected assert hasattr(v, 'is_integer') == hasattr(expected, 'is_integer'),\ "Expected {0}, {1}".format(type(expected), type(v))
def test_inline_String(dummy_sheet): cell = ReadOnlyCell(dummy_sheet, None, None, "Hello World!", 'inlineStr') assert cell.value == "Hello World!"
def test_bool(dummy_sheet, value, expected): cell = ReadOnlyCell(dummy_sheet, None, None, value, 'b') assert cell.value is expected
def test_coordinate(dummy_sheet): cell = ReadOnlyCell(dummy_sheet, 1, 1, 10, None) assert cell.coordinate == "A1"
def test_string_table(dummy_sheet): cell = ReadOnlyCell(dummy_sheet, None, None, '0', 's') assert cell.shared_strings == ['Hello world'] assert cell.value == 'Hello world'
def test_base_date(dummy_sheet): cell = ReadOnlyCell(dummy_sheet, None, None, '10', 'n') assert cell.base_date == 2415018.5
def test_ctor(dummy_sheet): cell = ReadOnlyCell(dummy_sheet, None, None, '10', 'n') assert cell.value == 10
def test_font(self, dummy_sheet): cell = ReadOnlyCell(dummy_sheet, None, None, None) assert cell.font == None
def test_style_array(self, dummy_sheet): cell = ReadOnlyCell(dummy_sheet, None, None, None) assert cell.style_array == StyleArray()