def test_process_files__select(self): options = {'select': 'W603'} self.tool = Pep8(self.problems, options, root_dir) self.tool.process_files([self.fixtures[1]]) problems = self.problems.all(self.fixtures[1]) eq_(1, len(problems)) for p in problems: assert_in('W603', p.body)
def test_process_files__line_length(self): options = {'max-line-length': '10'} self.tool = Pep8(self.problems, options, root_dir) self.tool.process_files([self.fixtures[1]]) problems = self.problems.all(self.fixtures[1]) eq_(10, len(problems)) expected = Comment(self.fixtures[1], 1, 1, 'E501 line too long (23 > 10 characters)') eq_(expected, problems[0])
def test_process_files__ignore(self): options = {'ignore': 'E2,W603'} self.tool = Pep8(self.problems, options, root_dir) self.tool.process_files([self.fixtures[1]]) problems = self.problems.all(self.fixtures[1]) eq_(4, len(problems)) for p in problems: assert_not_in('E2', p.body) assert_not_in('W603', p.body)
def test_execute_fixer(self): tool = Pep8(self.problems, {'fixer': True}, root_dir) original = read_file(self.fixtures[1]) tool.execute_fixer(self.fixtures) updated = read_and_restore_file(self.fixtures[1], original) assert original != updated, 'File content should change.' eq_(0, len(self.problems.all()), 'No errors should be recorded')
def test_config_options_and_process_file(self): options = {'ignore': 'E2,W603'} self.tool = Pep8(self.problems, options) self.tool.process_files([self.fixtures[1]]) problems = self.problems.all(self.fixtures[1]) eq_(4, len(problems)) for p in problems: self.assertFalse('E2' in p.body) self.assertFalse('W603' in p.body)
def test_execute_fixer__python3(self): options = {'fixer': True, 'python': 3} tool = Pep8(self.problems, options, root_dir) original = read_file(self.fixtures[1]) tool.execute_fixer(self.fixtures) updated = read_and_restore_file(self.fixtures[1], original) assert original != updated, 'File content should change.' self.assertEqual(0, len(self.problems.all()), 'No errors should be recorded')
def test_execute_fixer__fewer_problems_remain(self): tool = Pep8(self.problems, {'fixer': True}, root_dir) # The fixture file can have all problems fixed by autopep8 original = read_file(self.fixtures[1]) tool.execute_fixer(self.fixtures) tool.process_files(self.fixtures) read_and_restore_file(self.fixtures[1], original) self.assertGreaterEqual(len(self.problems.all()), 0, 'Most errors should be fixed')
def test_execute_fixer__fewer_problems_remain(self): tool = Pep8(self.problems, {'fixer': True}, root_dir) # The fixture file can have all problems fixed by autopep8 original = read_file(self.fixtures[1]) tool.execute_fixer(self.fixtures) tool.process_files(self.fixtures) read_and_restore_file(self.fixtures[1], original) assert len(self.problems.all()) > 0, 'Most errors should be fixed' text = [c.body for c in self.problems.all()] assert_in("'<>' is deprecated", ' '.join(text))
def test_execute_fixer__options(self): tool = Pep8(self.problems, { 'fixer': True, 'max-line-length': 120, 'exclude': 'W201' }, root_dir) original = read_file(self.fixtures[1]) tool.execute_fixer(self.fixtures) updated = read_and_restore_file(self.fixtures[1], original) assert original != updated, 'File content should change.' eq_(0, len(self.problems.all()), 'No errors should be recorded')
def test_execute_fixer__fewer_problems_remain__python3(self): options = {'fixer': True, 'python': 3} tool = Pep8(self.problems, options, root_dir) # The fixture file can have all problems fixed by autopep8 original = read_file(self.fixtures[1]) tool.execute_fixer(self.fixtures) tool.process_files(self.fixtures) read_and_restore_file(self.fixtures[1], original) self.assertLessEqual(1, len(self.problems.all()), 'Most errors should be fixed') text = [c.body for c in self.problems.all()] self.assertIn("'<>' is deprecated", ' '.join(text))
def setUp(self): self.problems = Problems() self.tool = Pep8(self.problems, {}, root_dir)
def test_has_fixer__enabled(self): tool = Pep8(self.problems, {'fixer': True}) eq_(True, tool.has_fixer())
def test_has_fixer__not_enabled(self): tool = Pep8(self.problems, {}) eq_(False, tool.has_fixer())
def test_has_fixer__enabled(self): tool = Pep8(self.problems, {'fixer': True}) self.assertEqual(True, tool.has_fixer())
def test_has_fixer__not_enabled(self): tool = Pep8(self.problems, {}) self.assertEqual(False, tool.has_fixer())
def setUp(self): self.problems = Problems() self.tool = Pep8(self.problems)