Ejemplo n.º 1
0
    def test_from_existing_raises_if_no_mbed_os_dir_found_and_check_mbed_os_is_true(
            self, 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)
Ejemplo n.º 2
0
    def test_finds_program_higher_in_dir_tree(self, fs):
        program_root = pathlib.Path(fs, "foo")
        pwd = program_root / "subprojfoo" / "libbar"
        make_mbed_program_files(program_root)
        pwd.mkdir(parents=True)

        self.assertEqual(_find_program_root(pwd), program_root.resolve())
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def test_from_existing_finds_existing_program_data(self, fs):
        root = pathlib.Path(fs, "foo")
        make_mbed_program_files(root)

        program = MbedProgramFiles.from_existing(root)

        self.assertTrue(program.app_config_file.exists())
Ejemplo n.º 5
0
    def test_finds_program_higher_in_dir_tree(self, tmp_path):
        program_root = pathlib.Path(tmp_path, "foo")
        pwd = program_root / "subprojfoo" / "libbar"
        make_mbed_program_files(program_root)
        pwd.mkdir(parents=True)

        assert _find_program_root(pwd) == program_root.resolve()
Ejemplo n.º 6
0
    def test_checks_for_unresolved_libraries(self, fs):
        root = pathlib.Path(fs, "root").absolute().resolve()
        make_mbed_program_files(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")

        program = MbedProgram.from_existing(root, check_mbed_os=False)

        self.assertTrue(program.has_unresolved_libraries())
Ejemplo n.º 7
0
    def test_from_existing_raises_if_no_mbed_os_dir_found_and_check_mbed_os_is_true(
            self, tmp_path):
        fs_root = pathlib.Path(tmp_path, "foo")
        make_mbed_program_files(fs_root)

        with pytest.raises(MbedOSNotFound):
            MbedProgram.from_existing(fs_root,
                                      DEFAULT_BUILD_SUBDIR,
                                      check_mbed_os=True)
Ejemplo n.º 8
0
    def test_from_existing_returns_valid_program(self, 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, DEFAULT_BUILD_SUBDIR)

        self.assertTrue(program.files.app_config_file.exists())
        self.assertTrue(program.mbed_os.root.exists())
Ejemplo n.º 9
0
    def test_from_existing_finds_existing_program_data(self, tmp_path):
        root = pathlib.Path(tmp_path, "foo")
        make_mbed_program_files(root)

        program = MbedProgramFiles.from_existing(
            root, pathlib.Path("K64F", "develop", "GCC_ARM"))

        assert program.app_config_file.exists()
        assert program.mbed_os_ref.exists()
        assert program.cmakelists_file.exists()
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def test_from_existing_with_mbed_os_path_returns_valid_program(self, fs):
        fs_root = pathlib.Path(fs, "foo")
        mbed_os_path = fs_root / "extern/mbed-os"
        mbed_os_path.mkdir(parents=True)
        make_mbed_program_files(fs_root)
        make_mbed_os_files(mbed_os_path)

        program = MbedProgram.from_existing(fs_root, DEFAULT_BUILD_SUBDIR, mbed_os_path)

        self.assertTrue(program.files.app_config_file.exists())
        self.assertTrue(program.mbed_os.root.exists())
Ejemplo n.º 12
0
    def test_from_existing_skips_rendering_cmake_template_if_file_exists(
            self, fs):
        with mock.patch(
                "mbed_tools.project._internal.project_data.render_cmakelists_template"
        ) as render_cmake:
            root = pathlib.Path(fs, "foo")
            make_mbed_program_files(root)
            (root / CMAKELISTS_FILE_NAME).touch()

            MbedProgramFiles.from_existing(root)

            render_cmake.assert_not_called()
Ejemplo n.º 13
0
    def test_from_existing_calls_render_cmakelists_template_with_program_name_if_file_nonexistent(
            self, fs):
        with mock.patch(
                "mbed_tools.project._internal.project_data.render_cmakelists_template"
        ) as render_cmake:
            root = pathlib.Path(fs, "foo")
            make_mbed_program_files(root)
            render_cmake.return_value = "foo"

            program_files = MbedProgramFiles.from_existing(root)

            render_cmake.assert_called_with(program_files.cmakelists_file,
                                            root.stem)
Ejemplo n.º 14
0
    def test_lists_all_known_libraries(self, fs):
        root = pathlib.Path(fs, "root").absolute().resolve()
        make_mbed_program_files(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"
        )

        program = MbedProgram.from_existing(root, check_mbed_os=False)
        libs = program.list_known_library_dependencies()

        self.assertEqual(str(lib_ref_unresolved), str(libs[1]))
        self.assertEqual(str(lib_ref), str(libs[2]))
Ejemplo n.º 15
0
    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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
0
    def test_finds_program_at_current_path(self, fs):
        program_root = pathlib.Path(fs, "foo")
        make_mbed_program_files(program_root)

        self.assertEqual(_find_program_root(program_root), program_root.resolve())
Ejemplo n.º 21
0
    def test_finds_program_at_current_path(self, tmp_path):
        program_root = pathlib.Path(tmp_path, "foo")
        make_mbed_program_files(program_root)

        assert _find_program_root(program_root) == program_root.resolve()