class TestExcluder(BaseTest): def setUp(self): super(TestExcluder, self).setUp() excludes_text = textwrap.dedent(""" # ignore C++ .*\.cpp::.* # ignore python .*\.py::Flake8 """) self.excluder = FileExcluder( self._create_scalastyle_excludes_file([excludes_text]), logger) def _create_scalastyle_excludes_file(self, exclude_patterns=None): return self.create_file( relpath='scalastyle_excludes.txt', contents='\n'.join(exclude_patterns) if exclude_patterns else '') def test_excludes_cpp_any(self): self.assertFalse(self.excluder.should_include('test/file.cpp', '.*')) def test_excludes_cpp_flake8(self): self.assertFalse( self.excluder.should_include('test/file.cpp', 'Flake8')) def test_excludes_python_flake8(self): self.assertFalse(self.excluder.should_include('test/file.py', 'Flake8')) def test_excludes_python_trailingws(self): self.assertTrue( self.excluder.should_include('test/file.py', 'TrailingWhiteSpace'))
class TestExcluder(BaseTest): def setUp(self): super(TestExcluder, self).setUp() excludes_text = textwrap.dedent(""" # ignore C++ .*\.cpp::.* # ignore python .*\.py::Flake8 """) self.excluder = FileExcluder( self._create_scalastyle_excludes_file([excludes_text]), logger) def _create_scalastyle_excludes_file(self, exclude_patterns=None): return self.create_file( relpath='scalastyle_excludes.txt', contents='\n'.join(exclude_patterns) if exclude_patterns else '') def test_excludes_cpp_any(self): self.assertFalse(self.excluder.should_include('test/file.cpp', '.*')) def test_excludes_cpp_flake8(self): self.assertFalse(self.excluder.should_include('test/file.cpp', 'Flake8')) def test_excludes_python_flake8(self): self.assertFalse(self.excluder.should_include('test/file.py', 'Flake8')) def test_excludes_python_trailingws(self): self.assertTrue(self.excluder.should_include('test/file.py', 'TrailingWhiteSpace'))
class TestExcluder(PythonTaskTestBase): def task_type(cls): """Required method""" return PythonCheckStyleTask def setUp(self, *args, **kwargs): super(TestExcluder, self).setUp(*args, **kwargs) excludes_text = textwrap.dedent(''' # ignore C++ .*\.cpp::.* # ignore python .*\.py::Flake8''') self.excluder = FileExcluder( self._create_scalastyle_excludes_file([excludes_text]), logger) def _create_scalastyle_excludes_file(self, exclude_patterns=None): return self.create_file( relpath='scalastyle_excludes.txt', contents='\n'.join(exclude_patterns) if exclude_patterns else '') def test_excludes_cpp_any(self): assert not self.excluder.should_include('test/file.cpp', '.*') def test_excludes_cpp_flake8(self): assert not self.excluder.should_include('test/file.cpp', 'Flake8') def test_excludes_python_flake8(self): assert not self.excluder.should_include('test/file.py', 'Flake8') def test_excludes_python_trailingws(self): assert self.excluder.should_include('test/file.py', 'TrailingWhiteSpace')
class TestExcluder(PythonTaskTestBase): def task_type(cls): """Required method""" return PythonCheckStyleTask def setUp(self, *args, **kwargs): super(TestExcluder, self).setUp(*args, **kwargs) excludes_text = textwrap.dedent(''' # ignore C++ .*\.cpp::.* # ignore python .*\.py::Flake8''') self.excluder = FileExcluder( self._create_scalastyle_excludes_file([excludes_text]), logger) def _create_scalastyle_excludes_file(self, exclude_patterns=None): return self.create_file( relpath='scalastyle_excludes.txt', contents='\n'.join(exclude_patterns) if exclude_patterns else '') def test_excludes_cpp_any(self): assert not self.excluder.should_include('test/file.cpp', '.*') def test_excludes_cpp_flake8(self): assert not self.excluder.should_include('test/file.cpp', 'Flake8') def test_excludes_python_flake8(self): assert not self.excluder.should_include('test/file.py', 'Flake8') def test_excludes_python_trailingws(self): assert self.excluder.should_include('test/file.py', 'TrailingWhiteSpace')
def get_nits(self, python_file): """Iterate over the instances style checker and yield Nits :param python_file: PythonFile Object """ if noqa_file_filter(python_file): return if self.options.suppress: # Filter out any suppressed plugins excluder = FileExcluder(self.options.suppress, self.context.log) check_plugins = [plugin for plugin in self._plugins if excluder.should_include(python_file.filename, plugin['name'])] else: check_plugins = self._plugins for plugin in check_plugins: if plugin['checker'].subsystem.global_instance().get_options().skip: return for nit in plugin['checker'](python_file): if nit._line_number is None: yield nit continue nit_slice = python_file.line_range(nit._line_number) for line_number in range(nit_slice.start, nit_slice.stop): if noqa_line_filter(python_file, line_number): break else: yield nit
def get_nits(self, python_file): """Iterate over the instances style checker and yield Nits :param python_file: PythonFile Object """ if noqa_file_filter(python_file): return if self.options.suppress: # Filter out any suppressed plugins excluder = FileExcluder(self.options.suppress, self.context.log) check_plugins = [ plugin for plugin in self._plugins if excluder.should_include(python_file.filename, plugin.name) ] else: check_plugins = self._plugins for plugin in check_plugins: for nit in plugin.checker(python_file): if nit._line_number is None: yield nit continue nit_slice = python_file.line_range(nit._line_number) for line_number in range(nit_slice.start, nit_slice.stop): if noqa_line_filter(python_file, line_number): break else: yield nit