-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
60 lines (48 loc) · 2.31 KB
/
tests.py
File metadata and controls
60 lines (48 loc) · 2.31 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
from module_utils.ExcelFile import ExcelFile
from os.path import isfile
from os import remove
from datetime import datetime
import unittest
class MyTestCase(unittest.TestCase):
def test_create_excel_file(self):
file_path = 'test/test' + str(datetime.now().timestamp()) + '.xlsx'
e1 = ExcelFile(file_path)
e1.create_empty_excel_file()
self.assertEqual(isfile(file_path), True)
remove(file_path)
def test_call(self):
file_path = 'unexisting/test.xlsx'
with (self.assertRaises(FileNotFoundError)):
e1 = ExcelFile(file_path)
def test_load_excel_file(self):
e1 = ExcelFile('test/test.xlsx')
e1.load_excel_file()
my_cell_value = e1.excel_file['Feuil1']['A1'].value
self.assertEqual(my_cell_value, 'test')
def test_write_in_cell_of_sheet(self):
file_path = 'test/test' + str(datetime.now().timestamp()) + '.xlsx'
e1 = ExcelFile(file_path)
e1.write_in_cell_of_sheet('Sheet', 1, 1, 'test')
self.assertEqual(e1.excel_file['Sheet']['A1'].value, 'test')
remove(file_path)
def test_write_in_cell_of_sheet_already_existing_file(self):
file_path = 'test/test_write_already_existing_file.xlsx'
e1 = ExcelFile(file_path)
e1.write_in_cell_of_sheet('Sheet', 1, 1, 'test')
self.assertEqual(e1.excel_file['Sheet']['A1'].value, 'test')
self.assertEqual(e1.excel_file['Sheet']['G8'].value, 'hello')
e1.write_in_cell_of_sheet('Sheet', 1, 1, '')
def test_write_list_in_line_of_sheet(self):
file_path = 'test/test' + str(datetime.now().timestamp()) + '.xlsx'
e1 = ExcelFile(file_path)
e1.write_list_in_line_of_sheet('Sheet', 3, ['test3', 'test2', 'test3'])
self.assertEqual(e1.excel_file['Sheet']['A3'].value, 'test3')
self.assertEqual(e1.excel_file['Sheet']['B3'].value, 'test2')
self.assertEqual(e1.excel_file['Sheet']['C3'].value, 'test3')
e1.write_list_in_line_of_sheet('Sheet', 7, ['test3', 'test2', 'test3'], start_column=5)
self.assertEqual(e1.excel_file['Sheet']['E7'].value, 'test3')
self.assertEqual(e1.excel_file['Sheet']['F7'].value, 'test2')
self.assertEqual(e1.excel_file['Sheet']['G7'].value, 'test3')
remove(file_path)
if __name__ == '__main__':
unittest.main()