Esempio n. 1
0
 def test_config_options_and_process_file(self):
     options = {'ignore': 'F4,W603', 'config': ''}
     self.tool = Flake8(self.problems, options)
     self.tool.process_files([self.fixtures[1]])
     problems = self.problems.all(self.fixtures[1])
     eq_(5, len(problems))
     for p in problems:
         self.assertFalse('F4' in p.body)
         self.assertFalse('W603' in p.body)
Esempio n. 2
0
    def test_execute_fixer(self):
        tool = Flake8(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')
Esempio n. 3
0
 def test_execute_config_with_format(self):
     tool = Flake8(self.problems,
                   {'config': 'tests/fixtures/pep8/flake8_bad_format.ini'},
                   root_dir)
     fixtures = ['/src/' + path for path in self.fixtures]
     tool.process_files(fixtures)
     problems = self.problems.all(self.fixtures[1])
     assert len(problems), 'should have problems'
     for issue in problems:
         assert 'W302' not in issue.body
Esempio n. 4
0
 def test_config_options_and_process_file(self):
     options = {
         'ignore': 'F4,W603',
     }
     self.tool = Flake8(self.problems, options, root_dir)
     self.tool.process_files([self.fixtures[1]])
     problems = self.problems.all(self.fixtures[1])
     assert len(problems) >= 5
     for p in problems:
         self.assertFalse('F4' in p.body)
         self.assertFalse('W603' in p.body)
Esempio n. 5
0
    def test_execute_fixer__python3(self):
        options = {'fixer': True, 'python': 3}
        tool = Flake8(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')
Esempio n. 6
0
    def test_execute_fixer__fewer_problems_remain(self):
        tool = Flake8(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 1 < len(self.problems.all()), 'Most errors should be fixed'

        text = [c.body for c in self.problems.all()]
        assert_in("'<>' is deprecated", ' '.join(text))
Esempio n. 7
0
 def test_make_command__no_config(self):
     options = {
         'ignore': 'F4,W603',
         'max-line-length': 120,
         'max-complexity': 10
     }
     tool = Flake8(self.problems, options, root_dir)
     out = tool.make_command([self.fixtures[1]])
     expected = [
         'flake8', '--ignore', 'F4,W603', '--max-complexity', 10,
         '--max-line-length', 120, '--isolated', self.fixtures[1]
     ]
     self.assertEqual(set(expected), set(out))
Esempio n. 8
0
 def test_make_command__config(self):
     options = {
         'ignore': 'F4,W603',
         'max-line-length': 120,
         'max-complexity': 10
     }
     tool = Flake8(self.problems, options)
     out = tool.make_command([self.fixtures[1]])
     expected = [
         'flake8', '--ignore', 'F4,W603', '--max-complexity', 10,
         '--max-line-length', 120, self.fixtures[1]
     ]
     eq_(expected, out)
Esempio n. 9
0
    def test_execute_fixer__fewer_problems_remain__python3(self):
        options = {'fixer': True, 'python': 3}
        tool = Flake8(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.assertGreaterEqual(len(self.problems.all()), 1,
                                'Most errors should be fixed')

        text = [c.body for c in self.problems.all()]
        self.assertIn("'<>' is deprecated", ' '.join(text))
Esempio n. 10
0
 def test_make_command__config(self):
     options = {
         'ignore': 'F4,W603',
         'max-line-length': 120,
         'max-complexity': 10,
         'config': '.flake8'
     }
     tool = Flake8(self.problems, options, root_dir)
     out = tool.make_command([self.fixtures[1]])
     expected = [
         'flake8', '--ignore', 'F4,W603', '--max-complexity', 10,
         '--max-line-length', 120, '--config', '.flake8', '--format',
         'default', self.fixtures[1]
     ]
     eq_(set(expected), set(out))
Esempio n. 11
0
 def test_has_fixer__not_enabled(self):
     tool = Flake8(self.problems, {}, root_dir)
     eq_(False, tool.has_fixer())
Esempio n. 12
0
 def setUp(self):
     self.problems = Problems()
     self.tool = Flake8(self.problems, {}, root_dir)
Esempio n. 13
0
 def test_has_fixer__enabled(self):
     tool = Flake8(self.problems, {'fixer': True}, root_dir)
     eq_(True, tool.has_fixer())
Esempio n. 14
0
 def setUp(self):
     self.problems = Problems()
     self.tool = Flake8(self.problems, options={'config': ''})
Esempio n. 15
0
 def setUp(self):
     self.problems = Problems()
     self.tool = Flake8(self.problems)