예제 #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)
예제 #2
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)
예제 #3
0
    def test_can_be_saved_and_restored_from_file(self):
        project = ProjectInDirectory(self.tmpdir).with_modules(["good_module.py", "bad_module.py"])
        project['good_module'].add_objects([Class("AClass", [Method("amethod")]),
                                            Function("afunction")])
        project['bad_module'].errors = ["Syntax error"]
        project.save()

        project = Project.from_directory(project.path)

        assert_equal(2, len(project.get_modules()))
        assert_equal(2, len(project['good_module'].objects))
        assert_equal(["AClass"], get_names(project['good_module'].classes))
        assert_equal(["amethod"], get_names(project['good_module'].classes[0].methods))
        assert_equal(["afunction"], get_names(project['good_module'].functions))
        assert_equal(["Syntax error"], project['bad_module'].errors)
예제 #4
0
    def test_can_be_saved_and_restored_from_file(self):
        project = ProjectInDirectory(self.tmpdir).with_modules(
            ["good_module.py", "bad_module.py"])
        project['good_module'].add_objects(
            [Class("AClass", [Method("amethod")]),
             Function("afunction")])
        project['bad_module'].errors = ["Syntax error"]
        project.save()

        project = Project.from_directory(project.path)

        assert_equal(2, len(project.get_modules()))
        assert_equal(2, len(project['good_module'].objects))
        assert_equal(["AClass"], get_names(project['good_module'].classes))
        assert_equal(["amethod"],
                     get_names(project['good_module'].classes[0].methods))
        assert_equal(["afunction"],
                     get_names(project['good_module'].functions))
        assert_equal(["Syntax error"], project['bad_module'].errors)