def test_structured_table_reference_boundaries(ref, expected): Column = namedtuple('Column', 'name') class Table: def __init__(self, ref, header_rows, totals_rows): self.ref = ref self.headerRowCount = header_rows self.totalsRowCount = totals_rows self.tableColumns = tuple( Column(name) for name in 'col1 col2 col3 col4 col5'.split()) class Excel: def __init__(self, table): self.a_table = table def table(self, name): if name == 'a_table': return self.a_table, None else: return None, None class Cell: def __init__(self, table, address): self.excel = Excel(table) self.address = AddressCell(address) cell = Cell(Table('A1:E8', 1, 1), 'E5') if isinstance(expected, PyCelException): with pytest.raises(PyCelException): structured_reference_boundaries(ref, cell=cell) elif expected is None: with pytest.raises(PyCelException): structured_reference_boundaries(ref, cell=None) else: ref_bound = structured_reference_boundaries(ref, cell=cell) expected_bound = range_boundaries(expected, cell=cell) assert ref_bound == expected_bound expected_ref = range_boundaries(ref, cell=cell) assert ref_bound == expected_ref
def test_structured_table_reference_boundaries(ref, expected): Column = namedtuple('Column', 'name') class Table: def __init__(self, ref, header_rows, totals_rows): self.ref = ref self.headerRowCount = header_rows self.totalsRowCount = totals_rows self.tableColumns = tuple( Column(name) for name in 'col1 col2 col3 col4 col5'.split()) class Excel: def __init__(self, table): self.a_table = table def table(self, name): if name == 'a_table': return self.a_table, None else: return None, None class Cell: def __init__(self, table, address): self.excel = Excel(table) self.address = AddressCell(address) cell = Cell(Table('A1:E8', 1, 1), 'E5') if isinstance(expected, PyCelException): with pytest.raises(PyCelException): structured_reference_boundaries(ref, cell=cell) elif expected is None: with pytest.raises(PyCelException): structured_reference_boundaries(ref, cell=None) else: ref_bound = structured_reference_boundaries(ref, cell=cell) expected_bound = range_boundaries(expected, cell=cell) assert ref_bound == expected_bound expected_ref = range_boundaries(ref, cell=cell) assert ref_bound == expected_ref
def test_multi_area_ranges(excel, ATestCell): cell = ATestCell('A', 1, excel=excel) from unittest import mock with mock.patch.object(excel, '_defined_names', {'dname': (('$A$1', 's1'), ('$A$3:$A$4', 's2'))}): multi_area_range = AddressMultiAreaRange( tuple(AddressRange(addr, sheet=sh)) for addr, sh in excel._defined_names['dname']) assert (multi_area_range, None) == range_boundaries('dname', cell) assert multi_area_range == AddressRange.create('dname', cell=cell)
def test_extended_range_boundaries_errors(address_string): cell = ATestCell('A', 1) with pytest.raises(ValueError, match='not a valid coordinate or range'): range_boundaries(address_string, cell)
def test_range_boundaries_defined_names(excel): cell = ATestCell('A', 1, excel=excel) assert ((3, 1, 3, 18), 'Sheet1') == range_boundaries('SINUS', cell)
def test_extended_range_boundaries(): cell = ATestCell('A', 1) assert (1, 2) * 2 == range_boundaries('A2')[0] assert (2, 1) * 2 == range_boundaries('B1')[0] assert (1, 2) * 2 == range_boundaries('R2C1')[0] assert (2, 1) * 2 == range_boundaries('R1C2')[0] assert (2, 3) * 2 == range_boundaries('R[2]C[1]', cell)[0] assert (3, 2) * 2 == range_boundaries('R[1]C[2]', cell)[0] assert (1, 1, 2, 2) == range_boundaries('A1:B2')[0] assert (1, 1, 2, 2) == range_boundaries('R1C1:R2C2')[0] assert (2, 1, 2, 3) == range_boundaries('R1C2:R[2]C[1]', cell)[0] assert (3, 13) * 2 == range_boundaries('R13C3')[0] assert (1, 1, 1, 1) == range_boundaries('RC', cell)[0] assert (None, 1, None, 4) == range_boundaries('R:R[3]', cell)[0] assert (None, 1, None, 4) == range_boundaries('R1:R[3]', cell)[0] assert (None, 2, None, 4) == range_boundaries('R2:R[3]', cell)[0] assert (1, None, 4, None) == range_boundaries('C:C[3]', cell)[0] assert (1, None, 4, None) == range_boundaries('C1:C[3]', cell)[0] assert (2, None, 4, None) == range_boundaries('C2:C[3]', cell)[0] with pytest.raises(NotImplementedError, match='Multiple Colon Ranges'): range_boundaries('A1:B2:C3')
def test_extended_range_boundaries(expected, address, ATestCell): assert range_boundaries(address, cell=ATestCell('A', 1))[0] == expected
def test_extended_range_boundaries_errors(address_string): cell = ATestCell('A', 1) with pytest.raises(ValueError, match='not a valid coordinate or range'): range_boundaries(address_string, cell)
def test_range_boundaries_defined_names(excel): cell = ATestCell('A', 1, excel=excel) assert ((3, 1, 3, 18), 'Sheet1') == range_boundaries('SINUS', cell)
def test_extended_range_boundaries(): cell = ATestCell('A', 1) assert (1, 2) * 2 == range_boundaries('A2')[0] assert (2, 1) * 2 == range_boundaries('B1')[0] assert (1, 2) * 2 == range_boundaries('R2C1')[0] assert (2, 1) * 2 == range_boundaries('R1C2')[0] assert (2, 3) * 2 == range_boundaries('R[2]C[1]', cell)[0] assert (3, 2) * 2 == range_boundaries('R[1]C[2]', cell)[0] assert (1, 1, 2, 2) == range_boundaries('A1:B2')[0] assert (1, 1, 2, 2) == range_boundaries('R1C1:R2C2')[0] assert (2, 1, 2, 3) == range_boundaries('R1C2:R[2]C[1]', cell)[0] assert (3, 13) * 2 == range_boundaries('R13C3')[0] assert (1, 1, 1, 1) == range_boundaries('RC', cell)[0] assert (None, 1, None, 4) == range_boundaries('R:R[3]', cell)[0] assert (None, 1, None, 4) == range_boundaries('R1:R[3]', cell)[0] assert (None, 2, None, 4) == range_boundaries('R2:R[3]', cell)[0] assert (1, None, 4, None) == range_boundaries('C:C[3]', cell)[0] assert (1, None, 4, None) == range_boundaries('C1:C[3]', cell)[0] assert (2, None, 4, None) == range_boundaries('C2:C[3]', cell)[0] with pytest.raises(NotImplementedError, match='Multiple Colon Ranges'): range_boundaries('A1:B2:C3')