Exemple #1
0
    def _test_appending(self, modified_input, expected_output):
        project = ProjectInDirectory(self.tmpdir)

        module_path = putfile(project.path, "module.py", read_data("appending_test_cases_module_initial.py"))
        test_module_path = putfile(project.path, "test_module.py", read_data("appending_test_cases_output_initial.py"))

        # Analyze the project with an existing test module.
        inspect_project(project)

        # Filesystem stat has resolution of 1 second, and we don't want to
        # sleep in a test, so we just fake the original files creation time.
        project["module"].created = 0
        project["test_module"].created = 0

        # Modify the application module and analyze it again.
        putfile(project.path, "module.py", read_data(modified_input))
        inspect_project(project)

        # Regenerate the tests.
        add_tests_to_project(project, [module_path], 'unittest')
        project.save()

        assert_length(project.get_modules(), 2)
        result = read_file_contents(test_module_path)
        expected_result = read_data(expected_output)
        assert_equal_strings(expected_result, result)
Exemple #2
0
 def test_skips_dynamic_inspection_when_no_changes_were_made_to_the_project(
         self):
     project = ProjectInDirectory(self.tmpdir)
     inspect_project(project)
     assert_equal_strings(
         "INFO: No changes discovered in the source code, skipping dynamic inspection.\n",
         self._get_log_output())
Exemple #3
0
    def _test_appending(self, modified_input, expected_output):
        project = ProjectInDirectory(self.tmpdir)

        module_path = putfile(
            project.path, "module.py",
            read_data("appending_test_cases_module_initial.py"))
        test_module_path = putfile(
            project.path, "test_module.py",
            read_data("appending_test_cases_output_initial.py"))

        # Analyze the project with an existing test module.
        inspect_project(project)

        # Filesystem stat has resolution of 1 second, and we don't want to
        # sleep in a test, so we just fake the original files creation time.
        project["module"].created = 0
        project["test_module"].created = 0

        # Modify the application module and analyze it again.
        putfile(project.path, "module.py", read_data(modified_input))
        inspect_project(project)

        # Regenerate the tests.
        add_tests_to_project(project, [module_path], 'unittest')
        project.save()

        assert_length(project.get_modules(), 2)
        result = read_file_contents(test_module_path)
        expected_result = read_data(expected_output)
        assert_equal_strings(expected_result, result)
Exemple #4
0
    def test_reports_each_inspected_point_of_entry(self):
        paths = ["one.py", "two.py"]
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(paths)

        inspect_project(project)

        for path in paths:
            assert_contains_once(self._get_log_output(), "INFO: Inspecting point of entry %s." % path)
Exemple #5
0
 def test_catches_exceptions_raised_by_entry_points(self):
     project = ProjectInDirectory(self.tmpdir).with_point_of_entry("exc.py", "raise Exception")
     inspect_project(project)
     if sys.version_info < (2, 5):
         assert_contains_once(
             self._get_log_output(), "WARNING: Point of entry exited with error: <exceptions.Exception instance at"
         )
     else:
         assert_contains_once(self._get_log_output(), "WARNING: Point of entry exited with error: Exception()")
Exemple #6
0
    def test_reports_each_inspected_point_of_entry(self):
        paths = ["one.py", "two.py"]
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(paths)

        inspect_project(project)

        for path in paths:
            assert_contains_once(self._get_log_output(),
                                 "INFO: Inspecting point of entry %s." % path)
Exemple #7
0
    def test_skips_inspection_of_up_to_date_modules(self):
        paths = ["module.py", "something_else.py", P("module/in/directory.py")]
        project = ProjectInDirectory(self.tmpdir).with_modules(paths)

        inspect_project(project)

        for path in paths:
            assert_contains_once(self._get_log_output(),
                "DEBUG: %s hasn't changed since last inspection, skipping." % path)
Exemple #8
0
    def test_generates_test_stubs(self):
        expected_result = read_data("static_analysis_output.py")
        project = ProjectInDirectory(self.tmpdir)
        module_path = putfile(project.path, "module.py", read_data("static_analysis_module.py"))

        inspect_project(project)
        add_tests_to_project(project, [module_path], 'unittest')
        result = get_test_module_contents(project)

        assert_equal_strings(expected_result, result)
Exemple #9
0
    def test_generates_test_stubs(self):
        expected_result = read_data("static_analysis_output.py")
        project = ProjectInDirectory(self.tmpdir)
        module_path = putfile(project.path, "module.py", read_data("static_analysis_module.py"))

        inspect_project(project)
        add_tests_to_project(project, [module_path], 'unittest')
        result = get_test_module_contents(project)

        assert_equal_strings(expected_result, result)
Exemple #10
0
    def test_skips_inspection_of_up_to_date_modules(self):
        paths = ["module.py", "something_else.py", P("module/in/directory.py")]
        project = ProjectInDirectory(self.tmpdir).with_modules(paths)

        inspect_project(project)

        for path in paths:
            assert_contains_once(
                self._get_log_output(),
                "DEBUG: %s hasn't changed since last inspection, skipping." %
                path)
Exemple #11
0
    def execute_with_point_of_entry_and_assert(self, id):
        expected_result = read_data("%s_output.py" % id)
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(["poe.py"])
        module_path = putfile(project.path, "module.py", read_data("%s_module.py" % id))
        write_content_to_file(read_data("generic_acceptance_poe.py"), project.path_for_point_of_entry("poe.py"))

        inspect_project(project)
        add_tests_to_project(project, [module_path], 'unittest')
        result = get_test_module_contents(project)

        assert_equal_strings(expected_result, result)
