Пример #1
0
 def test_check_python_file_bad_indentation(self):
     """Test check_python_file() with bad indentation"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, "def foo():\n  pass\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 1)
         self.assertTrue("please run through" in errors[0])
 def test_check_python_file_bad_indentation(self):
     """Test check_python_file() with bad indentation"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, "def foo():\n  pass\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 1)
         self.assertTrue("please run through" in errors[0])
Пример #3
0
 def test_check_python_file_incomp_merge(self):
     """Test check_python_file() with incomplete merge"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, ">>>>>>> \n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 2)
         self.assertTrue("please run through" in errors[0])
         self.assertTrue(":1: error: Incomplete merge found." in errors[1])
 def test_check_python_file_incomp_merge(self):
     """Test check_python_file() with incomplete merge"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, ">>>>>>> \n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 2)
         self.assertTrue("please run through" in errors[0])
         self.assertTrue(":1: error: Incomplete merge found."
                         in errors[1])
 def test_check_python_file_temp_test(self):
     """Test check_python_file() with temp test marker"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, "class MyTest:\n"
                          "    def temp_hide_test_bar():\n        pass\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 1)
         self.assertTrue(":2: Test case has the temp_hide_ prefix"
                         in errors[0])
Пример #6
0
 def test_check_python_file_temp_test(self):
     """Test check_python_file() with temp test marker"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, "class MyTest:\n"
                          "    def temp_hide_test_bar():\n        pass\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 1)
         self.assertTrue(":2: Test case has the temp_hide_ prefix"
                         in errors[0])
 def test_check_python_file_duplicate_tests(self):
     """Test check_python_file() with duplicate tests"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, "class Tests:\n"
                                 "    def test_xyz():\n        pass\n"
                                 "    def test_xyz():\n        pass\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 1)
         self.assertTrue(":4: Test case has multiple tests with "
                         "the same name test_xyz" in errors[0])
Пример #8
0
 def test_check_python_file_duplicate_tests(self):
     """Test check_python_file() with duplicate tests"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, "test.py")
         utils.write_file(fname, "class Tests:\n"
                                 "    def test_xyz():\n        pass\n"
                                 "    def test_xyz():\n        pass\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 1)
         self.assertTrue(":4: Test case has multiple tests with "
                         "the same name test_xyz" in errors[0])
 def test_check_example_no_doxygen(self):
     """Test Python example with missing doxygen comments"""
     with utils.TempDir() as tmpdir:
         os.mkdir(os.path.join(tmpdir, 'examples'))
         fname = os.path.join(tmpdir, "examples", "my_example.py")
         utils.write_file(fname, "x = 42\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 2)
         self.assertTrue(":1: Example does not have doxygen comments "
                         "at start" in errors[0])
         self.assertTrue(":1: Example \\example marker in first line"
                         in errors[1])
Пример #10
0
 def test_check_example_no_doxygen(self):
     """Test Python example with missing doxygen comments"""
     with utils.TempDir() as tmpdir:
         os.mkdir(os.path.join(tmpdir, 'examples'))
         fname = os.path.join(tmpdir, "examples", "my_example.py")
         utils.write_file(fname, "x = 42\n")
         errors = []
         check_standards.check_python_file(fname, errors)
         self.assertEqual(len(errors), 2)
         self.assertTrue(":1: Example does not have doxygen comments "
                         "at start" in errors[0])
         self.assertTrue(
             ":1: Example \\example marker in first line" in errors[1])
    def test_check_example_bad_import(self):
        """Test Python example with bad imports"""
        with utils.TempDir() as tmpdir:
            os.mkdir(os.path.join(tmpdir, 'examples'))
            fname = os.path.join(tmpdir, "examples", "my_example.py")
            utils.write_file(fname, """## \\example my_example.py
from foo import bar
import bar as baz
""")
            errors = []
            check_standards.check_python_file(fname, errors)
            self.assertEqual(len(errors), 2)
            self.assertTrue(":2: Examples should not use import from as "
                            "that confuses doxygen" in errors[0])
            self.assertTrue(":3: Examples should not rename types on import"
                            in errors[1])
Пример #12
0
    def test_check_example_bad_import(self):
        """Test Python example with bad imports"""
        with utils.TempDir() as tmpdir:
            os.mkdir(os.path.join(tmpdir, 'examples'))
            fname = os.path.join(tmpdir, "examples", "my_example.py")
            utils.write_file(fname, """## \\example my_example.py
from foo import bar
import bar as baz
""")
            errors = []
            check_standards.check_python_file(fname, errors)
            self.assertEqual(len(errors), 2)
            self.assertTrue(":2: Examples should not use import from as "
                            "that confuses doxygen" in errors[0])
            self.assertTrue(":3: Examples should not rename types on import"
                            in errors[1])