Exemple #1
0
    def test_project_does_not_reference_updated_library(self, mocker):
        requirements = "not\nplus\nthree\nmine"
        mocker.patch.object(Project,
                            "read_requirements_file",
                            return_value=requirements)
        library_project_names = ["one", "two", "else"]

        project = Project(project_path="path")
        result = project.project_references_updated_library(
            library_project_names)

        assert result is False
Exemple #2
0
    def test_project_has_changed_with_different_file_count(self):
        current_file_1 = MagicMock(spec=File)
        current_project = Project(project_path="here",
                                  file_list=[current_file_1])
        previous_file_1 = MagicMock(spec=File)
        previous_file_2 = MagicMock(spec=File)
        project_from_last_run = MagicMock(
            spec=Project, file_list=[previous_file_2, previous_file_1])

        current_project.set_needs_build_due_to_file_changes(
            project_from_last_run)

        assert current_project.needs_build is True
Exemple #3
0
    def test_set_needs_build_due_to_updated_library_reference_no(self, mocker):
        updated_library_names = ["one", "two"]
        project_references_updated_library_mock = mocker.patch.object(
            Project, "project_references_updated_library", return_value=False)
        set_needs_build_mock = mocker.patch.object(Project, "set_needs_build")

        project = Project(project_path="path")
        project.set_needs_build_due_to_updated_library_reference(
            updated_library_names)

        project_references_updated_library_mock.assert_called_once_with(
            updated_library_names)
        set_needs_build_mock.assert_not_called()
Exemple #4
0
    def test_project_from_previous_run_is_none(self):
        current_file_1 = MagicMock(spec=File,
                                   file="first",
                                   last_changed_time=1)
        current_file_2 = MagicMock(spec=File,
                                   file="second",
                                   last_changed_time=1)
        current_project = Project(project_path="here",
                                  file_list=[current_file_1, current_file_2])

        current_project.set_needs_build_due_to_file_changes(None)

        assert current_project.needs_build is True
Exemple #5
0
    def test_get_project_name_replaces_underscores(self, mocker):
        path_mock = MagicMock()
        path_mock.name = "call_me-Ismael"
        mocker.patch.object(Project, "path", path_mock)
        project = Project(project_path="path")

        assert project.name == "call-me-Ismael"
Exemple #6
0
    def test_get_project_name(self, mocker):
        path_mock = MagicMock()
        path_mock.name = "callmeIsmael"
        mocker.patch.object(Project, "path", path_mock)
        project = Project(project_path="path")

        assert project.name == "callmeIsmael"
Exemple #7
0
    def test_read_requirements_file_for_python(self, mocker):
        join_mock = mocker.patch("monorepo_builder.projects.os.path.join",
                                 side_effect=["file1", "file2"])
        path_mock = mocker.patch.object(Path, "__init__", return_value=None)
        project = Project(project_path="here")
        exist_mock = mocker.patch.object(Path, "exists", return_value=True)
        mocker.patch.object(Path, "read_text", return_value="content")

        result = project.read_requirements_file()

        assert join_mock.call_args_list == [
            call("here", "requirements.txt"),
            call("here", "package.json"),
        ]
        path_mock.assert_called_once_with("file1")
        exist_mock.assert_called_once()
        assert result == "content"
Exemple #8
0
 def test_is_regular_project(self, mocker):
     configuration_mock = MagicMock(spec=Configuration,
                                    library_folder_name="lib")
     mocker.patch.object(ConfigurationManager,
                         "get",
                         return_value=configuration_mock)
     mocker.patch.object(Project, "path",
                         MagicMock(parts=("first", "project", "third")))
     project = Project(project_path="something/web/project")
     assert project.project_type == ProjectType.Standard
Exemple #9
0
    def test_read_requirements_file_not_found(self, mocker):
        join_mock = mocker.patch("monorepo_builder.projects.os.path.join",
                                 side_effect=["file1", "file2"])
        path_mock = mocker.patch.object(Path, "__init__", return_value=None)
        project = Project(project_path="here")
        exist_mock = mocker.patch.object(Path,
                                         "exists",
                                         side_effect=[False, False])
        mocker.patch.object(Project, "name", return_value="project")

        with pytest.raises(RequirementsFileNotFoundException):
            project.read_requirements_file()

        assert join_mock.call_args_list == [
            call("here", "requirements.txt"),
            call("here", "package.json"),
        ]
        assert path_mock.call_args_list == [call("file1"), call("file2")]
        assert exist_mock.call_count == 2
Exemple #10
0
    def test_project_has_not_changed(self):
        current_file_1 = MagicMock(spec=File,
                                   file="first",
                                   last_changed_time=1)
        current_file_2 = MagicMock(spec=File,
                                   file="second",
                                   last_changed_time=1)
        current_project = Project(project_path="here",
                                  file_list=[current_file_2, current_file_1])
        previous_file_1 = MagicMock(spec=File,
                                    file="first",
                                    last_changed_time=1)
        previous_file_2 = MagicMock(spec=File,
                                    file="second",
                                    last_changed_time=1)
        project_from_last_run = MagicMock(
            spec=Project, file_list=[previous_file_1, previous_file_2])

        current_project.set_needs_build_due_to_file_changes(
            project_from_last_run)

        assert current_project.needs_build is False
Exemple #11
0
    def test_project_has_changed_with_with_matching_files_and_different_times(
            self):
        current_file_1 = MagicMock(spec=File,
                                   file="first",
                                   last_changed_time=1)
        current_file_2 = MagicMock(spec=File,
                                   file="second",
                                   last_changed_time=1)
        current_project = Project(project_path="here",
                                  file_list=[current_file_1, current_file_2])
        previous_file_1 = MagicMock(spec=File,
                                    file="first",
                                    last_changed_time=1)
        previous_file_2 = MagicMock(spec=File,
                                    file="second",
                                    last_changed_time=2)
        project_from_last_run = MagicMock(
            spec=Project, file_list=[previous_file_1, previous_file_2])

        current_project.set_needs_build_due_to_file_changes(
            project_from_last_run)

        assert current_project.needs_build is True
    def get_projects_in_folder(self, folder: str) -> List[Project]:
        if not Path(folder).exists():
            return []

        project_list: List[Project] = []
        for project in Path(folder).iterdir():
            if not project.is_dir():
                continue
            if self.is_folder_project(project):
                project_path = str(project)
                project_list.append(
                    Project(
                        project_path=project_path,
                        file_list=ProjectFileListBuilder().build(project),
                    )
                )
            else:
                project_list.extend(self.get_projects_in_folder(str(project)))
        return project_list
Exemple #13
0
 def test_path(self, mocker):
     path_mock = mocker.patch("monorepo_builder.projects.Path")
     project = Project(project_path="this")
     assert project.path is path_mock.return_value
     path_mock.assert_called_once_with("this")
Exemple #14
0
def copy_installers(project_path: str):
    project = Project(project_path=project_path)
    InstallerManager().copy_installers_to_project(project)