Exemple #12
0
    def execute_with_point_of_entry_and_assert(self, id):
        expected_result = read_data("%s_output.py" % id)
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(["poe.py"])
        module_path = putfile(project.path, "module.py", read_data("%s_module.py" % id))
        write_content_to_file(read_data("generic_acceptance_poe.py"), project.path_for_point_of_entry("poe.py"))

        inspect_project(project)
        add_tests_to_project(project, [module_path], 'unittest')
        result = get_test_module_contents(project)

        assert_equal_strings(expected_result, result)
Exemple #13
0
    def test_reports_each_inspected_module(self):
        paths = ["module.py", "something_else.py", P("module/in/directory.py")]
        project = ProjectInDirectory(self.tmpdir).with_modules(paths)
        # Force the inspection by faking files creation time.
        project["module"].created = 0
        project["something_else"].created = 0
        project["module.in.directory"].created = 0

        inspect_project(project)

        for path in paths:
            assert_contains_once(self._get_log_output(), "INFO: Inspecting module %s." % path)
Exemple #14
0
 def test_catches_exceptions_raised_by_entry_points(self):
     project = ProjectInDirectory(self.tmpdir).with_point_of_entry(
         "exc.py", "raise Exception")
     inspect_project(project)
     if sys.version_info < (2, 5):
         assert_contains_once(
             self._get_log_output(),
             "WARNING: Point of entry exited with error: <exceptions.Exception instance at"
         )
     else:
         assert_contains_once(
             self._get_log_output(),
             "WARNING: Point of entry exited with error: Exception()")
Exemple #15
0
    def test_reports_each_inspected_module(self):
        paths = ["module.py", "something_else.py", P("module/in/directory.py")]
        project = ProjectInDirectory(self.tmpdir).with_modules(paths)
        # Force the inspection by faking files creation time.
        project["module"].created = 0
        project["something_else"].created = 0
        project["module.in.directory"].created = 0

        inspect_project(project)

        for path in paths:
            assert_contains_once(self._get_log_output(),
                                 "INFO: Inspecting module %s." % path)
Exemple #16
0
    def test_warns_about_unreliable_implementation_of_util_generator_has_ended(self):
        if not hasattr(generator_has_ended, 'unreliable'):
            raise SkipTest

        paths = ["edgar.py", "allan.py"]
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(paths)

        inspect_project(project)

        assert_contains_once(self._get_log_output(),
                             "WARNING: Pure Python implementation of "
                             "util.generator_has_ended is not reliable on "
                             "Python 2.4 and lower. Please compile the _util "
                             "module or use Python 2.5 or higher.")
Exemple #17
0
 def test_catches_string_exceptions_raised_by_entry_points(self):
     project = ProjectInDirectory(self.tmpdir).with_point_of_entry("exc.py", "raise 'bad string'")
     inspect_project(project)
     if sys.version_info < (2, 6):
         assert_contains_once(self._get_log_output(),
                              "WARNING: Point of entry exited with error: bad string")
     elif sys.version_info > (2, 6, 4): # Message changed a bit from 2.6.4 to 2.6.5
         assert_contains_once(self._get_log_output(),
                              "WARNING: Point of entry exited with error: "
                              "TypeError('exceptions must be old-style classes or derived from BaseException, not str',)")
     else:
         assert_contains_once(self._get_log_output(),
                              "WARNING: Point of entry exited with error: "
                              "TypeError('exceptions must be classes or instances, not str',)")
Exemple #18
0
    def test_warns_about_unreliable_implementation_of_util_generator_has_ended(
            self):
        if not hasattr(generator_has_ended, 'unreliable'):
            raise SkipTest

        paths = ["edgar.py", "allan.py"]
        project = ProjectInDirectory(self.tmpdir).with_points_of_entry(paths)

        inspect_project(project)

        assert_contains_once(
            self._get_log_output(), "WARNING: Pure Python implementation of "
            "util.generator_has_ended is not reliable on "
            "Python 2.4 and lower. Please compile the _util "
            "module or use Python 2.5 or higher.")
Exemple #19
0
 def test_catches_string_exceptions_raised_by_entry_points(self):
     project = ProjectInDirectory(self.tmpdir).with_point_of_entry(
         "exc.py", "raise 'bad string'")
     inspect_project(project)
     if sys.version_info < (2, 6):
         assert_contains_once(
             self._get_log_output(),
             "WARNING: Point of entry exited with error: bad string")
     elif sys.version_info > (
             2, 6, 4):  # Message changed a bit from 2.6.4 to 2.6.5
         assert_contains_once(
             self._get_log_output(),
             "WARNING: Point of entry exited with error: "
             "TypeError('exceptions must be old-style classes or derived from BaseException, not str',)"
         )
     else:
         assert_contains_once(
             self._get_log_output(),
             "WARNING: Point of entry exited with error: "
             "TypeError('exceptions must be classes or instances, not str',)"
         )
Exemple #20
0
 def test_skips_dynamic_inspection_when_no_changes_were_made_to_the_project(self):
     project = ProjectInDirectory(self.tmpdir)
     inspect_project(project)
     assert_equal_strings(
         "INFO: No changes discovered in the source code, skipping dynamic inspection.\n", self._get_log_output()
     )