Skip to content

Commit

Permalink
linter: apply more strict ruff rules
Browse files Browse the repository at this point in the history
Signed-off-by: Evgeniy Zayats <zayatsevgeniy@nspcc.io>
  • Loading branch information
Evgeniy Zayats committed Jan 17, 2025
1 parent 74045cb commit b600cdd
Show file tree
Hide file tree
Showing 36 changed files with 261 additions and 291 deletions.
2 changes: 1 addition & 1 deletion neofs-testlib/neofs_testlib/blockchain/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _call_endpoint(self, method, params=None) -> Dict[str, Any]:
return response.json()
except Exception as exc:
raise NeoRPCException(
f"Could not call method {method} " f"with endpoint: {self.endpoint}: {exc}" f"\nRequest sent: {payload}"
f"Could not call method {method} with endpoint: {self.endpoint}: {exc}\nRequest sent: {payload}"
) from exc


Expand Down
2 changes: 1 addition & 1 deletion neofs-testlib/neofs_testlib/cli/cli_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _format_command(self, command: str, **params) -> str:
val_str = str(value_item).replace("'", "\\'")
param_str.append(f"--{param} '{val_str}'")
elif isinstance(value, dict):
param_str.append(f'--{param} \'{",".join(f"{key}={val}" for key, val in value.items())}\'')
param_str.append(f"--{param} '{','.join(f'{key}={val}' for key, val in value.items())}'")
else:
if "'" in str(value):
value_str = str(value).replace('"', '\\"')
Expand Down
14 changes: 7 additions & 7 deletions neofs-testlib/neofs_testlib/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def download_binary(repo: str, version: str, file: str, target: str):
tar_file.extractall()
tar_file.close()
os.remove(target)
logger.info(f"rename: {file.rstrip(".tar.gz")} into {target}")
logger.info(f"rename: {file.rstrip('.tar.gz')} into {target}")
os.rename(file.rstrip(".tar.gz"), target)
elif "warp" in file:
temp_dir = f"temp_dir_{uuid.uuid4()}"
Expand Down Expand Up @@ -1368,11 +1368,11 @@ def prepare(
)
result = self.neofs_env.shell.exec(command)
assert not result.return_code, "RC after k6 prepare script is not zero"
assert (
f"Total Containers has been created: {containers}" in result.stdout
), "Prepare script didn't create requested containers"
assert (
f"Total Objects has been created: {preload_obj}" in result.stdout
), "Prepare script didn't create requested objects"
assert f"Total Containers has been created: {containers}" in result.stdout, (
"Prepare script didn't create requested containers"
)
assert f"Total Objects has been created: {preload_obj}" in result.stdout, (
"Prepare script didn't create requested objects"
)

shutil.copy(out, os.path.join(self.xk6_dir, "scenarios"))
4 changes: 2 additions & 2 deletions neofs-testlib/neofs_testlib/shell/local_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _exec_interactive(self, command: str, options: CommandOptions) -> CommandRes
self._report_command_result(command, start_time, end_time, result)

if options.check and result.return_code != 0:
raise RuntimeError(f"Command: {command}\nreturn code: {result.return_code}\n" f"Output: {result.stdout}")
raise RuntimeError(f"Command: {command}\nreturn code: {result.return_code}\nOutput: {result.stdout}")
return result

