@@ -52,86 +52,90 @@ def check_isort_ret(ret, ref):
52
52
53
53
54
54
testcases = [
55
- {'name' : 'sorted_correctly_default' ,
56
- 'code' : ('import os\n '
57
- 'from sys import path\n ' ),
58
- 'ref' : []},
59
- {'name' : 'sorted_correctly_alpha' ,
60
- 'config' : 'force_single_line=True\n '
61
- 'force_alphabetical_sort=True\n ' ,
62
- 'code' : 'from sys import path\n '
63
- '\n '
64
- 'import os\n ' ,
65
- 'ref' : []},
66
- {'name' : 'eof_blank_lines' ,
67
- 'code' : 'import os\n '
68
- 'from sys import path\n '
69
- '\n '
70
- '\n '
71
- ' \n ' ,
72
- 'ref' : []},
73
- {'name' : 'imports_requires_blank_line' ,
74
- 'code' : 'from __future__ import division\n '
75
- 'import threading\n '
76
- 'from sys import pid\n ' ,
77
- 'ref' : [(2 , 0 , 'I003 ' )]},
78
- {'name' : 'isortcfg_skip_file' ,
79
- 'config' : 'skip=test.py' ,
80
- 'code' : 'skipped_file' ,
81
- 'ref' : []},
82
- {'name' : 'file_skipped_with_comment' ,
83
- 'code' : '# isort:skip_file' ,
84
- 'ref' : []},
85
- {'name' : 'imports_unexpected_blank_line' ,
86
- 'code' : 'from __future__ import division\n '
87
- '\n '
88
- 'import threading\n '
89
- '\n '
90
- 'from sys import pid\n ' ,
91
- 'ref' : [(4 , 0 , 'I004 ' )]},
92
- {'name' : 'sorted_incorrectly_multiple' ,
93
- 'code' : 'from __future__ import division\n '
94
- 'import os\n '
95
- 'from sys import pid\n '
96
- 'import threading\n '
97
- '\n '
98
- 'import isort\n '
99
- '\n \n \n '
100
- 'def func()\n ' ,
101
- 'ref' : [(2 , 0 , 'I003 ' ),
102
- (4 , 0 , 'I001 ' ),
103
- (9 , 0 , 'I004 ' )]},
104
- {'name' : 'sorted_incorrectly' ,
105
- 'config' : 'force_single_line=True' ,
106
- 'code' : 'from sys import pid\n '
107
- 'import threading' ,
108
- 'ref' : [(2 , 0 , 'I001 ' )]},
109
- {'name' : 'empty_file' ,
110
- 'code' : '\n \n ' ,
111
- 'ref' : []},
112
- {'name' : 'wrapped_imports' ,
113
- 'config' : 'wrap_length=65' ,
114
- 'code' : 'from deluge.common import (fdate, fpcnt, fpeer, fsize, fspeed,\n '
115
- ' ftime, get_path_size, is_infohash,\n '
116
- ' is_ip, is_magnet, is_url)\n ' ,
117
- 'ref' : []},
118
- {'name' : 'force_single_line_imports' ,
119
- 'config' : 'force_alphabetical_sort=True\n '
120
- 'force_single_line=True' ,
121
- 'code' : 'from plone.app.testing import applyProfile\n '
122
- 'from plone.app.testing import FunctionalTesting\n ' ,
123
- 'ref' : []},
124
- {'name' : 'missing_add_imports' ,
125
- 'config' : 'add_imports=from __future__ import unicode_literals' ,
126
- 'code' : 'import os\n ' ,
127
- 'ref' : [(1 , 0 , 'I003' ),
128
- (1 , 0 , 'I005' )]},
55
+ {
56
+ 'name' : 'sorted_correctly_default' ,
57
+ 'code' : ('import os\n ' 'from sys import path\n ' ),
58
+ 'ref' : [],
59
+ },
60
+ {
61
+ 'name' : 'sorted_correctly_alpha' ,
62
+ 'config' : 'force_single_line=True\n ' 'force_alphabetical_sort=True\n ' ,
63
+ 'code' : 'from sys import path\n ' '\n ' 'import os\n ' ,
64
+ 'ref' : [],
65
+ },
66
+ {
67
+ 'name' : 'eof_blank_lines' ,
68
+ 'code' : 'import os\n ' 'from sys import path\n ' '\n ' '\n ' ' \n ' ,
69
+ 'ref' : [],
70
+ },
71
+ {
72
+ 'name' : 'imports_requires_blank_line' ,
73
+ 'code' : 'from __future__ import division\n '
74
+ 'import threading\n '
75
+ 'from sys import pid\n ' ,
76
+ 'ref' : [(2 , 0 , 'I003 ' )],
77
+ },
78
+ {
79
+ 'name' : 'isortcfg_skip_file' ,
80
+ 'config' : 'skip=test.py' ,
81
+ 'code' : 'skipped_file' ,
82
+ 'ref' : [],
83
+ },
84
+ {'name' : 'file_skipped_with_comment' , 'code' : '# isort:skip_file' , 'ref' : []},
85
+ {
86
+ 'name' : 'imports_unexpected_blank_line' ,
87
+ 'code' : 'from __future__ import division\n '
88
+ '\n '
89
+ 'import threading\n '
90
+ '\n '
91
+ 'from sys import pid\n ' ,
92
+ 'ref' : [(4 , 0 , 'I004 ' )],
93
+ },
94
+ {
95
+ 'name' : 'sorted_incorrectly_multiple' ,
96
+ 'code' : 'from __future__ import division\n '
97
+ 'import os\n '
98
+ 'from sys import pid\n '
99
+ 'import threading\n '
100
+ '\n '
101
+ 'import isort\n '
102
+ '\n \n \n '
103
+ 'def func()\n ' ,
104
+ 'ref' : [(2 , 0 , 'I003 ' ), (4 , 0 , 'I001 ' ), (9 , 0 , 'I004 ' )],
105
+ },
106
+ {
107
+ 'name' : 'sorted_incorrectly' ,
108
+ 'config' : 'force_single_line=True' ,
109
+ 'code' : 'from sys import pid\n ' 'import threading' ,
110
+ 'ref' : [(2 , 0 , 'I001 ' )],
111
+ },
112
+ {'name' : 'empty_file' , 'code' : '\n \n ' , 'ref' : []},
113
+ {
114
+ 'name' : 'wrapped_imports' ,
115
+ 'config' : 'wrap_length=65' ,
116
+ 'code' : 'from deluge.common import (fdate, fpcnt, fpeer, fsize, fspeed,\n '
117
+ ' ftime, get_path_size, is_infohash,\n '
118
+ ' is_ip, is_magnet, is_url)\n ' ,
119
+ 'ref' : [],
120
+ },
121
+ {
122
+ 'name' : 'force_single_line_imports' ,
123
+ 'config' : 'force_alphabetical_sort=True\n ' 'force_single_line=True' ,
124
+ 'code' : 'from plone.app.testing import applyProfile\n '
125
+ 'from plone.app.testing import FunctionalTesting\n ' ,
126
+ 'ref' : [],
127
+ },
128
+ {
129
+ 'name' : 'missing_add_imports' ,
130
+ 'config' : 'add_imports=from __future__ import unicode_literals' ,
131
+ 'code' : 'import os\n ' ,
132
+ 'ref' : [(1 , 0 , 'I003' ), (1 , 0 , 'I005' )],
133
+ },
129
134
]
130
135
131
136
132
137
@pytest .mark .parametrize ('mode' , ["file" , "code_string" ])
133
- @pytest .mark .parametrize ('testcase' , testcases ,
134
- ids = [t ['name' ] for t in testcases ])
138
+ @pytest .mark .parametrize ('testcase' , testcases , ids = [t ['name' ] for t in testcases ])
135
139
def test_flake8_isort (tmpdir , testcase , mode ):
136
140
"""Test the code examples in files and directly from string"""
137
141
with tmpdir .as_cwd ():
@@ -151,8 +155,7 @@ def test_flake8_isort(tmpdir, testcase, mode):
151
155
def test_isortcfg_found (tmpdir ):
152
156
(file_path , lines ) = write_python_file (
153
157
tmpdir ,
154
- 'from sys import pid\n '
155
- 'import threading' ,
158
+ 'from sys import pid\n ' 'import threading' ,
156
159
)
157
160
write_isort_cfg (tmpdir , 'force_single_line=True' )
158
161
checker = Flake8Isort (None , file_path , lines )
@@ -162,10 +165,7 @@ def test_isortcfg_found(tmpdir):
162
165
163
166
164
167
def test_isortcfg_not_found (tmpdir ):
165
- (file_path , lines ) = write_python_file (
166
- tmpdir ,
167
- 'from sys import pid, path'
168
- )
168
+ (file_path , lines ) = write_python_file (tmpdir , 'from sys import pid, path' )
169
169
checker = Flake8Isort (None , file_path , lines )
170
170
checker .search_current = False
171
171
checker .config_file = True
@@ -175,18 +175,12 @@ def test_isortcfg_not_found(tmpdir):
175
175
176
176
def test_isort_formatted_output (tmpdir ):
177
177
options = collections .namedtuple (
178
- 'Options' , [
179
- 'no_isort_config' ,
180
- 'isort_show_traceback' ,
181
- 'stdin_display_name'
182
- ]
178
+ 'Options' , ['no_isort_config' , 'isort_show_traceback' , 'stdin_display_name' ]
183
179
)
184
180
185
181
(file_path , lines ) = write_python_file (
186
182
tmpdir ,
187
- 'from __future__ import division\n '
188
- 'import os\n '
189
- 'from sys import pid\n ' ,
183
+ 'from __future__ import division\n ' 'import os\n ' 'from sys import pid\n ' ,
190
184
)
191
185
192
186
diff = ' from __future__ import division\n +\n import os'
@@ -202,12 +196,12 @@ def test_isort_formatted_output(tmpdir):
202
196
203
197
@pytest .mark .parametrize (
204
198
'method_to_write_config' ,
205
- [write_isort_cfg , write_setup_cfg , write_tox_ini , write_pyproject_toml ])
199
+ [write_isort_cfg , write_setup_cfg , write_tox_ini , write_pyproject_toml ],
200
+ )
206
201
def test_if_config_file_is_used (tmpdir , method_to_write_config ):
207
202
(file_path , lines ) = write_python_file (
208
203
tmpdir ,
209
- 'import os\n '
210
- 'from sys import path\n ' ,
204
+ 'import os\n ' 'from sys import path\n ' ,
211
205
)
212
206
method_to_write_config (tmpdir , 'lines_between_types=1' )
213
207
0 commit comments