Exemplo 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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_removes_definitions_of_modules_that_dont_exist_anymore(self):
        project = ProjectInDirectory(self.tmpdir).with_modules(["module.py", "other_module.py", "test_module.py"])
        test_class = create(TestClass, associated_modules=[project["module"]])
        add_test_case(project["test_module.py"], test_class)
        project.save()

        os.remove(os.path.join(project.path, "other_module.py"))

        remove_deleted_modules(project)

        assert_not_raises(ModuleNotFound, lambda: project["module"])
        assert_raises(ModuleNotFound, lambda: project["other_module"])
        assert_not_raises(ModuleNotFound, lambda: project["test_module"])
Exemplo n.º 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)
Exemplo n.º 5
0
    def test_doesnt_save_uncomplete_pickle_files(self):
        project = ProjectInDirectory(self.tmpdir)
        project.save()
        original_pickle = read_file_contents(project._get_pickle_path())

        # Inject unpickable object into project.
        project._injected_attr = UNPICKABLE_OBJECT
        try:
            project.save()
        except PicklingError:
            pass

        # Make sure that the original file wasn't overwritten.
        assert_equal_strings(original_pickle,
                             read_file_contents(project._get_pickle_path()))
Exemplo n.º 6
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)