From 3fd99e2177c17539f4101151cb061e8f7700d6a1 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Apr 2025 07:22:19 -0600 Subject: patman: Adjust how the fake request() function is provided Instead of passing the URL and function to each call, put the fake into the Patchwork object instead. Signed-off-by: Simon Glass --- tools/patman/patchwork.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tools/patman/patchwork.py') diff --git a/tools/patman/patchwork.py b/tools/patman/patchwork.py index e0adbdb6481..3ec266f073e 100644 --- a/tools/patman/patchwork.py +++ b/tools/patman/patchwork.py @@ -139,6 +139,7 @@ class Patchwork: 'https://patchwork.ozlabs.org' """ self.url = url + self.fake_request = None self.proj_id = None self.link_name = None self._show_progress = show_progress @@ -160,6 +161,8 @@ class Patchwork: """ # print('subpath', subpath) self.request_count += 1 + if self.fake_request: + return self.fake_request(subpath) full_url = f'{self.url}/api/1.2/{subpath}' async with self.semaphore: @@ -178,6 +181,29 @@ class Patchwork: if i == RETRIES: raise + async def session_request(self, subpath): + async with aiohttp.ClientSession() as client: + return await self._request(client, subpath) + + def request(self, subpath): + return asyncio.run(self.session_request(subpath)) + + @staticmethod + def for_testing(func): + """Get an instance to use for testing + + Args: + func (function): Function to call to handle requests. The function + is passed a URL and is expected to return a dict with the + resulting data + + Returns: + Patchwork: testing instance + """ + pwork = Patchwork(None, show_progress=False) + pwork.fake_request = func + return pwork + async def get_series(self, client, link): """Read information about a series -- cgit v1.2.3