Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberw committed Sep 13, 2024
1 parent d54546a commit 7eb1d9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
44 changes: 28 additions & 16 deletions locust_plugins/users/ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, environment):
self.user = None
self.host = None

def connect(self, user='anonymous', password='anonymous@', port=21, timeout=5, tls=False, passive_mode=False):
def connect(self, user="anonymous", password="anonymous@", port=21, timeout=5, tls=False, passive_mode=False):
self.user = user
if tls:
self.connection = ftplib.FTP_TLS()
Expand All @@ -46,22 +46,28 @@ def download_file(self, remote_file_name, local_dir_path):
exception = None
response = ""
try:
with open(local_file_path, 'wb') as local_file:
with open(local_file_path, "wb") as local_file:
response = self.connection.retrbinary("RETR " + remote_file_name, local_file.write)
response_time = (time.perf_counter() - start_perf_counter) * 1000
except ftplib.all_errors as e:
exception = e
response_time = (time.perf_counter() - start_perf_counter) * 1000

if exception:
self.environment.events.request.fire(request_type="FTP download", name=remote_file_name,
exception=exception,
response_time=response_time,
response_length=len(str(exception)))
self.environment.events.request.fire(
request_type="FTP download",
name=remote_file_name,
exception=exception,
response_time=response_time,
response_length=len(str(exception)),
)
else:
self.environment.events.request.fire(request_type="FTP download", name=remote_file_name,
response_time=response_time,
response_length=len(response))
self.environment.events.request.fire(
request_type="FTP download",
name=remote_file_name,
response_time=response_time,
response_length=len(response),
)

def upload_file(self, local_file_path):
local_file_path = os.path.normpath(local_file_path)
Expand All @@ -77,14 +83,20 @@ def upload_file(self, local_file_path):
response_time = (time.perf_counter() - start_perf_counter) * 1000

if exception:
self.environment.events.request.fire(request_type="FTP upload", name=local_file_path,
exception=exception,
response_time=response_time,
response_length=len(str(exception)))
self.environment.events.request.fire(
request_type="FTP upload",
name=local_file_path,
exception=exception,
response_time=response_time,
response_length=len(str(exception)),
)
else:
self.environment.events.request.fire(request_type="FTP upload", name=local_file_path,
response_time=response_time,
response_length=len(response))
self.environment.events.request.fire(
request_type="FTP upload",
name=local_file_path,
response_time=response_time,
response_length=len(response),
)

def disconnect(self):
self.connection.close()
2 changes: 1 addition & 1 deletion test/test_missing_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_error_messages(self):
with self.assertLogs("root") as cm:
with self.assertRaises(SystemExit):
importlib.import_module(module)
self.assertIn("you need to install it using \"pip install", cm.output[0])
self.assertIn('you need to install it using "pip install', cm.output[0])

0 comments on commit 7eb1d9f

Please sign in to comment.