forked from pyexcel/pyexcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sheet_access.py
47 lines (34 loc) · 1.38 KB
/
test_sheet_access.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import random
from .base import PyexcelSheetBase
class TestSheetAccess(PyexcelSheetBase):
@staticmethod
def get_random_char():
i = random.randint(97, 122)
return chr(i)
def test_out_of_bounds_write(self):
value = self.get_random_char()
column = self.get_random_char() + self.get_random_char()
cell = column + str(random.randint(9, 30))
self.sheet[cell] = value
self.assertEqual(value, self.sheet[cell])
def test_out_of_column_bound_write(self):
value = self.get_random_char()
column = self.get_random_char() + self.get_random_char()
cell = "A" + column + str(random.randint(9, 30))
self.sheet[cell] = value
self.assertEqual(value, self.sheet[cell])
def test_out_of_bounds_read(self):
with self.assertRaises(IndexError):
self.sheet[0, 20]
with self.assertRaises(IndexError):
self.sheet[20, 0]
def test_column_edge_case(self):
column = self.sheet.number_of_columns() - 1
self.assertEqual(self.sheet[0, column], f"0_{column}")
with self.assertRaises(IndexError):
self.sheet[0, column + 1]
def test_row_edge_case(self):
row = self.sheet.number_of_rows() - 1
self.assertEqual(self.sheet[row, 0], f"{row}_0")
with self.assertRaises(IndexError):
self.sheet[row + 1, 0]