def _exec_non_interactive(self, command: str, options: CommandOptions) -> CommandResult:
Expand Down Expand Up @@ -95,7 +95,7 @@ def _exec_non_interactive(self, command: str, options: CommandOptions) -> Comman
return_code=exc.returncode,
)
raise RuntimeError(
f"Command: {command}\nError:\n" f"return code: {exc.returncode}\n" f"output: {exc.output}"
f"Command: {command}\nError:\nreturn code: {exc.returncode}\noutput: {exc.output}"
) from exc
except (OSError, subprocess.SubprocessError) as exc:
raise RuntimeError(f"Command: {command}\nOutput: {exc.strerror}") from exc
Expand Down
2 changes: 1 addition & 1 deletion neofs-testlib/neofs_testlib/shell/ssh_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def _create_connection(self, attempts: int = SSH_CONNECTION_ATTEMPTS) -> SSHClie
)
else:
logger.info(
f"Trying to connect to host {self.host} as {self.login} using password " f"(attempt {attempt})"
f"Trying to connect to host {self.host} as {self.login} using password (attempt {attempt})"
)
connection.connect(
hostname=self.host,
Expand Down
2 changes: 1 addition & 1 deletion neofs-testlib/neofs_testlib_tests/unit/test_local_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_command_with_one_prompt(self):
self.assertEqual("", result.stderr)

def test_command_with_several_prompts(self):
script = "input1 = input('Input1: '); print(input1); " "input2 = input('Input2: '); print(input2)"
script = "input1 = input('Input1: '); print(input1); input2 = input('Input2: '); print(input2)"
inputs = [
InteractiveInput(prompt_pattern="Input1", input="test1"),
InteractiveInput(prompt_pattern="Input2", input="test2"),
Expand Down
4 changes: 1 addition & 3 deletions neofs-testlib/neofs_testlib_tests/unit/test_ssh_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def test_command_with_one_prompt(self):
self.assertEqual("", result.stderr)

def test_command_with_several_prompts(self):
script = (
"input1 = input('Input1: '); print('\\n' + input1); " "input2 = input('Input2: '); print('\\n' + input2)"
)
script = "input1 = input('Input1: '); print('\\n' + input1); input2 = input('Input2: '); print('\\n' + input2)"
inputs = [
InteractiveInput(prompt_pattern="Input1", input="test1"),
InteractiveInput(prompt_pattern="Input2", input="test2"),
Expand Down
4 changes: 2 additions & 2 deletions pytest_tests/lib/helpers/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __str__(self):
return (
",".join(
[
f"{filter.header_type.value}:" f"{filter.key}{filter.match_type.value}{filter.value}"
f"{filter.header_type.value}:{filter.key}{filter.match_type.value}{filter.value}"
for filter in self.filters
]
)
Expand All @@ -140,7 +140,7 @@ def to_dict(self) -> Dict[str, Any]:

def __str__(self):
role = self.role.value if isinstance(self.role, EACLRole) else f"{self.role.role_type.value}:{self.role.value}"
return f'{self.access.value} {self.operation.value} {self.filters or ""} {role}'
return f"{self.access.value} {self.operation.value} {self.filters or ''} {role}"


@allure.title("Get extended ACL")
Expand Down
49 changes: 16 additions & 33 deletions pytest_tests/lib/helpers/aws_cli_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,41 @@ def list_buckets(self) -> dict:
return self._to_json(output)

def get_bucket_acl(self, Bucket: str) -> dict:
cmd = f"aws {self.common_flags} s3api get-bucket-acl --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
cmd = f"aws {self.common_flags} s3api get-bucket-acl --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd, REGULAR_TIMEOUT)
return self._to_json(output)

def get_bucket_versioning(self, Bucket: str) -> dict:
cmd = (
f"aws {self.common_flags} s3api get-bucket-versioning --bucket {Bucket} "
f"--endpoint {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3api get-bucket-versioning --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd, REGULAR_TIMEOUT)
return self._to_json(output)

def get_bucket_location(self, Bucket: str) -> dict:
cmd = (
f"aws {self.common_flags} s3api get-bucket-location --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3api get-bucket-location --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd, REGULAR_TIMEOUT)
return self._to_json(output)

def put_bucket_versioning(self, Bucket: str, VersioningConfiguration: dict) -> dict:
cmd = (
f"aws {self.common_flags} s3api put-bucket-versioning --bucket {Bucket} "
f'--versioning-configuration Status={VersioningConfiguration.get("Status")} '
f"--versioning-configuration Status={VersioningConfiguration.get('Status')} "
f"--endpoint {self.s3gate_endpoint}"
)
output = _cmd_run(cmd)
return self._to_json(output)

def list_objects(self, Bucket: str) -> dict:
cmd = f"aws {self.common_flags} s3api list-objects --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
cmd = f"aws {self.common_flags} s3api list-objects --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

def list_objects_v2(self, Bucket: str) -> dict:
cmd = f"aws {self.common_flags} s3api list-objects-v2 --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
cmd = f"aws {self.common_flags} s3api list-objects-v2 --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

def list_object_versions(self, Bucket: str) -> dict:
cmd = (
f"aws {self.common_flags} s3api list-object-versions --bucket {Bucket} "
f"--endpoint {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3api list-object-versions --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

Expand Down Expand Up @@ -247,7 +239,7 @@ def put_bucket_acl(
GrantWrite: Optional[str] = None,
GrantRead: Optional[str] = None,
) -> dict:
cmd = f"aws {self.common_flags} s3api put-bucket-acl --bucket {Bucket} " f" --endpoint {self.s3gate_endpoint}"
cmd = f"aws {self.common_flags} s3api put-bucket-acl --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
if ACL:
cmd += f" --acl {ACL}"
if GrantWrite:
Expand Down Expand Up @@ -306,14 +298,12 @@ def delete_bucket(self, Bucket: str) -> dict:
return self._to_json(output)

def get_bucket_tagging(self, Bucket: str) -> dict:
cmd = (
f"aws {self.common_flags} s3api get-bucket-tagging --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3api get-bucket-tagging --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

def get_bucket_policy(self, Bucket: str) -> dict:
cmd = f"aws {self.common_flags} s3api get-bucket-policy --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
cmd = f"aws {self.common_flags} s3api get-bucket-policy --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

Expand All @@ -326,7 +316,7 @@ def put_bucket_policy(self, Bucket: str, Policy: dict) -> dict:
return self._to_json(output)

def get_bucket_cors(self, Bucket: str) -> dict:
cmd = f"aws {self.common_flags} s3api get-bucket-cors --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
cmd = f"aws {self.common_flags} s3api get-bucket-cors --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

Expand All @@ -339,9 +329,7 @@ def put_bucket_cors(self, Bucket: str, CORSConfiguration: dict) -> dict:
return self._to_json(output)

def delete_bucket_cors(self, Bucket: str) -> dict:
cmd = (
f"aws {self.common_flags} s3api delete-bucket-cors --bucket {Bucket} " f"--endpoint {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3api delete-bucket-cors --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

Expand All @@ -354,10 +342,7 @@ def put_bucket_tagging(self, Bucket: str, Tagging: dict) -> dict:
return self._to_json(output)

def delete_bucket_tagging(self, Bucket: str) -> dict:
cmd = (
f"aws {self.common_flags} s3api delete-bucket-tagging --bucket {Bucket} "
f"--endpoint {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3api delete-bucket-tagging --bucket {Bucket} --endpoint {self.s3gate_endpoint}"
output = _cmd_run(cmd)
return self._to_json(output)

Expand Down Expand Up @@ -421,9 +406,7 @@ def sync(
ACL: Optional[str] = None,
Metadata: Optional[dict] = None,
) -> dict:
cmd = (
f"aws {self.common_flags} s3 sync {dir_path} s3://{bucket_name} " f"--endpoint-url {self.s3gate_endpoint}"
)
cmd = f"aws {self.common_flags} s3 sync {dir_path} s3://{bucket_name} --endpoint-url {self.s3gate_endpoint}"
if Metadata:
cmd += " --metadata"
for key, value in Metadata.items():
Expand Down Expand Up @@ -537,7 +520,7 @@ def get_object_lock_configuration(self, Bucket):
def put_bucket_ownership_controls(self, Bucket, OwnershipControls):
cmd = (
f"aws {self.common_flags} s3api put-bucket-ownership-controls --bucket {Bucket} "
f"--ownership-controls '{{\"Rules\": [{{\"ObjectOwnership\": \"{OwnershipControls['Rules'][0]['ObjectOwnership']}\"}}]}}' "
f'--ownership-controls \'{{"Rules": [{{"ObjectOwnership": "{OwnershipControls["Rules"][0]["ObjectOwnership"]}"}}]}}\' '
f"--endpoint-url {self.s3gate_endpoint}"
)
output = _cmd_run(cmd)
Expand All @@ -546,7 +529,7 @@ def put_bucket_ownership_controls(self, Bucket, OwnershipControls):
def generate_presigned_url(self, ClientMethod: str, Params: dict, ExpiresIn: int, HttpMethod: str):
cmd = (
f"aws s3 {self.common_flags} --endpoint {self.s3gate_endpoint} presign "
f"s3://{Params["Bucket"]}/{Params["Key"]} --expires-in {ExpiresIn}"
f"s3://{Params['Bucket']}/{Params['Key']} --expires-in {ExpiresIn}"
)
return _cmd_run(cmd)

Expand Down
14 changes: 6 additions & 8 deletions pytest_tests/lib/helpers/cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,14 @@ def _cmd_run(cmd: str, timeout: int = 30) -> str:

return output
except subprocess.CalledProcessError as exc:
logger.info(f"Command: {cmd}\n" f"Error:\nreturn code: {exc.returncode} " f"\nOutput: {exc.output}")
logger.info(f"Command: {cmd}\nError:\nreturn code: {exc.returncode} \nOutput: {exc.output}")
end_time = datetime.now(UTC)
return_code, cmd_output = subprocess.getstatusoutput(cmd)
_attach_allure_log(cmd, cmd_output, return_code, start_time, end_time)

raise RuntimeError(
f"Command: {cmd}\n" f"Error:\nreturn code: {exc.returncode}\n" f"Output: {exc.output}"
) from exc
raise RuntimeError(f"Command: {cmd}\nError:\nreturn code: {exc.returncode}\nOutput: {exc.output}") from exc
except OSError as exc:
raise RuntimeError(f"Command: {cmd}\n" f"Output: {exc.strerror}") from exc
raise RuntimeError(f"Command: {cmd}\nOutput: {exc.strerror}") from exc
except Exception as exc:
return_code, cmd_output = subprocess.getstatusoutput(cmd)
end_time = datetime.now(UTC)
Expand Down Expand Up @@ -114,7 +112,7 @@ def _attach_allure_log(cmd: str, output: str, return_code: int, start_time: date
f"RC: {return_code}\n"
f"Start / End / Elapsed\t {start_time.time()} / {end_time.time()} / {end_time - start_time}"
)
with allure.step(f'COMMAND: {shorten(cmd, width=60, placeholder="...")}'):
with allure.step(f"COMMAND: {shorten(cmd, width=60, placeholder='...')}"):
allure.attach(command_attachment, "Command execution", allure.attachment_type.TEXT)


Expand All @@ -123,6 +121,6 @@ def log_command_execution(cmd: str, output: Union[str, dict]) -> None:
with suppress(Exception):
json_output = json.dumps(output, indent=4, sort_keys=True)
output = json_output
command_attachment = f"COMMAND: '{cmd}'\n" f"OUTPUT:\n {output}\n"
with allure.step(f'COMMAND: {shorten(cmd, width=60, placeholder="...")}'):
command_attachment = f"COMMAND: '{cmd}'\nOUTPUT:\n {output}\n"
with allure.step(f"COMMAND: {shorten(cmd, width=60, placeholder='...')}"):
allure.attach(command_attachment, "Command execution", allure.attachment_type.TEXT)
2 changes: 1 addition & 1 deletion pytest_tests/lib/helpers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

NEOFS_CONTRACT = os.getenv("NEOFS_IR_CONTRACTS_NEOFS")

TEST_RUN_DIR = f"test-run-{datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%d-%H-%M-%S-%f")}"
TEST_RUN_DIR = f"test-run-{datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d-%H-%M-%S-%f')}"
TEST_FILES_DIR = os.getenv("TEST_FILES_DIR", "TestFilesDir")
TEST_OBJECTS_DIR = os.getenv("TEST_OBJECTS_DIR", "TestObjectsDir")
DEVENV_PATH = os.getenv("DEVENV_PATH", os.path.join("..", "neofs-dev-env"))
Expand Down
4 changes: 1 addition & 3 deletions pytest_tests/lib/helpers/neofs_verbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,7 @@ def search_object(

if expected_objects_list:
if sorted(found_objects) == sorted(expected_objects_list):
logger.info(
f"Found objects list '{found_objects}' " f"is equal for expected list '{expected_objects_list}'"
)
logger.info(f"Found objects list '{found_objects}' is equal for expected list '{expected_objects_list}'")
else:
warning = f"Found object list {found_objects} is not equal to expected list '{expected_objects_list}'"
logger.warning(warning)
Expand Down
6 changes: 3 additions & 3 deletions pytest_tests/lib/helpers/object_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def can_get_object(
except OPERATION_ERROR_TYPE as err:
assert error_matches_status(err, OBJECT_ACCESS_DENIED), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
return False
assert get_file_hash(file_name) == get_file_hash(
got_file_path
), "file hash of downloaded object is not equal to the uploaded"
assert get_file_hash(file_name) == get_file_hash(got_file_path), (
"file hash of downloaded object is not equal to the uploaded"
)
return True


Expand Down
4 changes: 1 addition & 3 deletions pytest_tests/lib/helpers/remote_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ def clear(self) -> None:
@allure.step("Start remote process")
def _start_process(self) -> None:
self.shell.exec(
f"nohup {self.process_dir}/command.sh </dev/null "
f">{self.process_dir}/stdout "
f"2>{self.process_dir}/stderr &"
f"nohup {self.process_dir}/command.sh </dev/null >{self.process_dir}/stdout 2>{self.process_dir}/stderr &"
)

@allure.step("Create process directory")
Expand Down
2 changes: 1 addition & 1 deletion pytest_tests/lib/helpers/rest_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def upload_via_rest_gate_curl(


def _attach_allure_step(request: str, status_code: int, req_type="GET"):
command_attachment = f"REQUEST: '{request}'\n" f"RESPONSE:\n {status_code}\n"
command_attachment = f"REQUEST: '{request}'\nRESPONSE:\n {status_code}\n"
with allure.step(f"{req_type} Request"):
allure.attach(command_attachment, f"{req_type} Request", allure.attachment_type.TEXT)

Expand Down
Loading

0 comments on commit b600cdd

Please sign in to comment.