-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,8 @@ | |
|
||
def complete_libraries(needle: str,) -> List[str]: | ||
"""Complete library names.""" | ||
matches = [] | ||
|
||
for lib in list(STDLIBS) + list(get_root_modules()): | ||
if needle in lib.lower(): | ||
matches.append(lib) | ||
|
||
return matches | ||
return [ | ||
lib | ||
for lib in list(STDLIBS) + list(get_root_modules()) | ||
if needle in lib.lower() | ||
] | ||
Comment on lines
-10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ def execute_ipywidget( | |
arguments, | ||
values, | ||
): | ||
header = rpa and "Tasks" or "Test Cases" | ||
header = "Tasks" if rpa else "Test Cases" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
code += f"""\ | ||
|
||
*** {header} *** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,10 +174,7 @@ def end_test(self, name, attributes): | |
|
||
|
||
def clear_drivers(drivers, type_): | ||
remained = [] | ||
for driver in drivers: | ||
if driver.get("type") != type_: | ||
remained.append(driver) | ||
remained = [driver for driver in drivers if driver.get("type") != type_] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
drivers.clear() | ||
drivers.extend(remained) | ||
|
||
|
@@ -189,10 +186,12 @@ def get_webdrivers(cache, type_): | |
conn = cache._connections[idx] | ||
if conn in cache._closed: | ||
continue | ||
aliases = [] | ||
for alias, idx_ in cache._aliases.items(): | ||
if (idx + 1) == idx_: | ||
aliases.append(alias) | ||
aliases = [ | ||
alias | ||
for alias, idx_ in cache._aliases.items() | ||
if (idx + 1) == idx_ | ||
] | ||
|
||
Comment on lines
-192
to
+194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
drivers.append( | ||
dict( | ||
instance=conn, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ def read(self, ipynbfile, rawdata): | |
|
||
for cell in notebook.cells: | ||
# Skip non-code cells | ||
if not cell.cell_type == "code": | ||
if cell.cell_type != "code": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
continue | ||
|
||
# Execute %%python module magics | ||
|
@@ -60,21 +60,19 @@ def read(self, ipynbfile, rawdata): | |
|
||
if HAS_RF32_PARSER: | ||
return data | ||
else: | ||
robotfile = BytesIO(data.encode("UTF-8")) | ||
return RobotReader().read(robotfile, rawdata, ipynbfile.name) | ||
robotfile = BytesIO(data.encode("UTF-8")) | ||
return RobotReader().read(robotfile, rawdata, ipynbfile.name) | ||
|
||
return NotebookReader() | ||
|
||
|
||
def _get_ipynb_file(old): | ||
def _get_file(self, source, accept_text): | ||
path = self._get_path(source, accept_text) | ||
if path and os.path.splitext(path)[1].lower() == ".ipynb": | ||
file = StringIO(NotebookReader().read(path, "")) | ||
return file, os.path.basename(path), True | ||
else: | ||
if not path or os.path.splitext(path)[1].lower() != ".ipynb": | ||
return old(self, source, accept_text) | ||
file = StringIO(NotebookReader().read(path, "")) | ||
return file, os.path.basename(path), True | ||
Comment on lines
-73
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
return _get_file | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,12 +396,10 @@ def get_selenium_needle_from_user(driver): | |
def get_selenium_css_selector_completions(needle, driver): | ||
needle = needle[4:] | ||
unresolved = [] | ||
results = [] | ||
matches = [] | ||
if not needle: | ||
needle = get_selenium_needle_from_user(driver) | ||
if needle: | ||
results = driver.find_elements_by_css_selector(needle) | ||
results = driver.find_elements_by_css_selector(needle) if needle else [] | ||
Comment on lines
-399
to
+402
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for result in visible_or_all(results): | ||
id_ = result.get_attribute("id") | ||
if " " in needle: # always include simmer result for complex needles | ||
|
@@ -425,10 +423,8 @@ def get_selenium_css_selector_completions(needle, driver): | |
def get_selenium_tag_selector_completions(needle, driver): | ||
needle = needle[4:] | ||
unresolved = [] | ||
results = [] | ||
matches = [] | ||
if needle: | ||
results = driver.find_elements_by_css_selector(needle) | ||
results = driver.find_elements_by_css_selector(needle) if needle else [] | ||
Comment on lines
-428
to
+427
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for result in visible_or_all(results): | ||
id_ = result.get_attribute("id") | ||
if id_: | ||
|
@@ -446,24 +442,22 @@ def get_selenium_tag_selector_completions(needle, driver): | |
|
||
def get_selenium_link_selector_completions(needle, driver): | ||
needle = needle[5:] | ||
matches = [] | ||
if needle: | ||
results = driver.find_elements_by_partial_link_text(needle) | ||
else: | ||
results = driver.find_elements_by_xpath("//a") | ||
for result in visible_or_all(results): | ||
if result.text: | ||
matches.append((f"link:{result.text}", result)) | ||
return matches | ||
return [ | ||
(f"link:{result.text}", result) | ||
for result in visible_or_all(results) | ||
if result.text | ||
] | ||
Comment on lines
-449
to
+453
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def get_selenium_xpath_selector_completions(needle, driver): | ||
needle = needle[6:] | ||
results = [] | ||
matches = [] | ||
unresolved = [] | ||
if needle: | ||
results = driver.find_elements_by_xpath(needle) | ||
results = driver.find_elements_by_xpath(needle) if needle else [] | ||
Comment on lines
-462
to
+460
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for result in visible_or_all(results): | ||
id_ = result.get_attribute("id") | ||
if id_: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,11 @@ def take_screenshot(as_bytes=False): | |
screenshot = Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppPArgb) | ||
graphics = Graphics.FromImage(screenshot) | ||
graphics.CopyFromScreen(0, 0, 0, 0, screenshot.Size) | ||
if as_bytes: | ||
fp = MemoryStream() | ||
screenshot.Save(fp, ImageFormat.Png) | ||
return bytes(bytearray(fp.ToArray())) | ||
else: | ||
if not as_bytes: | ||
return screenshot | ||
fp = MemoryStream() | ||
screenshot.Save(fp, ImageFormat.Png) | ||
return bytes(bytearray(fp.ToArray())) | ||
Comment on lines
-47
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@staticmethod | ||
def pick(snip=False): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,14 +84,12 @@ def lunr_builder(ref, fields): | |
|
||
def readable_keyword(s): | ||
"""Return keyword with only the first letter in title case.""" | ||
if s and not s.startswith("*") and not s.startswith("["): | ||
if s.count("."): | ||
library, name = s.rsplit(".", 1) | ||
return library + "." + name[0].title() + name[1:].lower() | ||
else: | ||
return s[0].title() + s[1:].lower() | ||
else: | ||
if not s or s.startswith("*") or s.startswith("["): | ||
return s | ||
if not s.count("."): | ||
return s[0].title() + s[1:].lower() | ||
library, name = s.rsplit(".", 1) | ||
return library + "." + name[0].title() + name[1:].lower() | ||
Comment on lines
-87
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
def detect_robot_context(code, cursor_pos): | ||
|
@@ -101,18 +99,17 @@ def detect_robot_context(code, cursor_pos): | |
context_parts = code.rsplit("***", 2) | ||
if len(context_parts) != 3: | ||
return "__root__" | ||
context_name = context_parts[1].strip().lower() | ||
if context_name == "settings": | ||
return "__settings__" | ||
elif line.lstrip() == line: | ||
return "__root__" | ||
elif context_name in ["tasks", "test cases"]: | ||
return "__tasks__" | ||
elif context_name == "keywords": | ||
return "__keywords__" | ||
else: | ||
context_name = context_parts[1].strip().lower() | ||
if context_name == "settings": | ||
return "__settings__" | ||
elif line.lstrip() == line: | ||
return "__root__" | ||
elif context_name in ["tasks", "test cases"]: | ||
return "__tasks__" | ||
elif context_name == "keywords": | ||
return "__keywords__" | ||
else: | ||
return "__root__" | ||
return "__root__" | ||
Comment on lines
+102
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
NAME_REGEXP = re.compile("`(.+?)`") | ||
|
@@ -233,12 +230,11 @@ def to_mime_and_metadata(obj) -> (dict, dict): # noqa: C901 | |
try: | ||
if isinstance(obj, str): | ||
return {"text/html": f"<pre>{to_html(obj)}</pre>".replace("\\n", "\n")}, {} | ||
else: | ||
data, metadata = JSON(data=obj, expanded=True)._repr_json_() | ||
return ( | ||
{"application/json": data, "text/html": f"<pre>{to_html(obj)}</pre>"}, | ||
metadata, | ||
) | ||
data, metadata = JSON(data=obj, expanded=True)._repr_json_() | ||
return ( | ||
{"application/json": data, "text/html": f"<pre>{to_html(obj)}</pre>"}, | ||
metadata, | ||
) | ||
Comment on lines
-236
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except (TypeError, JSONDecodeError): | ||
pass | ||
try: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
build_suite
refactored with the following changes:dict-comprehension
)