Add flake8-ycm to test requirements

Fix errors reported by flake8-ycm.
This commit is contained in:
micbou 2018-05-30 01:00:49 +02:00
parent 8e448920c9
commit 6b4d705238
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
15 changed files with 131 additions and 129 deletions

View File

@ -1,5 +1,6 @@
flake8 >= 3.0.0
flake8-comprehensions >= 1.4.1
flake8-ycm >= 0.1.0
mock >= 1.0.1
nose >= 1.3.7
PyHamcrest >= 1.8.0

View File

@ -32,7 +32,7 @@ from ycmd.utils import ToBytes, urljoin, urlparse, GetCurrentDirectory
from ycmd.hmac_utils import CreateRequestHmac, CreateHmac, SecureBytesEqual
from ycmd.responses import ServerError, UnknownExtraConf
_HEADERS = {'content-type': 'application/json'}
_HEADERS = { 'content-type': 'application/json' }
_CONNECT_TIMEOUT_SEC = 0.01
# Setting this to None seems to screw up the Requests/urllib3 libs.
_READ_TIMEOUT_SEC = 30

View File

@ -94,7 +94,7 @@ def _FormatCompleterDebugInfo( completer ):
message += ' {0} process ID: {1}\n'.format( name, server[ 'pid' ] )
else:
message += ' {0} not running\n'.format( name )
message += ' {0} executable: {1}\n'.format( name, server[ 'executable'] )
message += ' {0} executable: {1}\n'.format( name, server[ 'executable' ] )
logfiles = server[ 'logfiles' ]
if logfiles:
message += ' {0} logfiles:\n'.format( name )

View File

@ -42,7 +42,7 @@ SYNTAX_ARGUMENT_REGEX = re.compile(
r"^\w+=.*$" )
SYNTAX_REGION_ARGUMENT_REGEX = re.compile(
r"^(?:matchgroup|start)=.*$")
r"^(?:matchgroup|start)=.*$" )
# See ":h syn-nextgroup".
SYNTAX_NEXTGROUP_ARGUMENTS = {
@ -106,7 +106,7 @@ def _SyntaxGroupsFromOutput( syntax_output ):
group_name_to_group[ current_group.name ] = current_group
current_group = SyntaxGroup( match.group( 'group_name' ),
[ match.group( 'content').strip() ] )
[ match.group( 'content' ).strip() ] )
else:
if looking_for_group:
continue

View File

@ -35,7 +35,7 @@ from ycm import base
@contextlib.contextmanager
def MockCurrentFiletypes( filetypes = [''] ):
def MockCurrentFiletypes( filetypes = [ '' ] ):
with patch( 'ycm.vimsupport.CurrentFiletypes', return_value = filetypes ):
yield
@ -180,7 +180,7 @@ def LastEnteredCharIsIdentifierChar_Basic_test():
def LastEnteredCharIsIdentifierChar_FiletypeHtml_test():
with MockCurrentFiletypes( ['html'] ):
with MockCurrentFiletypes( [ 'html' ] ):
with MockCurrentColumnAndLineContents( 3, 'ab-' ):
ok_( base.LastEnteredCharIsIdentifierChar() )
@ -272,7 +272,7 @@ def CurrentIdentifierFinished_InMiddleOfLine_test():
def CurrentIdentifierFinished_Html_test():
with MockCurrentFiletypes( ['html'] ):
with MockCurrentFiletypes( [ 'html' ] ):
with MockCurrentColumnAndLineContents( 4, 'bar-zoo' ):
ok_( not base.CurrentIdentifierFinished() )

View File

@ -65,7 +65,7 @@ def RawResponse_ConvertedFromOmniCompleter_test():
{ "word": "WORD2", "abbr": "ABBR2", "menu": "MENU2",
"kind": "KIND2", "info": "INFO" },
{ "word": "WORD", "abbr": "ABBR", },
{ },
{},
]
expected_results = [
has_entries( { "insertion_text": "WORD", "menu_text": "ABBR",
@ -75,7 +75,7 @@ def RawResponse_ConvertedFromOmniCompleter_test():
"extra_menu_info": "MENU2", "kind": [ "KIND2" ],
"detailed_info": "INFO" } ),
has_entries( { "insertion_text": "WORD", "menu_text": "ABBR", } ),
has_entries( { } ),
has_entries( {} ),
]
request = BuildOmnicompletionRequest( vim_results )

