From ae92adc432a143a9056eb2251f0cd8a40bcd8f64 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Tue, 26 Nov 2019 22:43:05 -0800 Subject: [PATCH] autopep8 (#196) * autopep8 * Update TestCase section --- README.md | 9 +++++++-- proxy/plugin/cache/base.py | 3 ++- proxy/plugin/cache/cache_responses.py | 3 ++- proxy/testing/test_case.py | 6 ++++-- tests/testing/test_test_case.py | 3 ++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cfb114bf..7d7d24ed 100644 --- a/README.md +++ b/README.md @@ -809,10 +809,12 @@ Note that: 1. `proxy.TestCase` overrides `unittest.TestCase.run()` method to setup and teardown `proxy.py`. 2. `proxy.py` server will listen on a random available port on the system. - This random port is available as `self.proxy_port` within your test cases. + This random port is available as `self.PROXY_PORT` within your test cases. 3. Only a single worker is started by default (`--num-workers 1`) for faster setup and teardown. 4. Most importantly, `proxy.TestCase` also ensures `proxy.py` server - is up and running before proceeding with execution of tests. + is up and running before proceeding with execution of tests. By default, + `proxy.TestCase` will wait for `10 seconds` for `proxy.py` server to start, + upon failure a `TimeoutError` exception will be raised. ## Override startup flags @@ -857,6 +859,9 @@ class TestProxyPyEmbedded(unittest.TestCase): super().run(result) ``` +or simply setup / teardown `proxy.py` within +`setUpClass` and `teardownClass` class methods. + Plugin Developer and Contributor Guide ====================================== diff --git a/proxy/plugin/cache/base.py b/proxy/plugin/cache/base.py index 2061bef0..81a2ef65 100644 --- a/proxy/plugin/cache/base.py +++ b/proxy/plugin/cache/base.py @@ -46,7 +46,8 @@ class BaseCacheResponsesPlugin(HttpProxyBasePlugin): logger.info('Caching disabled due to exception message %s', str(e)) return request - def handle_client_request(self, request: HttpParser) -> Optional[HttpParser]: + def handle_client_request( + self, request: HttpParser) -> Optional[HttpParser]: assert self.store return self.store.cache_request(request) diff --git a/proxy/plugin/cache/cache_responses.py b/proxy/plugin/cache/cache_responses.py index 2ad6926d..91f29079 100644 --- a/proxy/plugin/cache/cache_responses.py +++ b/proxy/plugin/cache/cache_responses.py @@ -24,5 +24,6 @@ class CacheResponsesPlugin(BaseCacheResponsesPlugin): def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) - self.disk_store = OnDiskCacheStore(uid=self.uid, cache_dir=tempfile.gettempdir()) + self.disk_store = OnDiskCacheStore( + uid=self.uid, cache_dir=tempfile.gettempdir()) self.set_store(self.disk_store) diff --git a/proxy/testing/test_case.py b/proxy/testing/test_case.py index 67341bb2..cc261f07 100644 --- a/proxy/testing/test_case.py +++ b/proxy/testing/test_case.py @@ -48,7 +48,8 @@ class TestCase(unittest.TestCase): cls.wait_for_server(cls.PROXY_PORT) @staticmethod - def wait_for_server(proxy_port: int, wait_for_seconds: int = DEFAULT_TIMEOUT) -> None: + def wait_for_server(proxy_port: int, + wait_for_seconds: int = DEFAULT_TIMEOUT) -> None: """Wait for proxy.py server to come up.""" start_time = time.time() while True: @@ -61,7 +62,8 @@ class TestCase(unittest.TestCase): time.sleep(0.1) if time.time() - start_time > wait_for_seconds: - raise TimeoutError('Timed out while waiting for proxy.py to start...') + raise TimeoutError( + 'Timed out while waiting for proxy.py to start...') @classmethod def tearDownClass(cls) -> None: diff --git a/tests/testing/test_test_case.py b/tests/testing/test_test_case.py index a3b3e3c7..c1dafa07 100644 --- a/tests/testing/test_test_case.py +++ b/tests/testing/test_test_case.py @@ -18,4 +18,5 @@ class TestTestCase(unittest.TestCase): def test_wait_for_server(self) -> None: with self.assertRaises(TimeoutError): - proxy.TestCase.wait_for_server(get_available_port(), wait_for_seconds=1) + proxy.TestCase.wait_for_server( + get_available_port(), wait_for_seconds=1)