def search_packages(self, reference, query=None, remote_name=None, outdated=False): recorder = SearchRecorder() search = Search(self._client_cache, self._remote_manager, self._registry) try: reference = ConanFileReference.loads(str(reference)) references = search.search_packages(reference, remote_name, query=query, outdated=outdated) except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise for remote_name, remote_ref in references.items(): recorder.add_recipe(remote_name, reference) if remote_ref.ordered_packages: for package_id, properties in remote_ref.ordered_packages.items(): package_recipe_hash = properties.get("recipe_hash", None) recorder.add_package(remote_name, reference, package_id, properties.get("options", []), properties.get("settings", []), properties.get("full_requires", []), remote_ref.recipe_hash != package_recipe_hash) return recorder.get_info()
def search_recipes(self, pattern, remote_name=None, case_sensitive=False): recorder = SearchRecorder() search = Search(self._client_cache, self._remote_manager, self._registry) try: references = search.search_recipes(pattern, remote_name, case_sensitive) except ConanException as exc: recorder.error = True exc.info = recorder.get_info() raise for remote_name, refs in references.items(): for ref in refs: recorder.add_recipe(remote_name, ref, with_packages=False) return recorder.get_info()
def setUp(self): self.search_recorder = SearchRecorder()
class SearchRecorderTest(unittest.TestCase): def setUp(self): self.search_recorder = SearchRecorder() def test_empty(self): info = self.search_recorder.get_info() expected_result = {'error': False, 'results': []} self.assertEqual(expected_result, info) def test_sequential(self): self.search_recorder.add_recipe("remote1", _ref("fake/0.1@user/channel")) self.search_recorder.add_package("remote1", _ref("fake/0.1@user/channel"), "fake_package_id", "fake_options", "fake_settings", "fake_requires", False) self.search_recorder.add_recipe("remote2", _ref("fakefake/0.1@user/channel")) self.search_recorder.add_package("remote2", _ref("fakefake/0.1@user/channel"), "fakefake_package_id1", "fakefake_options1", "fakefake_settings1", "fakefake_requires1", False) self.search_recorder.add_package("remote2", _ref("fakefake/0.1@user/channel"), "fakefake_package_id2", "fakefake_options2", "fakefake_settings2", "fakefake_requires2", False) info = self.search_recorder.get_info() expected_result = { "error": False, "results": [{ "remote": "remote1", "items": [{ "recipe": { "id": "fake/0.1@user/channel" }, "packages": [{ "id": "fake_package_id", "options": "fake_options", "settings": "fake_settings", "requires": "fake_requires", "outdated": False }] }] }, { "remote": "remote2", "items": [{ "recipe": { "id": "fakefake/0.1@user/channel" }, "packages": [{ "id": "fakefake_package_id1", "options": "fakefake_options1", "settings": "fakefake_settings1", "requires": "fakefake_requires1", "outdated": False }, { "id": "fakefake_package_id2", "options": "fakefake_options2", "settings": "fakefake_settings2", "requires": "fakefake_requires2", "outdated": False }] }] }] } self.assertEqual(expected_result, info) def test_unordered(self): self.search_recorder.add_recipe("my_remote1", _ref("fake1/0.1@user/channel")) self.search_recorder.add_recipe("my_remote2", _ref("fake2/0.1@user/channel")) self.search_recorder.add_recipe("my_remote3", _ref("fake3/0.1@user/channel")) self.search_recorder.add_package("my_remote1", _ref("fake1/0.1@user/channel"), "fake1_package_id1", "fake1_options1", "fake1_settings1", "fake1_requires1", False) self.search_recorder.add_package("my_remote2", _ref("fake2/0.1@user/channel"), "fake2_package_id1", "fake2_options1", "fake2_settings1", "fake2_requires1", False) self.search_recorder.add_package("my_remote2", _ref("fake2/0.1@user/channel"), "fake2_package_id2", "fake2_options2", "fake2_settings2", "fake2_requires2", False) info = self.search_recorder.get_info() expected_result = { "error": False, "results": [{ "remote": "my_remote1", "items": [{ "recipe": { "id": "fake1/0.1@user/channel" }, "packages": [{ "id": "fake1_package_id1", "options": "fake1_options1", "settings": "fake1_settings1", "requires": "fake1_requires1", "outdated": False }] }] }, { "remote": "my_remote2", "items": [{ "recipe": { "id": "fake2/0.1@user/channel" }, "packages": [{ "id": "fake2_package_id1", "options": "fake2_options1", "settings": "fake2_settings1", "requires": "fake2_requires1", "outdated": False }, { "id": "fake2_package_id2", "options": "fake2_options2", "settings": "fake2_settings2", "requires": "fake2_requires2", "outdated": False }] }] }, { "remote": "my_remote3", "items": [{ "recipe": { "id": "fake3/0.1@user/channel" }, "packages": [] }] }] } self.assertEqual(expected_result, info) def test_without_packages(self): self.search_recorder.add_recipe("my_remote1", _ref("fake1/0.1@user/channel"), None) self.search_recorder.add_recipe("my_remote2", _ref("fake2/0.1@user/channel"), None) self.search_recorder.add_recipe("my_remote3", _ref("fake3/0.1@user/channel"), None) info = self.search_recorder.get_info() expected_result = { "error": False, "results": [{ "remote": "my_remote1", "items": [{ "recipe": { "id": "fake1/0.1@user/channel" } }] }, { "remote": "my_remote2", "items": [{ "recipe": { "id": "fake2/0.1@user/channel" } }] }, { "remote": "my_remote3", "items": [{ "recipe": { "id": "fake3/0.1@user/channel" } }] }] } self.assertEqual(expected_result, info)