diff options
author | Simon Glass <sjg@chromium.org> | 2025-04-29 07:22:19 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2025-05-27 10:07:41 +0100 |
commit | 3fd99e2177c17539f4101151cb061e8f7700d6a1 (patch) | |
tree | b8e292fdfbf92fe88792c0311d4688dacfc1c027 /tools/patman/patchwork.py | |
parent | 3c5f27ce124e0025b48601b8c811ccfe45f0fe3a (diff) |
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 <sjg@chromium.org>
Diffstat (limited to 'tools/patman/patchwork.py')
-rw-r--r-- | tools/patman/patchwork.py | 26 |
1 files changed, 26 insertions, 0 deletions
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 |