Refactor the code of osccore-qa-testing-tools to comply with PEP8.
Related-prod: PRODX-42195
Change-Id: Id05e7584e0d024127ce1bd5042cfe681a1b52e2d
diff --git a/testrail_bot/control/utils.py b/testrail_bot/control/utils.py
index 2038aba..6c41f58 100644
--- a/testrail_bot/control/utils.py
+++ b/testrail_bot/control/utils.py
@@ -1,6 +1,7 @@
-from parse import parse
-from typing import Dict, List, Callable, Any
+from typing import Any, Callable, Dict, List
+
from django.core.cache import cache
+from parse import parse
def parse_title(test_name):
@@ -22,7 +23,7 @@
return f"{r['test_title']}[{r['id']}]"
except TypeError:
# return file_name.test_class.test_name in other complicated cases
- return '.'.join(test_name.split(".")[:3])
+ return ".".join(test_name.split(".")[:3])
def short_names_for_dict(_dict):
@@ -36,16 +37,17 @@
return __dict
-def get_dict_diff(dict1: dict,
- dict2: dict,
- compare_by_key=None) -> Dict[str, List]:
+def get_dict_diff(
+ dict1: dict, dict2: dict, compare_by_key=None
+) -> Dict[str, List]:
all_keys = sorted(set(list(dict1.keys()) + list(dict2.keys())))
result = dict()
for k in all_keys:
if compare_by_key:
if dict1.get(k, {}).get(compare_by_key) == dict2.get(k, {}).get(
- compare_by_key):
+ compare_by_key
+ ):
continue
else:
if dict1.get(k) == dict2.get(k):
@@ -61,9 +63,10 @@
return r
-def cached(timeout: int = None,
- condition_for_endless_cache: Callable = lambda x: False
- ) -> Callable:
+def cached(
+ timeout: int = None,
+ condition_for_endless_cache: Callable = lambda x: False,
+) -> Callable:
"""
:param timeout: (in seconds) usage accordingly
https://docs.djangoproject.com/en/4.2/topics/cache/#basic-usage
@@ -74,17 +77,18 @@
:return: decorator
"""
+
def decorator(func: Callable) -> Callable:
def wrapper(*args, **kwargs) -> Any:
- cache_key = f'{func.__name__}_{args}_{kwargs}'
- cache_key = replace_all(cache_key, "{}()\'\" .,:", "_")
+ cache_key = f"{func.__name__}_{args}_{kwargs}"
+ cache_key = replace_all(cache_key, "{}()'\" .,:", "_")
cached_value = cache.get(cache_key)
if cached_value is None:
print(f"{func.__name__} MISS")
result = func(*args, **kwargs)
- _timeout = None \
- if condition_for_endless_cache(result) \
- else timeout
+ _timeout = (
+ None if condition_for_endless_cache(result) else timeout
+ )
cache.set(cache_key, result, timeout=_timeout)
return result
@@ -99,7 +103,9 @@
# # ENDFIXME
return cached_value
+
return wrapper
+
return decorator