@@ -24,7 +24,6 @@ def get_sheet_lines(self, sheet_name):
24
24
25
25
def read_sheets (self ):
26
26
self .sub_sheet_names = list (self .sheets .keys ())
27
- self .sub_sheet_names .remove (self .main_sheet_name )
28
27
29
28
def test_spreadsheetinput_base_fails ():
30
29
spreadsheet_input = SpreadsheetInput ()
@@ -41,58 +40,54 @@ def test_csv_input(self, tmpdir):
41
40
subsheet = tmpdir .join ('subsheet.csv' )
42
41
subsheet .write ('colC,colD\n cell5,cell6\n cell7,cell8' )
43
42
44
- csvinput = CSVInput (input_name = tmpdir .strpath , main_sheet_name = 'main' )
45
- assert csvinput .main_sheet_name == 'main'
43
+ csvinput = CSVInput (input_name = tmpdir .strpath )
46
44
47
45
csvinput .read_sheets ()
48
46
49
- assert list (csvinput .get_main_sheet_lines ()) == \
47
+ assert csvinput .sub_sheet_names == ['main' , 'subsheet' ]
48
+ assert list (csvinput .get_sheet_lines ('main' )) == \
50
49
[{'colA' : 'cell1' , 'colB' : 'cell2' }, {'colA' : 'cell3' , 'colB' : 'cell4' }]
51
- assert csvinput .sub_sheet_names == ['subsheet' ]
52
50
assert list (csvinput .get_sheet_lines ('subsheet' )) == \
53
51
[{'colC' : 'cell5' , 'colD' : 'cell6' }, {'colC' : 'cell7' , 'colD' : 'cell8' }]
54
52
55
53
def test_xlsx_input (self ):
56
- xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/basic.xlsx' , main_sheet_name = 'main' )
57
- assert xlsxinput .main_sheet_name == 'main'
54
+ xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/basic.xlsx' )
58
55
59
56
xlsxinput .read_sheets ()
60
57
61
- assert list (xlsxinput .get_main_sheet_lines ()) == \
58
+ assert xlsxinput .sub_sheet_names == ['main' , 'subsheet' ]
59
+ assert list (xlsxinput .get_sheet_lines ('main' )) == \
62
60
[{'colA' : 'cell1' , 'colB' : 'cell2' }, {'colA' : 'cell3' , 'colB' : 'cell4' }]
63
- assert xlsxinput .sub_sheet_names == ['subsheet' ]
64
61
assert list (xlsxinput .get_sheet_lines ('subsheet' )) == \
65
62
[{'colC' : 'cell5' , 'colD' : 'cell6' }, {'colC' : 'cell7' , 'colD' : 'cell8' }]
66
63
67
64
def test_xlsx_input_integer (self ):
68
- xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/integer.xlsx' , main_sheet_name = 'main' )
69
- assert xlsxinput .main_sheet_name == 'main'
65
+ xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/integer.xlsx' )
70
66
71
67
xlsxinput .read_sheets ()
72
68
73
- assert list (xlsxinput .get_main_sheet_lines ( )) == \
69
+ assert list (xlsxinput .get_sheet_lines ( 'main' )) == \
74
70
[{'colA' : 1 }]
75
- assert xlsxinput .sub_sheet_names == []
71
+ assert xlsxinput .sub_sheet_names == ['main' ]
76
72
77
73
def test_xlsx_input_formula (self ):
78
74
""" When a forumla is present, we should use the value, rather than the
79
75
formula itself. """
80
76
81
- xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/formula.xlsx' , main_sheet_name = 'main' )
82
- assert xlsxinput .main_sheet_name == 'main'
77
+ xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/formula.xlsx' )
83
78
84
79
xlsxinput .read_sheets ()
85
80
86
- assert list (xlsxinput .get_main_sheet_lines ()) == \
81
+ assert xlsxinput .sub_sheet_names == ['main' , 'subsheet' ]
82
+ assert list (xlsxinput .get_sheet_lines ('main' )) == \
87
83
[{'colA' : 1 , 'colB' : 2 }, {'colA' : 2 , 'colB' : 4 }]
88
- assert xlsxinput .sub_sheet_names == ['subsheet' ]
89
84
assert list (xlsxinput .get_sheet_lines ('subsheet' )) == \
90
85
[{'colC' : 3 , 'colD' : 9 }, {'colC' : 4 , 'colD' : 12 }]
91
86
92
87
93
88
class TestInputFailure (object ):
94
89
def test_csv_no_directory (self ):
95
- csvinput = CSVInput (input_name = 'nonesensedirectory' , main_sheet_name = 'main' )
90
+ csvinput = CSVInput (input_name = 'nonesensedirectory' )
96
91
if sys .version > '3' :
97
92
with pytest .raises (FileNotFoundError ):
98
93
csvinput .read_sheets ()
@@ -101,66 +96,60 @@ def test_csv_no_directory(self):
101
96
csvinput .read_sheets ()
102
97
103
98
def test_csv_no_files (self , tmpdir ):
104
- csvinput = CSVInput (input_name = tmpdir .strpath , main_sheet_name = 'main' )
99
+ csvinput = CSVInput (input_name = tmpdir .strpath )
105
100
with pytest .raises (ValueError ) as e :
106
101
csvinput .read_sheets ()
107
102
assert 'Main sheet' in text_type (e ) and 'not found' in text_type (e )
108
103
109
104
def test_xlsx_no_file (self , tmpdir ):
110
- xlsxinput = XLSXInput (input_name = tmpdir .strpath .join ('test.xlsx' ), main_sheet_name = 'main' )
105
+ xlsxinput = XLSXInput (input_name = tmpdir .strpath .join ('test.xlsx' ))
111
106
if sys .version > '3' :
112
107
with pytest .raises (FileNotFoundError ):
113
108
xlsxinput .read_sheets ()
114
109
else :
115
110
with pytest .raises (IOError ):
116
111
xlsxinput .read_sheets ()
117
112
118
- def test_xlsx_no_main_sheet (self ):
119
- xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/basic.xlsx' , main_sheet_name = 'notmain' )
120
- with pytest .raises (ValueError ) as e :
121
- xlsxinput .read_sheets ()
122
- assert 'Main sheet "notmain" not found in workbook.' in text_type (e )
123
-
124
113
125
114
class TestUnicodeInput (object ):
126
115
def test_csv_input_utf8 (self , tmpdir ):
127
116
main = tmpdir .join ('main.csv' )
128
117
main .write_text ('colA\n éαГ😼𝒞人' , encoding = 'utf8' )
129
- csvinput = CSVInput (input_name = tmpdir .strpath , main_sheet_name = 'main' ) # defaults to utf8
118
+ csvinput = CSVInput (input_name = tmpdir .strpath ) # defaults to utf8
130
119
csvinput .read_sheets ()
131
- assert list (csvinput .get_main_sheet_lines ( )) == \
120
+ assert list (csvinput .get_sheet_lines ( 'main' )) == \
132
121
[{'colA' : 'éαГ😼𝒞人' }]
133
- assert csvinput .sub_sheet_names == []
122
+ assert csvinput .sub_sheet_names == ['main' ]
134
123
135
124
def test_csv_input_latin1 (self , tmpdir ):
136
125
main = tmpdir .join ('main.csv' )
137
126
main .write_text ('colA\n é' , encoding = 'latin-1' )
138
- csvinput = CSVInput (input_name = tmpdir .strpath , main_sheet_name = 'main' )
127
+ csvinput = CSVInput (input_name = tmpdir .strpath )
139
128
csvinput .encoding = 'latin-1'
140
129
csvinput .read_sheets ()
141
- assert list (csvinput .get_main_sheet_lines ( )) == \
130
+ assert list (csvinput .get_sheet_lines ( 'main' )) == \
142
131
[{'colA' : 'é' }]
143
- assert csvinput .sub_sheet_names == []
132
+ assert csvinput .sub_sheet_names == ['main' ]
144
133
145
134
@pytest .mark .xfail (
146
135
sys .version_info < (3 , 0 ),
147
136
reason = 'Python 2 CSV readers does not support UTF-16 (or any encodings with null bytes' )
148
137
def test_csv_input_utf16 (self , tmpdir ):
149
138
main = tmpdir .join ('main.csv' )
150
139
main .write_text ('colA\n éαГ😼𝒞人' , encoding = 'utf16' )
151
- csvinput = CSVInput (input_name = tmpdir .strpath , main_sheet_name = 'main' )
140
+ csvinput = CSVInput (input_name = tmpdir .strpath )
152
141
csvinput .encoding = 'utf16'
153
142
csvinput .read_sheets ()
154
- assert list (csvinput .get_main_sheet_lines ( )) == \
143
+ assert list (csvinput .get_sheet_lines ( 'main' )) == \
155
144
[{'colA' : 'éαГ😼𝒞人' }]
156
- assert csvinput .sub_sheet_names == []
145
+ assert csvinput .sub_sheet_names == ['main' ]
157
146
158
147
def test_xlsx_input_utf8 (self ):
159
148
"""This is an xlsx file saved by OpenOffice. It seems to use UTF8 internally."""
160
- xlsxinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/unicode.xlsx' , main_sheet_name = 'main ' )
149
+ csvinput = XLSXInput (input_name = 'flattentool/tests/fixtures/xlsx/unicode.xlsx' )
161
150
162
- xlsxinput .read_sheets ()
163
- assert list (xlsxinput . get_main_sheet_lines ( ))[0 ]['id' ] == 'éαГ😼𝒞人'
151
+ csvinput .read_sheets ()
152
+ assert list (csvinput . get_sheet_lines ( 'main' ))[0 ]['id' ] == 'éαГ😼𝒞人'
164
153
165
154
166
155
def test_convert_type (recwarn ):
0 commit comments