Пример #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())
Пример #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)
Пример #3
0
    def test_from_new_raises_if_program_already_exists(self, fs):
        root = pathlib.Path(fs, "foo")
        make_mbed_program_files(root)

        with self.assertRaises(ValueError):
            MbedProgramFiles.from_new(root)