Skip to content
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

Use f-strings when possible in feature/steps files #532

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions features/steps/cleaner_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ def check_help_from_cleaner(context):

# check if the output contains expected help message
# any optional garbage above and below help message is ignored
assert expected_output.strip() in stdout.strip(), "{} != {}".format(
stdout, expected_output
)
assert expected_output.strip() in stdout.strip(), f"{stdout} != {expected_output}"


def check_version_from_cleaner(context):
Expand All @@ -177,7 +175,7 @@ def check_version_from_cleaner(context):
# check the output
assert (
"Insights Results Aggregator Cleaner version 1.0" in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


def check_authors_info_from_cleaner(context):
Expand All @@ -189,7 +187,7 @@ def check_authors_info_from_cleaner(context):
# check the output
assert (
"Pavel Tisnovsky, Red Hat Inc." in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


@then("I should see info about configuration displayed by cleaner on standard output")
Expand Down Expand Up @@ -242,6 +240,4 @@ def check_non_empty_list_of_records(context):
found_clusters.add(cluster_name)

# compare both sets
assert expected_clusters == found_clusters, "Difference: {}".format(
expected_clusters ^ found_clusters
)
assert expected_clusters == found_clusters, f"Difference: {expected_clusters ^ found_clusters}"
14 changes: 6 additions & 8 deletions features/steps/cleaner_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def ensure_database_emptiness(context):
cursor = context.connection.cursor()
for table in DB_TABLES:
try:
cursor.execute("SELECT 1 from {}".format(table))
cursor.execute(f"SELECT 1 from {table}")
_ = cursor.fetchone()
context.connection.commit()
print("DB name: ", context.connection.info.dsn_parameters)
raise Exception("Table '{}' exists".format(table))
raise Exception(f"Table '{table}' exists")
except UndefinedTable:
# exception means that the table does not exists
context.connection.rollback()
Expand All @@ -43,12 +43,10 @@ def ensure_data_tables_emptiness(context):
for table in DB_TABLES:
cursor = context.connection.cursor()
try:
cursor.execute("SELECT count(*) as cnt from {}".format(table))
cursor.execute(f"SELECT count(*) as cnt from {table}")
results = cursor.fetchone()
assert len(results) == 1, "Wrong number of records returned: {}".format(
len(results)
)
assert results[0] == 0, "Table '{}' is not empty as expected".format(table)
assert len(results) == 1, f"Wrong number of records returned: {len(results)}"
assert results[0] == 0, f"Table '{table}' is not empty as expected"
except Exception:
raise

Expand All @@ -59,7 +57,7 @@ def delete_all_tables(context):
for table in DB_TABLES:
cursor = context.connection.cursor()
try:
cursor.execute("DROP TABLE {}".format(table))
cursor.execute(f"DROP TABLE {table}")
context.connection.commit()
except Exception:
context.connection.rollback()
Expand Down
8 changes: 4 additions & 4 deletions features/steps/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def look_for_executable_file(context, filename):
def file_was_found(context):
"""Check if the file was found on PATH."""
assert context.found is not None, \
"executable filaname '{}' is not on PATH".format(context.filename)
f"executable filaname '{context.filename}' is not on PATH"


@then("The process should finish with exit code {exit_code:d}")
def check_process_exit_code(context, exit_code):
"""Check exit code of process."""
assert context.return_code == exit_code, \
"Unexpected exit code {}. Output:\n{}".format(context.return_code, context.output)
f"Unexpected exit code {context.return_code}. Output:\n{context.output}"


@then('I should see following message in service output: "{message}"')
Expand All @@ -61,7 +61,7 @@ def check_message_in_output(context, message):
if message in line:
break
else:
raise Exception("Expected message not found in {}".format(context.output))
raise Exception(f"Expected message not found in {context.output}")


@then("BuildTime is a proper datetime stamp")
Expand All @@ -84,7 +84,7 @@ def check_db_version(context):
# just try to parse the version, that's all
version = int(dbVersion)

assert version >= 1, "Improper DB version {}".format(version)
assert version >= 1, f"Improper DB version {version}"


@when("I wait {number:n} seconds")
Expand Down
4 changes: 2 additions & 2 deletions features/steps/common_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def look_for_table(context, table):
"""Try to find a table in database."""
cursor = context.connection.cursor()
try:
cursor.execute("SELECT 1 from {}".format(table))
cursor.execute(f"SELECT 1 from {table}")
_ = cursor.fetchone()
context.table_found = True
except UndefinedTable:
Expand Down Expand Up @@ -129,7 +129,7 @@ def check_number_of_tables(context, expected=1):
context.connection.commit()

# result is returned as tuple -> we need to get the 1st item from that tuple
assert len(count) == 1, "Wrong number of records returned: {}".format(len(count))
assert len(count) == 1, f"Wrong number of records returned: {len(count)}"
count = count[0]

# check number of tables returned
Expand Down
2 changes: 1 addition & 1 deletion features/steps/exporter_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def check_generated_files(context):
# iterate over all items in feature table
for row in context.table:
filename = row["File name"]
assert exists(filename), "File {} does not exist".format(filename)
assert exists(filename), f"File {filename} does not exist"
12 changes: 4 additions & 8 deletions features/steps/exporter_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def check_help_from_exporter(context):
assert isinstance(stdout, str), "wrong type of stdout object"

# check the output
assert stdout.strip() == expected_output.strip(), "{} != {}".format(
stdout, expected_output
)
assert stdout.strip() == expected_output.strip(), f"{stdout} != {expected_output}"


def check_version_from_exporter(context):
Expand All @@ -103,7 +101,7 @@ def check_version_from_exporter(context):
# check the output
assert (
"Insights Results Aggregator Exporter version 1.0" in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


def check_authors_info_from_exporter(context):
Expand All @@ -115,7 +113,7 @@ def check_authors_info_from_exporter(context):
# check the output
assert (
"Pavel Tisnovsky, Red Hat Inc." in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


@then("I should see info about configuration displayed by exporter on standard output")
Expand All @@ -140,6 +138,4 @@ def check_configuration_info_from_exporter(context):

# iterate through expected artefacts and check if its names are found in generated output
for expected_artefact in expected_artefacts:
assert expected_artefact in stdout, "{} not found in output".format(
expected_artefact
)
assert expected_artefact in stdout, f"{expected_artefact} not found in output"
2 changes: 1 addition & 1 deletion features/steps/insights_content_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_build_time(context):
r".{3} .{3}[ ]{1,2}[0-9]{1,2} [0-9]{2}:[0-9]{2}:[0-9]{2} ([AP]M )?[A-Z]{1,5} [0-9]{4}"
)
match = re.match(pattern, buildTime)
assert match.group(0), "BuildTime is not a date time: {}".format(buildTime)
assert match.group(0), f"BuildTime is not a date time: {buildTime}"


@then("BuildVersion is in the proper format")
Expand Down
16 changes: 7 additions & 9 deletions features/steps/insights_results_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ def check_help_from_aggregator(context):

# check if the output contains expected help message
# any optional garbage above and below help message is ignored
assert expected_output.strip() in stdout.strip(), "{} != {}".format(
stdout, expected_output
)
assert expected_output.strip() in stdout.strip(), f"{stdout} != {expected_output}"


def check_version_from_aggregator(context):
Expand All @@ -147,10 +145,10 @@ def check_actual_configuration_for_aggregator(context):
i = find_block(context.output, "{")

# check the output
assert "Broker" in context.output[i+1], "Caught output: {}".format(context.output)
assert "Address" in context.output[i+2], "Caught output: {}".format(context.output)
assert "SecurityProtocol" in context.output[i+3], "Caught output: {}".format(context.output)
assert "CertPath" in context.output[i+4], "Caught output: {}".format(context.output)
assert "Broker" in context.output[i+1], f"Caught output: {context.output}"
assert "Address" in context.output[i+2], f"Caught output: {context.output}"
assert "SecurityProtocol" in context.output[i+3], f"Caught output: {context.output}"
assert "CertPath" in context.output[i+4], f"Caught output: {context.output}"


@when("I migrate aggregator database to version #{version:n}")
Expand Down Expand Up @@ -272,7 +270,7 @@ def check_empty_list_of_organizations(context):

# check if the list is empty
assert len(found_organizations) == 0, \
"Expected no organizations but {} has been returned".format(found_organizations)
f"Expected no organizations but {found_organizations} has been returned"


@then("I should retrieve empty list of clusters")
Expand All @@ -284,7 +282,7 @@ def check_empty_list_of_clusters(context):

# check if the list is empty
assert len(found_clusters) == 0, \
"Expected no clusters but {} has been returned".format(found_clusters)
f"Expected no clusters but {found_clusters} has been returned"


@when("I ask for list of all disabled rules for organization {organization:d} account number {account}, and user {user}") # noqa E501
Expand Down
18 changes: 8 additions & 10 deletions features/steps/insights_results_aggregator_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def check_help_from_mock(context):
assert isinstance(stdout, str), "wrong type of stdout object"

# check the output
assert stdout.strip() == expected_output.strip(), "{} != {}".format(
stdout, expected_output
)
assert stdout.strip() == expected_output.strip(), f"{stdout} != {expected_output}"


def check_version_from_mock(context):
Expand All @@ -82,7 +80,7 @@ def check_version_from_mock(context):
assert isinstance(context.output, list), "wrong type of output"

# check the output
assert "Version:\t0.1" in context.output, "Caught output: {}".format(context.output)
assert "Version:\t0.1" in context.output, f"Caught output: {context.output}"


def check_authors_info_from_mock(context):
Expand All @@ -94,7 +92,7 @@ def check_authors_info_from_mock(context):
# check the output
assert (
"Pavel Tisnovsky <[email protected]>" in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


@then("I should see actual configuration displayed by Insights Results Aggregator Mock on standard output") # noqa E501
Expand All @@ -105,11 +103,11 @@ def check_actual_configuration(context):
assert isinstance(context.output, list), "wrong type of output"

# check the output
assert "Server" in context.output[1], "Caught output: {}".format(context.output)
assert "Address" in context.output[2], "Caught output: {}".format(context.output)
assert "APIPrefix" in context.output[3], "Caught output: {}".format(context.output)
assert "APISpecFile" in context.output[4], "Caught output: {}".format(context.output)
assert "Content" in context.output[7], "Caught output: {}".format(context.output)
assert "Server" in context.output[1], f"Caught output: {context.output}"
assert "Address" in context.output[2], f"Caught output: {context.output}"
assert "APIPrefix" in context.output[3], f"Caught output: {context.output}"
assert "APISpecFile" in context.output[4], f"Caught output: {context.output}"
assert "Content" in context.output[7], f"Caught output: {context.output}"


@when("I request list of organizations")
Expand Down
4 changes: 1 addition & 3 deletions features/steps/jps.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def get_all_jvm_based_applications(context):
assert stdout is not None, "No output from application"

# check the return code of a process
assert out.returncode == 0, "Return code is {}, but 0 is expected".format(
out.returncode
)
assert out.returncode == 0, f"Return code is {out.returncode}, but 0 is expected"

# try to decode output
output = stdout.decode("utf-8").split("\n")
Expand Down
2 changes: 1 addition & 1 deletion features/steps/kafka_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def retrieve_broker_metadata(context, hostname=None, port=None):
if hostname is None or port is None:
hostname = context.kafka_hostname
port = context.kafka_port
address = "{}:{}".format(hostname, port)
address = f"{hostname}:{port}"

out = subprocess.Popen(
["kcat", "-b", address, "-L", "-J"],
Expand Down
16 changes: 6 additions & 10 deletions features/steps/notification_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def ensure_database_contains_all_tables(context):
cursor = context.connection.cursor()
for table in DB_TABLES:
try:
cursor.execute("SELECT 1 from {}".format(table))
cursor.execute(f"SELECT 1 from {table}")
_ = cursor.fetchone()
cursor.execute(f"TRUNCATE TABLE {table} CASCADE")
context.connection.commit()
Expand All @@ -108,7 +108,7 @@ def database_contains_all_tables(context):
cursor = context.connection.cursor()
for table in DB_TABLES:
try:
cursor.execute("SELECT 1 from {}".format(table))
cursor.execute(f"SELECT 1 from {table}")
_ = cursor.fetchone()
context.connection.commit()
except UndefinedTable as e:
Expand All @@ -122,7 +122,7 @@ def ensure_database_emptiness(context):
cursor = context.connection.cursor()
for table in DB_TABLES_LATEST:
try:
cursor.execute("SELECT 1 from {}".format(table))
cursor.execute(f"SELECT 1 from {table}")
_ = cursor.fetchone()
raise TableExistsException(table)
except UndefinedTable:
Expand All @@ -140,11 +140,9 @@ def select_all_rows_from_table(context, table):
"""Select number of all rows from given table."""
cursor = context.connection.cursor()
try:
cursor.execute("SELECT count(*) as cnt from {}".format(table))
cursor.execute(f"SELECT count(*) as cnt from {table}")
results = cursor.fetchone()
assert len(results) == 1, "Wrong number of records returned: {}".format(
len(results)
)
assert len(results) == 1, f"Wrong number of records returned: {len(results)}"
context.query_count = results[0]
except Exception as e:
raise e
Expand All @@ -156,9 +154,7 @@ def check_rows_count(context, expected_count):
"""Check if expected number of rows were returned."""
assert (
context.query_count == expected_count
), "Wrong number of rows returned: {} instead of {}".format(
context.query_count, expected_count
)
), f"Wrong number of rows returned: {context.query_count} instead of {expected_count}"


@when("I insert following row into table new_reports")
Expand Down
12 changes: 5 additions & 7 deletions features/steps/notification_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def process_ccx_notification_writer_output(context, out, return_code):
# check the return code of a process
assert (
out.returncode == 0 or out.returncode == return_code
), "Return code is {}".format(out.returncode)
), f"Return code is {out.returncode}"

# try to decode output
output = stdout.decode("utf-8").split("\n")
Expand Down Expand Up @@ -115,9 +115,7 @@ def check_help_from_ccx_notification_writer(context):

updated_output = stdout.replace("\t", " ").strip()
# check the output
assert updated_output == expected_output.strip(), "{} != {}".format(
stdout, expected_output
)
assert updated_output == expected_output.strip(), f"{stdout} != {expected_output}"


def check_version_from_ccx_notification_writer(context):
Expand All @@ -129,7 +127,7 @@ def check_version_from_ccx_notification_writer(context):
# check the output
assert (
"CCX Notification Writer version 1.0" in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


def check_authors_info_from_ccx_notification_writer(context):
Expand All @@ -141,7 +139,7 @@ def check_authors_info_from_ccx_notification_writer(context):
# check the output
assert (
"Pavel Tisnovsky, Red Hat Inc." in context.output
), "Caught output: {}".format(context.output)
), f"Caught output: {context.output}"


@then("the process should exit with status code set to {expected_code:d}")
Expand All @@ -150,7 +148,7 @@ def check_status_code(context, expected_code):
# check the return code of a process
assert (
context.returncode == expected_code
), "Return code is {}, but {} is expected".format(context.returncode, expected_code)
), f"Return code is {context.returncode}, but {expected_code} is expected"


@given("CCX Notification database is empty")
Expand Down
Loading