@@ -84,3 +84,77 @@ def test_flake8_executable_param(workspace):
8484
8585 call_args = popen_mock .call_args .args [0 ]
8686 assert flake8_executable in call_args
87+
88+
89+ def get_flake8_cfg_settings (workspace , config_str ):
90+ """Write a ``setup.cfg``, load it in the workspace, and return the flake8 settings.
91+
92+ This function creates a ``setup.cfg``; you'll have to delete it yourself.
93+ """
94+
95+ with open (os .path .join (workspace .root_path , "setup.cfg" ), "w+" ) as f :
96+ f .write (config_str )
97+
98+ workspace .update_config ({"pyls" : {"configurationSources" : ["flake8" ]}})
99+
100+ return workspace ._config .plugin_settings ("flake8" )
101+
102+
103+ def test_flake8_multiline (workspace ):
104+ config_str = r"""[flake8]
105+ exclude =
106+ blah/,
107+ file_2.py
108+ """
109+
110+ doc_str = "print('hi')\n import os\n "
111+
112+ doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
113+ workspace .put_document (doc_uri , doc_str )
114+
115+ flake8_settings = get_flake8_cfg_settings (workspace , config_str )
116+
117+ assert "exclude" in flake8_settings
118+ assert len (flake8_settings ["exclude" ]) == 2
119+
120+ with patch ('pyls.plugins.flake8_lint.Popen' ) as popen_mock :
121+ mock_instance = popen_mock .return_value
122+ mock_instance .communicate .return_value = [bytes (), bytes ()]
123+
124+ doc = workspace .get_document (doc_uri )
125+ flake8_lint .pyls_lint (workspace , doc )
126+
127+ call_args = popen_mock .call_args .args [0 ]
128+ assert call_args == ["flake8" , "-" , "--exclude=blah/,file_2.py" ]
129+
130+ os .unlink (os .path .join (workspace .root_path , "setup.cfg" ))
131+
132+
133+ def test_flake8_per_file_ignores (workspace ):
134+ config_str = r"""[flake8]
135+ ignores = F403
136+ per-file-ignores =
137+ **/__init__.py:F401,E402
138+ test_something.py:E402,
139+ exclude =
140+ file_1.py
141+ file_2.py
142+ """
143+
144+ doc_str = "print('hi')\n import os\n "
145+
146+ doc_uri = uris .from_fs_path (os .path .join (workspace .root_path , "blah/__init__.py" ))
147+ workspace .put_document (doc_uri , doc_str )
148+
149+ flake8_settings = get_flake8_cfg_settings (workspace , config_str )
150+
151+ assert "perFileIgnores" in flake8_settings
152+ assert len (flake8_settings ["perFileIgnores" ]) == 2
153+ assert "exclude" in flake8_settings
154+ assert len (flake8_settings ["exclude" ]) == 2
155+
156+ doc = workspace .get_document (doc_uri )
157+ res = flake8_lint .pyls_lint (workspace , doc )
158+ assert len (res ) == 0
159+
160+ os .unlink (os .path .join (workspace .root_path , "setup.cfg" ))
0 commit comments