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_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())
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_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())
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)
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_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)
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())
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)
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)