Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cell_range():
ipysheet.sheet(rows=3, columns=4)
# [row][column]
ipysheet.cell_range([[0, 1]]) # 1 row, 2 columns
ipysheet.cell_range([[0], [2]]) # 2 rows, 1 columns
ipysheet.cell_range([[0, 1], [2, 3]]) # 2 rows, 2 columns
ipysheet.cell_range([[0, 1], [2, 3], [4, 5]]) # 3 rows, 2 columns
ipysheet.cell_range([[0, 1, 9], [2, 3, 9], [4, 5, 9]]) # 3 rows, 3 columns
ipysheet.cell_range([[0, 1, 9]], column_end=2) # 3 rows, 3 columns
ipysheet.cell_range([[0, 1, 9]], column_start=1) # 1 rows, 3 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1], [2, 3], [4, 5], [6, 7]]) # 4 rows, 2 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]]) # 3 rows, 5 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2], [3, 4, 5, 6, 7]]) # not well shaped
with pytest.raises(ValueError):
ipysheet.cell_range([]) # empty rows
with pytest.raises(ValueError):
ipysheet.cell_range([[], []]) # empty columns
value = [[0, 1], [2, 3], [4, 5]]
with pytest.raises(ValueError):
ipysheet.cell_range([[], []]) # empty columns
value = [[0, 1], [2, 3], [4, 5]]
valueT = [[0, 2, 4], [1, 3, 5]] # it's transpose
assert value == transpose(valueT)
r = ipysheet.cell_range(value) # 3 rows, 2 columns
with pytest.raises(ValueError):
r.value = 1
with pytest.raises(ValueError):
r.value = [1, 2, 3]
with pytest.raises(ValueError):
r.value = [[1, 2]]
assert r.value == transpose(valueT)
rT = ipysheet.cell_range(valueT, transpose=True) # 3 rows, 2 columns
with pytest.raises(ValueError):
rT.value = 1
with pytest.raises(ValueError):
rT.value = [1, 2, 3]
with pytest.raises(ValueError):
rT.value = [[1, 2]]
rT.value = transpose(value)
assert rT.value == transpose(value)
sheet = ipysheet.sheet(rows=3, columns=4)
assert len(sheet.cells) == 0
with ipysheet.hold_cells():
ipysheet.cell_range(value)
ipysheet.cell_range(value)
assert len(sheet.cells) == 0
assert len(sheet.cells) == 2
ipysheet.cell_range([[0, 1, 9]], column_start=1) # 1 rows, 3 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1], [2, 3], [4, 5], [6, 7]]) # 4 rows, 2 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]]) # 3 rows, 5 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2], [3, 4, 5, 6, 7]]) # not well shaped
with pytest.raises(ValueError):
ipysheet.cell_range([]) # empty rows
with pytest.raises(ValueError):
ipysheet.cell_range([[], []]) # empty columns
value = [[0, 1], [2, 3], [4, 5]]
valueT = [[0, 2, 4], [1, 3, 5]] # it's transpose
assert value == transpose(valueT)
r = ipysheet.cell_range(value) # 3 rows, 2 columns
with pytest.raises(ValueError):
r.value = 1
with pytest.raises(ValueError):
r.value = [1, 2, 3]
with pytest.raises(ValueError):
r.value = [[1, 2]]
assert r.value == transpose(valueT)
rT = ipysheet.cell_range(valueT, transpose=True) # 3 rows, 2 columns
with pytest.raises(ValueError):
rT.value = 1
with pytest.raises(ValueError):
rT.value = [1, 2, 3]
with pytest.raises(ValueError):
rT.value = [[1, 2]]
rT.value = transpose(value)
def test_cell_range_style():
values = [[1]]
cell = ipysheet.cell_range(values, color='red')
assert cell.style['color'] == 'red'
cell = ipysheet.cell_range(values, background_color='blue')
assert cell.style['backgroundColor'] == 'blue'
cell = ipysheet.cell_range(values, font_style='nice')
assert cell.style['fontStyle'] == 'nice'
cell = ipysheet.cell_range(values, font_weight='bold')
assert cell.style['fontWeight'] == 'bold'
def test_cell_range():
ipysheet.sheet(rows=3, columns=4)
# [row][column]
ipysheet.cell_range([[0, 1]]) # 1 row, 2 columns
ipysheet.cell_range([[0], [2]]) # 2 rows, 1 columns
ipysheet.cell_range([[0, 1], [2, 3]]) # 2 rows, 2 columns
ipysheet.cell_range([[0, 1], [2, 3], [4, 5]]) # 3 rows, 2 columns
ipysheet.cell_range([[0, 1, 9], [2, 3, 9], [4, 5, 9]]) # 3 rows, 3 columns
ipysheet.cell_range([[0, 1, 9]], column_end=2) # 3 rows, 3 columns
ipysheet.cell_range([[0, 1, 9]], column_start=1) # 1 rows, 3 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1], [2, 3], [4, 5], [6, 7]]) # 4 rows, 2 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]]) # 3 rows, 5 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2], [3, 4, 5, 6, 7]]) # not well shaped
with pytest.raises(ValueError):
ipysheet.cell_range([]) # empty rows
with pytest.raises(ValueError):
ipysheet.cell_range([[], []]) # empty columns
value = [[0, 1], [2, 3], [4, 5]]
valueT = [[0, 2, 4], [1, 3, 5]] # it's transpose
assert value == transpose(valueT)
r = ipysheet.cell_range(value) # 3 rows, 2 columns
with pytest.raises(ValueError):
rT = ipysheet.cell_range(valueT, transpose=True) # 3 rows, 2 columns
with pytest.raises(ValueError):
rT.value = 1
with pytest.raises(ValueError):
rT.value = [1, 2, 3]
with pytest.raises(ValueError):
rT.value = [[1, 2]]
rT.value = transpose(value)
assert rT.value == transpose(value)
sheet = ipysheet.sheet(rows=3, columns=4)
assert len(sheet.cells) == 0
with ipysheet.hold_cells():
ipysheet.cell_range(value)
ipysheet.cell_range(value)
assert len(sheet.cells) == 0
assert len(sheet.cells) == 2
def test_cell_range_style():
values = [[1]]
cell = ipysheet.cell_range(values, color='red')
assert cell.style['color'] == 'red'
cell = ipysheet.cell_range(values, background_color='blue')
assert cell.style['backgroundColor'] == 'blue'
cell = ipysheet.cell_range(values, font_style='nice')
assert cell.style['fontStyle'] == 'nice'
cell = ipysheet.cell_range(values, font_weight='bold')
assert cell.style['fontWeight'] == 'bold'
def test_cell_range_style():
values = [[1]]
cell = ipysheet.cell_range(values, color='red')
assert cell.style['color'] == 'red'
cell = ipysheet.cell_range(values, background_color='blue')
assert cell.style['backgroundColor'] == 'blue'
cell = ipysheet.cell_range(values, font_style='nice')
assert cell.style['fontStyle'] == 'nice'
cell = ipysheet.cell_range(values, font_weight='bold')
assert cell.style['fontWeight'] == 'bold'
[1, 1, 1, 1],
[2, 2, 222, 22],
[2, 0, 111, 11],
],
row_start=0, column_start=0,
transpose=True
)
df = ipysheet.to_dataframe(sheet)
assert np.all(df['c0'].tolist() == [2, 34, 543, 23])
assert np.all(df['c1'].tolist() == [1, 1, 1, 1])
assert np.all(df['c2'].tolist() == [2, 2, 222, 22])
assert np.all(df['c3'].tolist() == [2, 0, 111, 11])
sheet = ipysheet.sheet(rows=4, columns=4, column_headers=['t0', 't1', 't2', 't3'])
ipysheet.cell_range(
[
[2, 34, 543, 23],
[1, 1, 1, 1],
[2, 2, 222, 22],
[2, 0, 111, 11],
],
row_start=0, column_start=0,
transpose=False
)
df = ipysheet.to_dataframe(sheet)
assert np.all(df['t0'].tolist() == [2, 1, 2, 2])
assert np.all(df['t1'].tolist() == [34, 1, 2, 0])
assert np.all(df['t2'].tolist() == [543, 1, 222, 111])
assert np.all(df['t3'].tolist() == [23, 1, 22, 11])
def test_cell_range():
ipysheet.sheet(rows=3, columns=4)
# [row][column]
ipysheet.cell_range([[0, 1]]) # 1 row, 2 columns
ipysheet.cell_range([[0], [2]]) # 2 rows, 1 columns
ipysheet.cell_range([[0, 1], [2, 3]]) # 2 rows, 2 columns
ipysheet.cell_range([[0, 1], [2, 3], [4, 5]]) # 3 rows, 2 columns
ipysheet.cell_range([[0, 1, 9], [2, 3, 9], [4, 5, 9]]) # 3 rows, 3 columns
ipysheet.cell_range([[0, 1, 9]], column_end=2) # 3 rows, 3 columns
ipysheet.cell_range([[0, 1, 9]], column_start=1) # 1 rows, 3 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1], [2, 3], [4, 5], [6, 7]]) # 4 rows, 2 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]]) # 3 rows, 5 columns
with pytest.raises(ValueError):
ipysheet.cell_range([[0, 1, 2, 3, 4], [2], [3, 4, 5, 6, 7]]) # not well shaped
with pytest.raises(ValueError):
ipysheet.cell_range([]) # empty rows
with pytest.raises(ValueError):
ipysheet.cell_range([[], []]) # empty columns
value = [[0, 1], [2, 3], [4, 5]]
valueT = [[0, 2, 4], [1, 3, 5]] # it's transpose
assert value == transpose(valueT)
r = ipysheet.cell_range(value) # 3 rows, 2 columns