浏览代码

Style refactor and cleanup

dhleong 8 年之前
父节点
当前提交
18a25d45b3
共有 2 个文件被更改,包括 35 次插入49 次删除
  1. 11 13
      python/ycm/diagnostic_filter.py
  2. 24 36
      python/ycm/tests/diagnostic_filter_tests.py

+ 11 - 13
python/ycm/diagnostic_filter.py

@@ -32,20 +32,18 @@ class DiagnosticFilter( object ):
     self._filters = []
 
     for filter_type in iterkeys( config ):
-      actual_filter_type = filter_type
       compiler = FILTER_COMPILERS.get( filter_type )
 
       if compiler is not None:
-        for filter_config in _ListOf( config[ actual_filter_type ] ):
-          fn = compiler( filter_config )
-          self._filters.append( fn )
+        for filter_config in _ListOf( config[ filter_type ] ):
+          compiledFilter = compiler( filter_config )
+          self._filters.append( compiledFilter )
 
 
   def IsAllowed( self, diagnostic ):
-    # NOTE: a diagnostic IsAllowed() ONLY if
-    #  NO filters match it
-    for f in self._filters:
-      if f( diagnostic ):
+    # NOTE: a diagnostic IsAllowed() ONLY if NO filters match it
+    for filterMatches in self._filters:
+      if filterMatches( diagnostic ):
         return False
 
     return True
@@ -57,8 +55,8 @@ class DiagnosticFilter( object ):
     all_filters = dict( user_options.get( 'filter_diagnostics', {} ) )
     for typeSpec, filterValue in iteritems( dict( all_filters ) ):
       if typeSpec.find(',') != -1:
-        for ft in typeSpec.split(','):
-          all_filters[ ft ] = filterValue
+        for filetype in typeSpec.split(','):
+          all_filters[ filetype ] = filterValue
 
     for filetype in filetypes:
       type_specific = all_filters.get( filetype, {} )
@@ -77,8 +75,8 @@ def _ListOf( config_entry ):
 
 
 def _Merge( into, other ):
-  for k in iterkeys( other ):
-    into[k] = _ListOf( into.get( k ) ) + _ListOf( other[ k ] )
+  for key in iterkeys( other ):
+    into[ key ] = _ListOf( into.get( key ) ) + _ListOf( other[ key ] )
 
   return into
 
@@ -95,7 +93,7 @@ def _CompileRegex( raw_regex ):
 def _CompileLevel( level ):
   # valid kinds are WARNING and ERROR;
   #  expected input levels are `warning` and `error`
-  # NB: we don't validate the input...
+  # NOTE: we don't validate the input...
   expected_kind = level.upper()
 
   def FilterLevel( diagnostic ):

+ 24 - 36
python/ycm/tests/diagnostic_filter_tests.py

@@ -23,9 +23,6 @@ from future import standard_library
 standard_library.install_aliases()
 from builtins import *  # noqa
 
-from ycm.test_utils import MockVimModule
-MockVimModule()
-
 from hamcrest import assert_that, equal_to
 from ycm.diagnostic_filter import DiagnosticFilter
 
@@ -57,49 +54,40 @@ def RegexFilter_test():
   _assert_accepts( f, 'This is a Burrito' )
 
 
-class ListOrSingle_test():
-  # NB: we already test the single config above
-
-  def ListOrSingle_SingleList_test( self ):
-    # NB: if the filetype doesn't override the global,
-    #  we would reject burrito and accept taco
-    opts = _JavaFilter( { 'regex' : [ 'taco' ] }  )
-    f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
-
-    _assert_rejects( f, 'This is a Taco' )
-    _assert_accepts( f, 'This is a Burrito' )
+def RegexSingleList_test():
+  opts = _JavaFilter( { 'regex' : [ 'taco' ] }  )
+  f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
 
+  _assert_rejects( f, 'This is a Taco' )
+  _assert_accepts( f, 'This is a Burrito' )
 
-  def ListOrSingle_MultiList_test( self ):
-    # NB: if the filetype doesn't override the global,
-    #  we would reject burrito and accept taco
-    opts = _JavaFilter( { 'regex' : [ 'taco', 'burrito' ] } )
-    f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
 
-    _assert_rejects( f, 'This is a Taco' )
-    _assert_rejects( f, 'This is a Burrito' )
+def RegexMultiList_test():
+  opts = _JavaFilter( { 'regex' : [ 'taco', 'burrito' ] } )
+  f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
 
+  _assert_rejects( f, 'This is a Taco' )
+  _assert_rejects( f, 'This is a Burrito' )
 
-class Level_test():
 
-  def Level_warnings_test( self ):
-    opts = _JavaFilter( { 'level' : 'warning' } )
-    f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
+def LevelWarnings_test():
+  opts = _JavaFilter( { 'level' : 'warning' } )
+  f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
 
-    _assert_rejects( f, { 'text' : 'This is an unimportant taco',
-                          'kind' : 'WARNING' } )
-    _assert_accepts( f, { 'text' : 'This taco will be shown',
-                          'kind' : 'ERROR' } )
+  _assert_rejects( f, { 'text' : 'This is an unimportant taco',
+                        'kind' : 'WARNING' } )
+  _assert_accepts( f, { 'text' : 'This taco will be shown',
+                        'kind' : 'ERROR' } )
 
 
-  def Level_errors_test( self ):
-    opts = _JavaFilter( { 'level' : 'error' } )
-    f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
+def LevelErrors_test():
+  opts = _JavaFilter( { 'level' : 'error' } )
+  f = DiagnosticFilter.from_filetype( opts, [ 'java' ] )
 
-    _assert_accepts( f, { 'text' : 'This is an IMPORTANT taco',
-                          'kind' : 'WARNING' } )
-    _assert_rejects( f, { 'text' : 'This taco will NOT be shown',
-                          'kind' : 'ERROR' } )
+  _assert_accepts( f, { 'text' : 'This is an IMPORTANT taco',
+                        'kind' : 'WARNING' } )
+  _assert_rejects( f, { 'text' : 'This taco will NOT be shown',
+                        'kind' : 'ERROR' } )
 
 
 def MultipleFilterTypesTypeTest_test():