Example #1
0
    def test_from_new_returns_valid_program(self, fs):
        root = pathlib.Path(fs, "foo")
        root.mkdir()

        program = MbedProgramFiles.from_new(root)

        self.assertTrue(program.app_config_file.exists())
Example #2
0
    def from_new(cls, dir_path: Path) -> "MbedProgram":
        """Create an MbedProgram from an empty directory.

        Creates the directory if it doesn't exist.

        Args:
            dir_path: Directory in which to create the program.

        Raises:
            ExistingProgram: An existing program was found in the path.
        """
        if _tree_contains_program(dir_path):
            raise ExistingProgram(
                f"An existing Mbed program was found in the directory tree {dir_path}. It is not possible to nest Mbed "
                "programs. Please ensure there is no .mbed file in the cwd hierarchy."
            )

        logger.info(f"Creating Mbed program at path '{dir_path.resolve()}'")
        dir_path.mkdir(exist_ok=True)
        program_files = MbedProgramFiles.from_new(dir_path)
        logger.info(
            f"Creating git repository for the Mbed program '{dir_path}'")
        repo = git_utils.init(dir_path)
        mbed_os = MbedOS.from_new(dir_path / MBED_OS_DIR_NAME)
        return cls(repo, program_files, mbed_os)
Example #3
0
    def test_from_new_returns_valid_program_file_set(self, tmp_path):
        root = pathlib.Path(tmp_path, "foo")
        root.mkdir()

        program = MbedProgramFiles.from_new(root)

        assert program.app_config_file.exists()
        assert program.mbed_os_ref.exists()
        assert program.cmakelists_file.exists()
Example #4
0
 def test_from_new_calls_render_template_for_gitignore_and_main(
         self, tmp_path):
     with mock.patch(
             "mbed_tools.project._internal.project_data.render_cmakelists_template"
     ) as render_cmakelists_template, mock.patch(
             "mbed_tools.project._internal.project_data.render_main_cpp_template"
     ) as render_main_cpp_template, mock.patch(
             "mbed_tools.project._internal.project_data.render_gitignore_template"
     ) as render_gitignore_template:
         root = pathlib.Path(tmp_path, "foo")
         root.mkdir()
         program_files = MbedProgramFiles.from_new(root)
         render_cmakelists_template.assert_called_once_with(
             program_files.cmakelists_file, "foo")
         render_main_cpp_template.assert_called_once_with(
             root / MAIN_CPP_FILE_NAME)
         render_gitignore_template.assert_called_once_with(root /
                                                           ".gitignore")
    def test_from_new_raises_if_program_files_already_exist(self, fs):
        root = pathlib.Path(fs, "foo")
        make_mbed_program_files(root)

        with self.assertRaises(ValueError):
            MbedProgramFiles.from_new(root)
Example #6
0
    def test_from_new_raises_if_program_files_already_exist(self, tmp_path):
        root = pathlib.Path(tmp_path, "foo")
        make_mbed_program_files(root)

        with pytest.raises(ValueError):
            MbedProgramFiles.from_new(root)