Skip to content

Commit 6aeef5a

Browse files
committed
fix: ruff linter
1 parent f298038 commit 6aeef5a

File tree

14 files changed

+92
-275
lines changed

14 files changed

+92
-275
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3131
- name: Run linters
3232
run: |
33-
black .
34-
ruff .
33+
ruff linter
34+
ruff format
3535
- name: Run example test
3636
run: |
3737
cd app

app/features/environment.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ def before_all(context):
2626
def before_scenario(context, scenario):
2727
"""define before scenario"""
2828
if context.test_settings.env not in scenario.effective_tags:
29-
if (
30-
PRIMARY_DEV_ENV in scenario.effective_tags
31-
and context.test_settings.env in SECONDARY_DEV_ENVS
32-
):
29+
if PRIMARY_DEV_ENV in scenario.effective_tags and context.test_settings.env in SECONDARY_DEV_ENVS:
3330
logging.info("Mapping primary development env to secondary envs")
3431
else:
3532
scenario.skip(
@@ -97,9 +94,7 @@ def before_feature(context, feature):
9794
"""runs before a feature"""
9895
for scenario in feature.scenarios:
9996
if "autoretry" in scenario.effective_tags:
100-
patch_scenario_with_autoretry(
101-
scenario, max_attempts=int(settings.autoretry_attempts)
102-
)
97+
patch_scenario_with_autoretry(scenario, max_attempts=int(settings.autoretry_attempts))
10398

10499

105100
def after_step(context, step):

app/support/apiclientactions/apiclient.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ def get_valid_rest_api_token(self):
3131
key = token["api_key"]
3232

3333
params = {"code": key}
34-
response = requests.get(
35-
url, params=params, verify=False, timeout=int(settings.wait_time)
36-
)
34+
response = requests.get(url, params=params, verify=False, timeout=int(settings.wait_time))
3735
if response.status_code != 200:
38-
logging.warning(
39-
"Request {url} returned response code: {response.status_code}"
40-
)
36+
logging.warning("Request {url} returned response code: {response.status_code}")
4137
return response.text
4238

4339
def call_rest_api(self, url):
@@ -54,9 +50,7 @@ def get_auth_token(self, sb_name, sas_name, sas_value, eh_name=""):
5450
Returns an authorization token dictionary
5551
for making calls to Event Hubs REST API.
5652
"""
57-
uri = urllib.parse.quote_plus(
58-
"https://{}.servicebus.windows.net/{}".format(sb_name, eh_name)
59-
)
53+
uri = urllib.parse.quote_plus("https://{}.servicebus.windows.net/{}".format(sb_name, eh_name))
6054
sas = sas_value.encode("utf-8")
6155
expiry = str(int(time.time() + 10000))
6256
string_to_sign = (uri + "\n" + expiry).encode("utf-8")
@@ -65,7 +59,5 @@ def get_auth_token(self, sb_name, sas_name, sas_value, eh_name=""):
6559
return {
6660
"sb_name": sb_name,
6761
"eh_name": eh_name,
68-
"token": "SharedAccessSignature sr={}&sig={}&se={}&skn={}".format(
69-
uri, signature, expiry, sas_name
70-
),
62+
"token": "SharedAccessSignature sr={}&sig={}&se={}&skn={}".format(uri, signature, expiry, sas_name),
7163
}

app/support/builders/example/examplerequestbuilder.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ class XMLMessageBuilder:
1616
def __init__(self, context):
1717
self.faker = Faker("en_GB")
1818
self.context = context
19-
self.environment = Environment(
20-
loader=FileSystemLoader("templates/"), autoescape=True
21-
)
19+
self.environment = Environment(loader=FileSystemLoader("templates/"), autoescape=True)
2220

2321
def header(self, auth_token):
2422
"""builds request header for a message"""

app/support/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class Settings:
1313
def __init__(self):
1414
settings_file = os.environ.get("SETTINGS_FILE_PATH")
1515
if not settings_file:
16-
settings_file = os.path.join(
17-
os.path.dirname(os.path.abspath(__file__)), "test_settings.json"
18-
)
16+
settings_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_settings.json")
1917

2018
with open(settings_file, encoding="utf-8") as file:
2119
setting = json.load(file)

app/support/core/elementaction.py

Lines changed: 30 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ def fetch_element(
7373

7474
try:
7575
WebDriverWait(self.context.driver, element_timeout).until(
76-
ec.visibility_of_element_located(
77-
(getattr(By, strategy), actual_locator)
78-
)
76+
ec.visibility_of_element_located((getattr(By, strategy), actual_locator))
7977
)
8078
except (TimeoutException, StaleElementReferenceException):
8179
logging.debug(
@@ -86,14 +84,10 @@ def fetch_element(
8684
)
8785

8886
if is_list_of_elements:
89-
return self.context.driver.find_elements(
90-
getattr(By, strategy), actual_locator
91-
)
87+
return self.context.driver.find_elements(getattr(By, strategy), actual_locator)
9288

9389
try:
94-
element = self.context.driver.find_element(
95-
getattr(By, strategy), actual_locator
96-
)
90+
element = self.context.driver.find_element(getattr(By, strategy), actual_locator)
9791
return element
9892
except TypeError:
9993
return False
@@ -119,9 +113,7 @@ def fetch_element(
119113
+ "'}"
120114
) from ex
121115

122-
def is_element_present(
123-
self, locator, replacement=None, timeout=None, retry_refresh_browser=False
124-
):
116+
def is_element_present(self, locator, replacement=None, timeout=None, retry_refresh_browser=False):
125117
"""Verify if element is present on page
126118
:param locator: element locator
127119
:param replacement: if locator contains dynamic part, i.e. '$value',
@@ -141,16 +133,12 @@ def is_element_present(
141133
def scroll_down_javascript(self, locator, pixel=0):
142134
"""Scrolls down javascript element"""
143135
try:
144-
self.execute_java_script(
145-
f"document.querySelector('{locator}').scrollTop={pixel}"
146-
)
136+
self.execute_java_script(f"document.querySelector('{locator}').scrollTop={pixel}")
147137
logging.info("Scrolling on element '%s' using JavaScript", locator)
148138
except Exception:
149139
Assert.assert_fail(f"Unable to scroll on element with locator {locator}")
150140

151-
def is_element_displayed(
152-
self, locator, replacement=None, timeout=None, retry_refresh_browser=False
153-
):
141+
def is_element_displayed(self, locator, replacement=None, timeout=None, retry_refresh_browser=False):
154142
"""Verify if element is present on page
155143
:param locator: element locator
156144
:param replacement: if locator contains dynamic part, i.e. '$value',
@@ -165,9 +153,7 @@ def is_element_displayed(
165153
if not self.fetch_element(locator, False, timeout, retry_refresh_browser):
166154
logging.info("Unable to find element '%s'", locator)
167155
return False
168-
return self.fetch_element(
169-
locator, False, timeout, retry_refresh_browser
170-
).is_displayed()
156+
return self.fetch_element(locator, False, timeout, retry_refresh_browser).is_displayed()
171157
except Exception:
172158
return False
173159

@@ -191,13 +177,9 @@ def is_text_present(self, locator, text, timeout=None):
191177
strategy = locator.split(",")[0].strip()
192178
actual_locator = locator.replace(strategy + ",", "")
193179

194-
logging.info(
195-
"Waiting for text '%s' to be present in '%s'", text, locator
196-
)
180+
logging.info("Waiting for text '%s' to be present in '%s'", text, locator)
197181
WebDriverWait(self.context.driver, timeout).until(
198-
ec.text_to_be_present_in_element(
199-
(getattr(By, strategy), actual_locator), text
200-
)
182+
ec.text_to_be_present_in_element((getattr(By, strategy), actual_locator), text)
201183
)
202184
logging.info("Found text '%s' present in '%s'", text, locator)
203185
return True
@@ -218,9 +200,7 @@ def is_text_present(self, locator, text, timeout=None):
218200
logging.info("Failed to find text '%s' present in '%s'", text, locator)
219201
return False
220202

221-
def is_element_checked(
222-
self, locator, replacement=None, timeout=None, retry_refresh_browser=False
223-
):
203+
def is_element_checked(self, locator, replacement=None, timeout=None, retry_refresh_browser=False):
224204
"""Verify is element is checked
225205
:param locator: element locator
226206
:param replacement: if locator contains dynamic part, i.e. '$value',
@@ -233,9 +213,7 @@ def is_element_checked(
233213
locator = locator.replace("$value", replacement)
234214

235215
try:
236-
is_element_checked = self.fetch_element(
237-
locator, False, timeout, retry_refresh_browser
238-
).is_selected()
216+
is_element_checked = self.fetch_element(locator, False, timeout, retry_refresh_browser).is_selected()
239217
logging.info(
240218
"Checked status for element '%s' is '%s'",
241219
locator,
@@ -261,9 +239,7 @@ def is_element_clickable(self, locator):
261239
actual_locator = locator.replace(strategy + ",", "").strip()
262240
timeout = int(settings.wait_time)
263241

264-
logging.info(
265-
"Checking element '%s' (%s) is clickable", actual_locator, strategy
266-
)
242+
logging.info("Checking element '%s' (%s) is clickable", actual_locator, strategy)
267243
WebDriverWait(self.context.driver, timeout).until(
268244
ec.element_to_be_clickable((getattr(By, strategy), actual_locator))
269245
)
@@ -314,9 +290,7 @@ def click(
314290
if timeout is None:
315291
timeout = int(settings.wait_time)
316292

317-
logging.info(
318-
"Checking element '%s' (%s) is clickable", actual_locator, strategy
319-
)
293+
logging.info("Checking element '%s' (%s) is clickable", actual_locator, strategy)
320294
WebDriverWait(self.context.driver, timeout).until(
321295
ec.element_to_be_clickable((getattr(By, strategy), actual_locator))
322296
)
@@ -345,32 +319,24 @@ def click(
345319
self.execute_java_script("arguments[0].click();", element)
346320
logging.info("Clicked on element '%s' using JavaScript", locator)
347321
except Exception as ex1:
348-
logging.warning(
349-
"Unable to click on element '%s' using JavaScript", locator
350-
)
322+
logging.warning("Unable to click on element '%s' using JavaScript", locator)
351323
logging.debug(ex1)
352324

353325
try:
354-
logging.info(
355-
"Clicking on element '%s' using ActionChains", locator
356-
)
326+
logging.info("Clicking on element '%s' using ActionChains", locator)
357327
element = self.fetch_element(locator)
358328
actions = ActionChains(self.context.driver)
359329
actions.move_to_element(element)
360330
actions.click(element)
361331
actions.perform()
362-
logging.info(
363-
"Clicked on element '%s' using ActionChains", locator
364-
)
332+
logging.info("Clicked on element '%s' using ActionChains", locator)
365333
except Exception as ex2:
366334
logging.warning(
367335
"Unable to click on element '%s' using ActionChains",
368336
locator,
369337
)
370338
logging.debug(ex2)
371-
Assert.assert_fail(
372-
"Unable to click on element '" + locator + "'"
373-
)
339+
Assert.assert_fail("Unable to click on element '" + locator + "'")
374340
# Adding a small delay after a click increases test reliability
375341
sleep(delay)
376342

@@ -394,14 +360,10 @@ def type(self, locator, text, delay: float = 0.2, sensitive: boolean = False):
394360
if sensitive:
395361
logging.info("Typed text ***** on element %s", locator, exc_info=True)
396362
else:
397-
logging.info(
398-
"Typed text %s on element %s", text, locator, exc_info=True
399-
)
363+
logging.info("Typed text %s on element %s", text, locator, exc_info=True)
400364
except Exception:
401365
logging.error("Unable to type text %s on element %s.", text, locator)
402-
Assert.assert_fail(
403-
"Unable to type text '" + text + "' on element '" + locator + "'"
404-
)
366+
Assert.assert_fail("Unable to type text '" + text + "' on element '" + locator + "'")
405367

406368
def type_using_actionschains(self, locator, text, delay: float = 0.5):
407369
"""Type text in locator
@@ -433,9 +395,7 @@ def type_using_actionschains(self, locator, text, delay: float = 0.5):
433395
locator,
434396
exc_info=True,
435397
)
436-
Assert.assert_fail(
437-
"Unable to type text '" + text + "' on element '" + locator + "'"
438-
)
398+
Assert.assert_fail("Unable to type text '" + text + "' on element '" + locator + "'")
439399

440400
def user_tab_on_element(self, locator=None, delay=0.5, replacement=None):
441401
"""user performs tab keystroke
@@ -738,9 +698,7 @@ def select_by_visible_text(self, locator, option_text, replacement=None):
738698
select = Select(self.fetch_element(locator))
739699
select.select_by_visible_text(option_text)
740700

741-
logging.info(
742-
"Selected element + %s+ by visible text + %s+ ", locator, option_text
743-
)
701+
logging.info("Selected element + %s+ by visible text + %s+ ", locator, option_text)
744702
except Exception:
745703
logging.error(
746704
"Unable to select option + %s +",
@@ -759,26 +717,20 @@ def switch_to_frame(self, frame_number, assert_it=True):
759717
self.context.driver.switch_to.frame(frame_number)
760718
logging.info("Successfully switched frame")
761719
except Exception:
762-
logging.info(
763-
"Frame not loaded yet! Waiting for another 10 seconds for frame to load..."
764-
)
720+
logging.info("Frame not loaded yet! Waiting for another 10 seconds for frame to load...")
765721
sleep(int(settings.wait_time))
766722

767723
try:
768724
self.context.driver.switch_to.frame(frame_number)
769-
logging.info(
770-
"Successfully switched to frame numbered + %s+ ", str(frame_number)
771-
)
725+
logging.info("Successfully switched to frame numbered + %s+ ", str(frame_number))
772726
except Exception:
773727
logging.error(
774728
"Unable to locate frame numbered + %s+ ",
775729
str(frame_number),
776730
exc_info=True,
777731
)
778732
if assert_it:
779-
Assert.assert_fail(
780-
"Unable to locate frame numbered '" + str(frame_number) + "' "
781-
)
733+
Assert.assert_fail("Unable to locate frame numbered '" + str(frame_number) + "' ")
782734

783735
def switch_to_default_content(self, assert_it=True, delay=0.5):
784736
"""Switch to parent window
@@ -789,15 +741,11 @@ def switch_to_default_content(self, assert_it=True, delay=0.5):
789741
self.context.driver.switch_to.default_content()
790742
logging.info("Successfully switched to default frame")
791743
except Exception as ex:
792-
logging.error(
793-
"Unable to switch to default content! Error: %s", ex, exc_info=True
794-
)
744+
logging.error("Unable to switch to default content! Error: %s", ex, exc_info=True)
795745
if assert_it:
796746
Assert.assert_fail("Unable to switch to default content!")
797747

798-
def switch_to_new_window(
799-
self, count=0, expected_window_url=None, validate_url=False, delay=0.5
800-
):
748+
def switch_to_new_window(self, count=0, expected_window_url=None, validate_url=False, delay=0.5):
801749
"""switch to the new window"""
802750
sleep(delay)
803751
tabs = self.context.driver.window_handles
@@ -809,9 +757,7 @@ def switch_to_new_window(
809757
else:
810758
for tab in tabs:
811759
self.context.driver.switch_to.window(tab)
812-
logging.info(
813-
"Switching to tab URL: %s", self.context.driver.current_url
814-
)
760+
logging.info("Switching to tab URL: %s", self.context.driver.current_url)
815761
opened_urls.append(self.context.driver.current_url)
816762
return opened_urls
817763

@@ -846,9 +792,7 @@ def close_other_tabs(self, delay=0.5):
846792
logging.info("Length of Driver = %s ", driver_len)
847793
if driver_len > 1:
848794
for i in range(driver_len - 1, 0, -1):
849-
self.context.driver.switch_to.window(
850-
self.context.driver.window_handles[i]
851-
)
795+
self.context.driver.switch_to.window(self.context.driver.window_handles[i])
852796
self.context.driver.close()
853797
print("Closed Tab No. ", i)
854798
self.context.driver.switch_to.window(self.context.driver.window_handles[0])
@@ -879,9 +823,7 @@ def press_key(self, locator, key, replacement=None):
879823
locator,
880824
exc_info=True,
881825
)
882-
Assert.assert_fail(
883-
"Unable to press key '" + key + "' on element '" + locator + "' "
884-
)
826+
Assert.assert_fail("Unable to press key '" + key + "' on element '" + locator + "' ")
885827

886828
def input_attachment_1(self, locator, filename):
887829
"""Add attachment"""
@@ -977,9 +919,7 @@ def convert_pdf_to_txt(self, path):
977919
def extract_text_by_page(self, pdf_path):
978920
"""extract text by page"""
979921
with open(pdf_path, "rb") as file_handle:
980-
for page in PDFPage.get_pages(
981-
file_handle, caching=True, check_extractable=True
982-
):
922+
for page in PDFPage.get_pages(file_handle, caching=True, check_extractable=True):
983923
resource_manager = PDFResourceManager()
984924
fake_file_handle = io.StringIO()
985925

0 commit comments

Comments
 (0)