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

Various linting fixes #1549

Merged
merged 3 commits into from
Aug 28, 2020
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
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def save_locust_help_output():
save_locust_help_output()

# Generate RST table with help/descriptions for all available environment variables


def save_locust_env_variables():
env_options_output_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "config-options.rst")
print("Generating RST table for Locust environment variables and storing in %s" % env_options_output_file)
Expand Down
2 changes: 1 addition & 1 deletion examples/events.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

"""
This is an example of a locustfile that uses Locust's built in event hooks to
This is an example of a locustfile that uses Locust's built in event hooks to
track the sum of the content-length header in all successful HTTP responses
"""

Expand Down
4 changes: 2 additions & 2 deletions locust/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_empty_argument_parser(add_help=True, default_config_files=DEFAULT_CONFIG
description=textwrap.dedent(
"""
Usage: locust [OPTIONS] [UserClass ...]

"""
),
# epilog="",
Expand Down Expand Up @@ -255,7 +255,7 @@ def setup_parser_arguments(parser):
"Worker options",
textwrap.dedent(
"""
Options for running a Locust Worker node when running Locust distributed.
Options for running a Locust Worker node when running Locust distributed.
Only the LOCUSTFILE (-f option) need to be specified when starting a Worker, since other options such as -u, -r, -t are specified on the Master node.
"""
),
Expand Down
2 changes: 1 addition & 1 deletion locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class by using the :py:func:`@task decorator <locust.task>` on the methods, or b

client = None
"""
Instance of HttpSession that is created upon instantiation of User.
Instance of HttpSession that is created upon instantiation of User.
The client support cookies, and therefore keeps the session between HTTP requests.
"""

Expand Down
58 changes: 29 additions & 29 deletions locust/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class Events:
request_success = EventHook
"""
Fired when a request is completed successfully. This event is typically used to report requests
when writing custom clients for locust.
when writing custom clients for locust.

Event arguments:

:param request_type: Request type method used
:param name: Path to the URL that was called (or override name if it was used in the call to the client)
:param response_time: Response time in milliseconds
Expand All @@ -63,11 +63,11 @@ class Events:

request_failure = EventHook
"""
Fired when a request fails. This event is typically used to report failed requests when writing
custom clients for locust.
Fired when a request fails. This event is typically used to report failed requests when writing
custom clients for locust.

Event arguments:

:param request_type: Request type method used
:param name: Path to the URL that was called (or override name if it was used in the call to the client)
:param response_time: Time in milliseconds until exception was thrown
Expand All @@ -78,9 +78,9 @@ class Events:
user_error = EventHook
"""
Fired when an exception occurs inside the execution of a User class.

Event arguments:

:param user_instance: User class instance where the exception occurred
:param exception: Exception that was thrown
:param tb: Traceback object (from sys.exc_info()[2])
Expand All @@ -91,11 +91,11 @@ class Events:
Used when Locust is running in --worker mode. It can be used to attach
data to the dicts that are regularly sent to the master. It's fired regularly when a report
is to be sent to the master server.

Note that the keys "stats" and "errors" are used by Locust and shouldn't be overridden.

Event arguments:

:param client_id: The client id of the running locust process.
:param data: Data dict that can be modified in order to attach data that should be sent to the master.
"""
Expand All @@ -104,64 +104,64 @@ class Events:
"""
Used when Locust is running in --master mode and is fired when the master
server receives a report from a Locust worker server.

This event can be used to aggregate data from the locust worker servers.

Event arguments:

:param client_id: Client id of the reporting worker
:param data: Data dict with the data from the worker node
"""

spawning_complete = EventHook
"""
Fired when all simulated users has been spawned.

Event arguments:

:param user_count: Number of users that were spawned
"""

quitting = EventHook
"""
Fired when the locust process is exiting

Event arguments:

:param environment: Environment instance
"""

init = EventHook
"""
Fired when Locust is started, once the Environment instance and locust runner instance
have been created. This hook can be used by end-users' code to run code that requires access to
Fired when Locust is started, once the Environment instance and locust runner instance
have been created. This hook can be used by end-users' code to run code that requires access to
the Environment. For example to register listeners to request_success, request_failure
or other events.

Event arguments:

:param environment: Environment instance
"""

init_command_line_parser = EventHook
"""
Event that can be used to add command line options to Locust

Event arguments:

:param parser: ArgumentParser instance
"""

test_start = EventHook
"""
Fired when a new load test is started. It's not fired again if the number of
users change during a test. When running locust distributed the event is only fired
on the master node and not on each worker node.
Fired when a new load test is started. It's not fired again if the number of
users change during a test. When running locust distributed the event is only fired
on the master node and not on each worker node.
"""

test_stop = EventHook
"""
Fired when a load test is stopped. When running locust distributed the event
Fired when a load test is stopped. When running locust distributed the event
is only fired on the master node and not on each worker node.
"""

Expand Down
4 changes: 2 additions & 2 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def main():
# Increasing the limit to 10000 within a running process should work on at least MacOS.
# It does not work on all OS:es, but we should be no worse off for trying.
resource.setrlimit(resource.RLIMIT_NOFILE, [10000, resource.RLIM_INFINITY])
except:
except BaseException:
logger.warning(
"System open file limit setting is not high enough for load testing, and the OS didn't allow locust to increase it by itself. See https://github.com/locustio/locust/wiki/Installation#increasing-maximum-number-of-open-files-limit for more info."
)
Expand Down Expand Up @@ -393,5 +393,5 @@ def sig_term_handler():
logger.info("Starting Locust %s" % version)
main_greenlet.join()
shutdown()
except KeyboardInterrupt as e:
except KeyboardInterrupt:
shutdown()
6 changes: 3 additions & 3 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ def stop_users(self, user_count, stop_rate=None):
for g in self.user_greenlets:
for l in bucket:
user = g.args[0]
if l == type(user):
if isinstance(user, l):
to_stop.append(user)
bucket.remove(l)
break

if not to_stop:
return

if stop_rate == None or stop_rate >= user_count:
if stop_rate is None or stop_rate >= user_count:
sleep_time = 0
logger.info("Stopping %i users" % (user_count))
else:
Expand Down Expand Up @@ -650,7 +650,7 @@ def client_listener(self):
if self.state == STATE_RUNNING or self.state == STATE_SPAWNING:
# balance the load distribution when new client joins
self.start(self.target_user_count, self.spawn_rate)
## emit a warning if the worker's clock seem to be out of sync with our clock
# emit a warning if the worker's clock seem to be out of sync with our clock
# if abs(time() - msg.data["time"]) > 5.0:
# warnings.warn("The worker node's clock seem to be out of sync. For the statistics to be correct the different locust servers need to have synchronized clocks.")
elif msg.type == "client_stopped":
Expand Down
22 changes: 11 additions & 11 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


"""
Default window size/resolution - in seconds - when calculating the current
Default window size/resolution - in seconds - when calculating the current
response time percentile
"""
CURRENT_RESPONSE_TIME_PERCENTILE_WINDOW = 10
Expand Down Expand Up @@ -86,10 +86,10 @@ def diff_response_time_dicts(latest, old):
percentiles.
"""
new = {}
for time in latest:
diff = latest[time] - old.get(time, 0)
for t in latest:
diff = latest[t] - old.get(t, 0)
if diff:
new[time] = diff
new[t] = diff
return new


Expand Down Expand Up @@ -226,24 +226,24 @@ class StatsEntry(object):
"""
A {response_time => count} dict that holds the response time distribution of all
the requests.
The keys (the response time in ms) are rounded to store 1, 2, ... 9, 10, 20. .. 90,

The keys (the response time in ms) are rounded to store 1, 2, ... 9, 10, 20. .. 90,
100, 200 .. 900, 1000, 2000 ... 9000, in order to save memory.

This dict is used to calculate the median and percentile response times.
"""

use_response_times_cache = False
"""
If set to True, the copy of the response_time dict will be stored in response_times_cache
every second, and kept for 20 seconds (by default, will be CURRENT_RESPONSE_TIME_PERCENTILE_WINDOW + 10).
We can use this dict to calculate the *current* median response time, as well as other response
If set to True, the copy of the response_time dict will be stored in response_times_cache
every second, and kept for 20 seconds (by default, will be CURRENT_RESPONSE_TIME_PERCENTILE_WINDOW + 10).
We can use this dict to calculate the *current* median response time, as well as other response
time percentiles.
"""

response_times_cache = None
"""
If use_response_times_cache is set to True, this will be a {timestamp => CachedResponseTimes()}
If use_response_times_cache is set to True, this will be a {timestamp => CachedResponseTimes()}
OrderedDict that holds a copy of the response_times dict for each of the last 20 seconds.
"""

Expand Down
8 changes: 4 additions & 4 deletions locust/test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def test_logging_output(self):
"""
import logging
from locust import User, task, constant

custom_logger = logging.getLogger("custom_logger")

class MyUser(User):
wait_time = constant(2)
@task
Expand Down Expand Up @@ -103,7 +103,7 @@ def test_skip_logging(self):
textwrap.dedent(
"""
from locust import User, task, constant

class MyUser(User):
wait_time = constant(2)
@task
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_log_to_file(self):
"""
import logging
from locust import User, task, constant

class MyUser(User):
wait_time = constant(2)
@task
Expand Down
2 changes: 0 additions & 2 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ def cpu_task(self):
runners.CPU_MONITOR_INTERVAL = _monitor_interval

def test_weight_locusts(self):
maxDiff = 2048

class BaseUser(User):
pass

Expand Down
6 changes: 3 additions & 3 deletions locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def test_diff_response_times_dicts(self):

class TestStatsEntry(unittest.TestCase):
def parse_string_output(self, text):
tokenlist = re.split("[\s\(\)%|]+", text.strip())
tokenlist = re.split(r"[\s\(\)%|]+", text.strip())
tokens = {
"method": tokenlist[0],
"name": tokenlist[1],
Expand Down Expand Up @@ -687,15 +687,15 @@ def test_request_stats_content_length(self):

def test_request_stats_no_content_length(self):
path = "/no_content_length"
r = self.locust.client.get(path)
self.locust.client.get(path)
self.assertEqual(
self.runner.stats.get(path, "GET").avg_content_length,
len("This response does not have content-length in the header"),
)

def test_request_stats_no_content_length_streaming(self):
path = "/no_content_length"
r = self.locust.client.get(path, stream=True)
self.locust.client.get(path, stream=True)
self.assertEqual(0, self.runner.stats.get(path, "GET").avg_content_length)

def test_request_stats_named_endpoint(self):
Expand Down
Loading