Skip to content

Commit

Permalink
Use f-strings instead of old style string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
tdadela committed Nov 8, 2024
1 parent bb0efad commit f5e2e97
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions locust/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ def _validate_user_class_name_uniqueness(self):
def _validate_shape_class_instance(self):
if self.shape_class is not None and not isinstance(self.shape_class, LoadTestShape):
raise ValueError(
"shape_class should be instance of LoadTestShape or subclass LoadTestShape, but got: %s"
% self.shape_class
f"shape_class should be instance of LoadTestShape or subclass LoadTestShape, but got: {self.shape_class}"
)

@property
Expand Down
2 changes: 1 addition & 1 deletion locust/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def exception_handler(greenlet):
if greenlet.exc_info[0] == SystemExit:
logger.log(
min(logging.INFO, level), # dont use higher than INFO for this, because it sounds way to urgent
"sys.exit(%s) called (use log level DEBUG for callstack)" % greenlet.exc_info[1],
f"sys.exit({greenlet.exc_info[1]}) called (use log level DEBUG for callstack)",
)
logger.log(logging.DEBUG, "Unhandled exception in greenlet: %s", greenlet, exc_info=greenlet.exc_info)
else:
Expand Down
2 changes: 1 addition & 1 deletion locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def stop_and_optionally_quit():
logger.info("--run-time limit reached, stopping test")
runner.stop()
if options.autoquit != -1:
logger.debug("Autoquit time limit set to %s seconds" % options.autoquit)
logger.debug(f"Autoquit time limit set to {options.autoquit} seconds")
time.sleep(options.autoquit)
logger.info("--autoquit time reached, shutting down")
runner.quit()
Expand Down
20 changes: 9 additions & 11 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def spawn(user_class: str, spawn_count: int) -> list[User]:
n += 1
if n % 10 == 0 or n == spawn_count:
logger.debug("%i users spawned" % self.user_count)
logger.debug("All users of class %s spawned" % user_class)
logger.debug(f"All users of class {user_class} spawned")
return new_users

new_users: list[User] = []
Expand Down Expand Up @@ -256,7 +256,7 @@ def stop_users(self, user_classes_stop_count: dict[str, int]) -> None:

while True:
user_to_stop: User = to_stop.pop()
logger.debug("Stopping %s" % user_to_stop.greenlet.name)
logger.debug(f"Stopping {user_to_stop.greenlet.name}")
if user_to_stop.greenlet is greenlet.getcurrent():
# User called runner.quit(), so don't block waiting for killing to finish
user_to_stop.group.killone(user_to_stop.greenlet, block=False)
Expand All @@ -272,8 +272,7 @@ def stop_users(self, user_classes_stop_count: dict[str, int]) -> None:

if not stop_group.join(timeout=self.environment.stop_timeout):
logger.info(
"Not all users finished their tasks & terminated in %s seconds. Stopping them..."
% self.environment.stop_timeout
f"Not all users finished their tasks & terminated in {self.environment.stop_timeout} seconds. Stopping them..."
)
stop_group.kill(block=True)

Expand Down Expand Up @@ -495,7 +494,7 @@ def _start(self, user_count: int, spawn_rate: float, wait: bool = False, user_cl
user_classes_spawn_count: dict[str, int] = {}
user_classes_stop_count: dict[str, int] = {}
user_classes_count = dispatched_users[self._local_worker_node.id]
logger.debug("Ramping to %s" % _format_user_classes_count_for_log(user_classes_count))
logger.debug(f"Ramping to {_format_user_classes_count_for_log(user_classes_count)}")
for user_class_name, user_class_count in user_classes_count.items():
if self.user_classes_count[user_class_name] > user_class_count:
user_classes_stop_count[user_class_name] = (
Expand Down Expand Up @@ -558,7 +557,7 @@ def send_message(self, msg_type: str, data: Any = None, client_id: str | None =
:param msg_type: The type of the message to emulate sending
:param data: Optional data to include
"""
logger.debug("Running locally: sending %s message to self" % msg_type)
logger.debug(f"Running locally: sending {msg_type} message to self")
if msg_type in self.custom_messages:
listener, concurrent = self.custom_messages[msg_type]
msg = Message(msg_type, data, "local")
Expand Down Expand Up @@ -877,7 +876,7 @@ def stop(self, send_stop_to_client: bool = True) -> None:

if send_stop_to_client:
for client in self.clients.all:
logger.debug("Sending stop message to worker %s" % client.id)
logger.debug(f"Sending stop message to worker {client.id}")
self.server.send_to_client(Message("stop", None, client.id))

# Give an additional 60s for all workers to stop
Expand Down Expand Up @@ -987,8 +986,7 @@ def client_listener(self) -> NoReturn:
logger.error(f"RPCError: {e}. Will reset RPC server.")
else:
logger.debug(
"RPCError when receiving from worker: %s (but no workers were expected to be connected anyway)"
% (e)
f"RPCError when receiving from worker: {e} (but no workers were expected to be connected anyway)"
)
self.connection_broken = True
gevent.sleep(FALLBACK_INTERVAL)
Expand Down Expand Up @@ -1410,7 +1408,7 @@ def worker(self) -> NoReturn:
# master says we have finished spawning (happens only once during a normal rampup)
self.environment.events.spawning_complete.fire(user_count=msg.data["user_count"])
elif msg.type in self.custom_messages:
logger.debug("Received %s message from master" % msg.type)
logger.debug(f"Received {msg.type} message from master")
listener, concurrent = self.custom_messages[msg.type]
if not concurrent:
listener(environment=self.environment, msg=msg)
Expand Down Expand Up @@ -1454,7 +1452,7 @@ def send_message(self, msg_type: str, data: dict[str, Any] | None = None, client
:param data: Optional data to send
:param client_id: (unused)
"""
logger.debug("Sending %s message to master" % msg_type)
logger.debug(f"Sending {msg_type} message to master")
self.client.send(Message(msg_type, data, self.client_id))

def _send_stats(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion locust/util/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def check_for_deprecated_task_set_attribute(class_dict):
if issubclass(task_set, TaskSet) and not hasattr(task_set, "locust_task_weight"):
warnings.warn(
"Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead "
"(tasks = [%s])" % task_set.__name__,
f"(tasks = [{task_set.__name__}])",
DeprecationWarning,
)

Expand Down

0 comments on commit f5e2e97

Please sign in to comment.