def test_from_existing_raises_if_path_is_not_a_program(self, fs):
        fs_root = pathlib.Path(fs, "foo")
        fs_root.mkdir()
        program_root = fs_root / "programfoo"

        with self.assertRaises(ProgramNotFound):
            MbedProgram.from_existing(program_root)
    def test_from_url_raises_if_dest_dir_contains_program(self, fs):
        fs_root = pathlib.Path(fs, "foo")
        make_mbed_program_files(fs_root)
        url = "https://valid"

        with self.assertRaises(ExistingProgram):
            MbedProgram.from_url(url, fs_root)
    def test_checkout_libraries(self, mock_lib_refs):
        program = MbedProgram(None, MbedProgramFiles(None, pathlib.Path(),
                                                     None),
                              MbedOS(pathlib.Path(), None))
        program.checkout_libraries()

        program.lib_references.checkout.assert_called_once()
    def test_from_new_local_dir_raises_if_path_is_existing_program(self, fs):
        program_root = pathlib.Path(fs, "programfoo")
        program_root.mkdir()
        (program_root / ".mbed").touch()

        with self.assertRaises(ExistingProgram):
            MbedProgram.from_new(program_root)
    def test_from_existing_raises_if_no_mbed_os_dir_found_and_check_mbed_os_is_true(
            self, mock_repo, fs):
        fs_root = pathlib.Path(fs, "foo")
        make_mbed_program_files(fs_root)

        with self.assertRaises(MbedOSNotFound):
            MbedProgram.from_existing(fs_root, check_mbed_os=True)
    def test_from_existing_raises_if_program_files_missing(self, fs):
        fs_root = pathlib.Path(fs, "foo")
        fs_root.mkdir()
        (fs_root / ".mbed").touch()
        program_root = fs_root

        with self.assertRaises(ProgramNotFound):
            MbedProgram.from_existing(program_root)
    def test_from_url_raises_if_check_mbed_os_is_true_and_mbed_os_dir_nonexistent(
            self, mock_clone, fs):
        fs_root = pathlib.Path(fs, "foo")
        url = "https://validrepo.com"
        mock_clone.side_effect = lambda *args: make_mbed_program_files(fs_root)

        with self.assertRaises(MbedOSNotFound):
            MbedProgram.from_url(url, fs_root, check_mbed_os=True)
    def test_from_url_raises_if_cloned_repo_is_not_program(
            self, mock_repo, fs):
        fs_root = pathlib.Path(fs, "foo")
        fs_root.mkdir()
        url = "https://validrepo.com"
        mock_repo.side_effect = lambda url, dst_dir: dst_dir.mkdir()

        with self.assertRaises(ProgramNotFound):
            MbedProgram.from_url(url, fs_root / "corrupt-prog")
    def test_checks_for_unresolved_libraries(self, fs):
        root = pathlib.Path(fs, "root")
        make_mbed_lib_reference(root, resolved=True, ref_url="https://blah")
        make_mbed_lib_reference(root,
                                name="my-unresolved-lib.lib",
                                resolved=False,
                                ref_url="https://blah")
        mbed_os_root = root / "mbed-os"
        mbed_os_root.mkdir()

        program = MbedProgram(
            None, MbedProgramFiles(None, pathlib.Path(root / ".mbed"), None),
            MbedOS(mbed_os_root, None))
        self.assertTrue(program.has_unresolved_libraries())
Example #10
0
    def test_from_url_returns_valid_program(self, mock_clone, fs):
        fs_root = pathlib.Path(fs, "foo")
        url = "https://valid"
        mock_clone.side_effect = lambda *args: make_mbed_program_files(fs_root)
        program = MbedProgram.from_url(url, fs_root, False)

        self.assertEqual(program.files,
                         MbedProgramFiles.from_existing(fs_root))
        mock_clone.assert_called_once_with(url, fs_root)
Example #11
0
    def test_lists_all_known_libraries(self, fs):
        root = pathlib.Path(fs, "root")
        lib_ref = make_mbed_lib_reference(root,
                                          resolved=True,
                                          ref_url="https://blah")
        lib_ref_unresolved = make_mbed_lib_reference(
            root,
            name="my-unresolved-lib.lib",
            resolved=False,
            ref_url="https://blah")
        mbed_os_root = root / "mbed-os"
        mbed_os_root.mkdir()

        program = MbedProgram(
            None, MbedProgramFiles(None, pathlib.Path(root, ".mbed"), None),
            MbedOS(mbed_os_root, None))
        libs = program.list_known_library_dependencies()
        self.assertEqual(str(lib_ref_unresolved), str(libs[0]))
        self.assertEqual(str(lib_ref), str(libs[1]))
Example #12
0
    def test_from_existing_returns_valid_program(self, mock_repo, fs):
        fs_root = pathlib.Path(fs, "foo")
        make_mbed_program_files(fs_root)
        make_mbed_os_files(fs_root / "mbed-os")

        program = MbedProgram.from_existing(fs_root)

        self.assertTrue(program.files.app_config_file.exists())
        self.assertTrue(program.mbed_os.root.exists())
        self.assertIsNotNone(program.repo)
Example #13
0
    def test_from_new_local_dir_generates_valid_program(self, mock_init, fs):
        fs_root = pathlib.Path(fs, "foo")
        fs_root.mkdir()
        program_root = fs_root / "programfoo"

        program = MbedProgram.from_new(program_root)

        self.assertEqual(program.files,
                         MbedProgramFiles.from_existing(program_root))
        self.assertEqual(program.repo, mock_init.return_value)
        mock_init.assert_called_once_with(program_root)
def assemble_config(mbed_target: str, mbed_program_directory: Path) -> Config:
    """Assemble Config for given target and program directory.

    The structure and configuration of MbedOS requires us to do multiple passes over
    configuration files, as each pass might affect which configuration files should be included
    in the final configuration.
    """
    target_source = Source.from_target(mbed_target, mbed_program_directory)
    mbed_lib_files = find_files("mbed_lib.json", mbed_program_directory)
    mbed_program = MbedProgram.from_existing(mbed_program_directory)
    mbed_app_file = mbed_program.files.app_config_file
    return _assemble_config_from_sources_and_lib_files(target_source,
                                                       mbed_lib_files,
                                                       mbed_app_file)
Example #15
0
def get_target_by_name(name: str, path_to_mbed_program: str) -> Target:
    """Returns the Target whose name matches the name given.

    The Target is as defined in the targets.json file found in the Mbed OS library.
    The program whose path is provided here will need a valid copy of the Mbed OS library
    in order to access this file.

    Args:
        name: the name of the Target to be returned
        path_to_mbed_program: path to an Mbed OS program

    Raises:
        TargetError: an error has occurred while fetching target
    """
    mbed_program = MbedProgram.from_existing(pathlib.Path(path_to_mbed_program))
    path_to_targets_json = mbed_program.mbed_os.targets_json_file
    return Target.by_name(name, path_to_targets_json)
Example #16
0
    def test_from_existing_raises_if_no_repo_found(self, fs):
        fs_root = pathlib.Path(fs, "foo")
        make_mbed_program_files(fs_root)

        with self.assertRaises(VersionControlError):
            MbedProgram.from_existing(fs_root)