View File

@ -389,7 +389,7 @@ def PostCompleteFixIt_ApplyFixIt_EmptyFixIt_test( replace_chunks, *args ):
@patch( 'ycm.vimsupport.ReplaceChunks' )
def PostCompleteFixIt_ApplyFixIt_NoFixIt_test( replace_chunks, *args ):
completions = [
BuildCompletion( )
BuildCompletion()
]
with _SetUpCompleteDone( completions ) as request:
request._OnCompleteDone_FixIt()

View File

@ -1114,17 +1114,17 @@ def ReplaceChunks_User_Aborts_Opening_File_test(
False, # second_file (apply)
True, # side_effect (check after open)
],
new_callable = ExtendedMock)
new_callable = ExtendedMock )
@patch( 'ycm.vimsupport.OpenFilename',
new_callable = ExtendedMock)
new_callable = ExtendedMock )
@patch( 'ycm.vimsupport.PostVimMessage',
new_callable = ExtendedMock)
new_callable = ExtendedMock )
@patch( 'ycm.vimsupport.Confirm', return_value = True,
new_callable = ExtendedMock)
new_callable = ExtendedMock )
@patch( 'vim.eval', return_value = 10,
new_callable = ExtendedMock)
new_callable = ExtendedMock )
@patch( 'vim.command',
new_callable = ExtendedMock)
new_callable = ExtendedMock )
def ReplaceChunks_MultiFile_Open_test( vim_command,
vim_eval,
confirm,
@ -1295,7 +1295,7 @@ def AddDiagnosticSyntaxMatch_UnicodeAtEndOfLine_test():
@patch( 'vim.command', new_callable=ExtendedMock )
@patch( 'vim.current', new_callable=ExtendedMock)
@patch( 'vim.current', new_callable=ExtendedMock )
def WriteToPreviewWindow_test( vim_current, vim_command ):
vim_current.window.options.__getitem__ = MagicMock( return_value = True )
@ -1534,7 +1534,7 @@ def SelectFromList_FirstItem_test( vim_eval ):
@patch( 'vim.eval', side_effect = [ None, 3, None ] )
def SelectFromList_OutOfRange_test( vim_eval ):
assert_that( calling( vimsupport.SelectFromList).with_args( 'test',
assert_that( calling( vimsupport.SelectFromList ).with_args( 'test',
[ 'a', 'b' ] ),
raises( RuntimeError, vimsupport.NO_SELECTION_MADE_MSG ) )

View File

@ -28,30 +28,30 @@ except ImportError:
# only send network requests). The YCM workload is one of those workloads where
# it's safe (the aforementioned network requests case).
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):
class _WorkItem( object ):
def __init__( self, future, fn, args, kwargs ):
self.future = future
self.fn = fn
self.args = args
self.kwargs = kwargs
def run(self):
def run( self ):
if not self.future.set_running_or_notify_cancel():
return
try:
result = self.fn(*self.args, **self.kwargs)
result = self.fn( *self.args, **self.kwargs )
except BaseException:
e = sys.exc_info()[1]
self.future.set_exception(e)
e = sys.exc_info()[ 1 ]
self.future.set_exception( e )
else:
self.future.set_result(result)
self.future.set_result( result )
def _worker(executor_reference, work_queue):
def _worker( executor_reference, work_queue ):
try:
while True:
work_item = work_queue.get(block=True)
work_item = work_queue.get( block=True )
if work_item is not None:
work_item.run()
continue
@ -61,15 +61,15 @@ def _worker(executor_reference, work_queue):
# - The executor that owns the worker has been shutdown.
if executor is None or executor._shutdown:
# Notice other workers
work_queue.put(None)
work_queue.put( None )
return
del executor
except BaseException:
_base.LOGGER.critical('Exception in worker', exc_info=True)
_base.LOGGER.critical( 'Exception in worker', exc_info=True )
class UnsafeThreadPoolExecutor(_base.Executor):
def __init__(self, max_workers):
class UnsafeThreadPoolExecutor( _base.Executor ):
def __init__( self, max_workers ):
"""Initializes a new ThreadPoolExecutor instance.
Args:
@ -82,38 +82,38 @@ class UnsafeThreadPoolExecutor(_base.Executor):
self._shutdown = False
self._shutdown_lock = threading.Lock()
def submit(self, fn, *args, **kwargs):
def submit( self, fn, *args, **kwargs ):
with self._shutdown_lock:
if self._shutdown:
raise RuntimeError('cannot schedule new futures after shutdown')
raise RuntimeError( 'cannot schedule new futures after shutdown' )
f = _base.Future()
w = _WorkItem(f, fn, args, kwargs)
w = _WorkItem( f, fn, args, kwargs )
self._work_queue.put(w)
self._work_queue.put( w )
self._adjust_thread_count()
return f
submit.__doc__ = _base.Executor.submit.__doc__
def _adjust_thread_count(self):
def _adjust_thread_count( self ):
# When the executor gets lost, the weakref callback will wake up
# the worker threads.
def weakref_cb(_, q=self._work_queue):
q.put(None)
def weakref_cb( _, q=self._work_queue ):
q.put( None )
# TODO(bquinlan): Should avoid creating new threads if there are more
# idle threads than items in the work queue.
if len(self._threads) < self._max_workers:
t = threading.Thread(target=_worker,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
if len( self._threads ) < self._max_workers:
t = threading.Thread( target=_worker,
args=( weakref.ref( self, weakref_cb ),
self._work_queue ) )
t.daemon = True
t.start()
self._threads.add(t)
self._threads.add( t )
def shutdown(self, wait=True):
def shutdown( self, wait=True ):
with self._shutdown_lock:
self._shutdown = True
self._work_queue.put(None)
self._work_queue.put( None )
if wait:
for t in self._threads:
t.join()

View File

@ -941,7 +941,7 @@ def ReplaceChunk( start, end, replacement_text, vim_buffer ):
replacement_lines[ 0 ] = start_existing_text + replacement_lines[ 0 ]
replacement_lines[ -1 ] = replacement_lines[ -1 ] + end_existing_text
vim_buffer[ start_line : end_line + 1 ] = replacement_lines[:]
vim_buffer[ start_line : end_line + 1 ] = replacement_lines[ : ]
return {
'bufnr': vim_buffer.number,
@ -977,7 +977,8 @@ def InsertNamespace( namespace ):
def SearchInCurrentBuffer( pattern ):
""" Returns the 1-indexed line on which the pattern matches
(going UP from the current position) or 0 if not found """
return GetIntValue( "search('{0}', 'Wcnb')".format( EscapeForVim( pattern )))
return GetIntValue(
"search('{0}', 'Wcnb')".format( EscapeForVim( pattern ) ) )
def LineTextInCurrentBuffer( line_number ):
@ -1033,7 +1034,7 @@ def WriteToPreviewWindow( message ):
vim.current.buffer.options[ 'modifiable' ] = True
vim.current.buffer.options[ 'readonly' ] = False
vim.current.buffer[:] = message.splitlines()
vim.current.buffer[ : ] = message.splitlines()
vim.current.buffer.options[ 'buftype' ] = 'nofile'
vim.current.buffer.options[ 'bufhidden' ] = 'wipe'

View File

@ -53,9 +53,9 @@ from ycm.client.messages_request import MessagesPoll
def PatchNoProxy():
current_value = os.environ.get('no_proxy', '')
current_value = os.environ.get( 'no_proxy', '' )
additions = '127.0.0.1,localhost'
os.environ['no_proxy'] = ( additions if not current_value
os.environ[ 'no_proxy' ] = ( additions if not current_value
else current_value + ',' + additions )