Esempio n. 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)
Esempio n. 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)
Esempio n. 3
0
    def setUp(self):
        super(TestGeneratorWithTestDirectoryAsFile, self).setUp()

        self.project = TestableProject(self.tmpdir)
        putfile(self.project.path, self.project.new_tests_directory, "its content")
        self.module_path = os.path.join(self.project.path, "module.py")
        def add_and_save():
            add_tests_to_project(self.project, [self.module_path], 'unittest')
            self.project.save()
        self.add_and_save = add_and_save
Esempio n. 4
0
    def test_doesnt_overwrite_existing_files_which_werent_analyzed(self):
        TEST_CONTENTS = "# test"
        project = TestableProject(self.tmpdir)
        # File exists, but project does NOT contain corresponding test module.
        existing_file = os.path.join(project.new_tests_directory, "test_module.py")
        putfile(project.path, existing_file, TEST_CONTENTS)

        def add_and_save():
            add_tests_to_project(project, [os.path.join(project.path, "module.py")], 'unittest')
            project.save()

        assert_raises(ModuleNeedsAnalysis, add_and_save)
        assert_equal(TEST_CONTENTS, read_file_contents(project._path_for_test("test_module.py")))
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
    def test_doesnt_overwrite_existing_files_which_were_modified_since_last_analysis(self):
        TEST_CONTENTS = "# test"
        project = TestableProject(self.tmpdir, ["test_module.py"])
        # File exists, and project contains corresponding, but outdated, test module.
        existing_file = putfile(project.path, "test_module.py", TEST_CONTENTS)
        project["test_module"].created = time.time() - 3600

        def add_and_save():
            add_tests_to_project(project, [os.path.join(project.path, "module.py")], 'unittest')
            project.save()

        assert_raises(ModuleNeedsAnalysis, add_and_save)
        assert_equal(TEST_CONTENTS, read_file_contents(existing_file))
Esempio n. 9
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)
Esempio n. 10
0
 def _init_project(self, module_code="", poe_content=""):
     self.project = ProjectInDirectory(self.tmpdir)
     putfile(self.project.path, "module.py", module_code)
     inspect_code(self.project, os.path.join(self.project.path, "module.py"), module_code)
     self.poe = PointOfEntryMock(self.project, content=poe_content)