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>
diff --git a/tools/patman/patchwork.py b/tools/patman/patchwork.py
index e0adbdb..3ec266f 100644
--- a/tools/patman/patchwork.py
+++ b/tools/patman/patchwork.py
@@ -139,6 +139,7 @@
'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 @@
"""
# 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 @@
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