-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_spreadsheet_to_text.py
40 lines (26 loc) · 1.04 KB
/
test_spreadsheet_to_text.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
import os
from os.path import join, abspath
import openpyxl
from spreadsheet_to_text import spreadsheet_to_text
original_wd = abspath(os.getcwd())
test_wd = join(abspath('.'), 'spreadsheet_to_text', 'test_files')
def test_spreadsheet_to_text():
setup_directory()
spreadsheet_to_text.spreadsheet_to_text('test_text_to_sheet.xlsx')
result_files = [file for file in os.listdir() if file.lower().endswith('.txt')]
wb = openpyxl.load_workbook('test_text_to_sheet.xlsx')
sheet = wb.active
assert sheet.max_column == len(result_files)
for column in sheet.columns:
with open(f'{column[0].value}', 'r') as reader:
lines = [cell.value for cell in column[1:] if cell.value]
for line in lines:
assert line == reader.readline()
revert_directory()
def setup_directory():
os.chdir(test_wd)
def revert_directory():
result_files = [file for file in os.listdir() if file.lower().endswith('.txt')]
for file in result_files:
os.remove(file)
os.chdir(original_wd)