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

Auto format using Black (20.8b1) Added black --check to build. #1546

Closed
wants to merge 1 commit into from
Closed
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
116 changes: 72 additions & 44 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -16,45 +16,69 @@

# Run command `locust --help` and store output in cli-help-output.txt which is included in the docs
def save_locust_help_output():
cli_help_output_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "cli-help-output.txt")
print("Running `locust --help` command and storing output in %s" % cli_help_output_file)
cli_help_output_file = os.path.join(
os.path.abspath(os.path.dirname(__file__)), "cli-help-output.txt"
)
print(
"Running `locust --help` command and storing output in %s"
% cli_help_output_file
)
help_output = subprocess.check_output(["locust", "--help"]).decode("utf-8")
with open(cli_help_output_file, "w") as f:
f.write(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)
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
)
parser = get_empty_argument_parser()
setup_parser_arguments(parser)
table_data = []
for action in parser._actions:
if action.env_var:
table_data.append((
", ".join(["``%s``" % c for c in action.option_strings]),
"``%s``" % action.env_var,
", ".join(["``%s``" % c for c in parser.get_possible_config_keys(action) if not c.startswith("--")]),
action.help,
))
table_data.append(
(
", ".join(["``%s``" % c for c in action.option_strings]),
"``%s``" % action.env_var,
", ".join(
[
"``%s``" % c
for c in parser.get_possible_config_keys(action)
if not c.startswith("--")
]
),
action.help,
)
)
colsizes = [max(len(r[i]) for r in table_data) for i in range(len(table_data[0]))]
formatter = ' '.join('{:<%d}' % c for c in colsizes)
formatter = " ".join("{:<%d}" % c for c in colsizes)
rows = [formatter.format(*row) for row in table_data]
edge = formatter.format(*['=' * c for c in colsizes])
divider = formatter.format(*['-' * c for c in colsizes])
headline = formatter.format(*["Command line", "Environment", "Config file", "Description"])
output = "\n".join([
edge,
headline,
divider,
"\n".join(rows),
edge,
])
edge = formatter.format(*["=" * c for c in colsizes])
divider = formatter.format(*["-" * c for c in colsizes])
headline = formatter.format(
*["Command line", "Environment", "Config file", "Description"]
)
output = "\n".join(
[
edge,
headline,
divider,
"\n".join(rows),
edge,
]
)
with open(env_options_output_file, "w") as f:
f.write(output)


save_locust_env_variables()


@@ -69,29 +93,29 @@ def save_locust_env_variables():

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", 'sphinx_search.extension']
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinx_search.extension"]

# autoclass options
#autoclass_content = "both"
# autoclass_content = "both"

autodoc_typehints = 'none' # I would have liked to use 'description' but unfortunately it too is very verbose
autodoc_typehints = "none" # I would have liked to use 'description' but unfortunately it too is very verbose

# Add any paths that contain templates here, relative to this directory.
#templates_path = ["_templates"]
# templates_path = ["_templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General substitutions.
project = 'Locust'
#copyright = ''
project = "Locust"
# copyright = ''

# Intersphinx config
intersphinx_mapping = {
'requests': ('https://requests.readthedocs.io/en/latest/', None),
"requests": ("https://requests.readthedocs.io/en/latest/", None),
}


@@ -100,12 +124,12 @@ def save_locust_env_variables():

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# today = ''
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%B %d, %Y'
today_fmt = "%B %d, %Y"

# List of documents that shouldn't be included in the build.
#unused_docs = []
# unused_docs = []

# If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True
@@ -118,9 +142,9 @@ def save_locust_env_variables():
# output. They are ignored by default.
show_authors = False

# Sphinx will recurse into subversion configuration folders and try to read
# any document file within. These should be ignored.
# Note: exclude_dirnames is new in Sphinx 0.5
# Sphinx will recurse into subversion configuration folders and try to read
# any document file within. These should be ignored.
# Note: exclude_dirnames is new in Sphinx 0.5
exclude_dirnames = []

# Options for HTML output
@@ -131,30 +155,34 @@ def save_locust_env_variables():


# on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]


# Custom CSS overrides
html_static_path = ["_static"]
html_context = {
"css_files": ["_static/theme-overrides.css", "_static/css/rtd_sphinx_search.min.css"],
"css_files": [
"_static/theme-overrides.css",
"_static/css/rtd_sphinx_search.min.css",
],
}


# HTML theme
#html_theme = "haiku"
# html_theme = "haiku"

#html_theme = "default"
#html_theme_options = {
# html_theme = "default"
# html_theme_options = {
# "rightsidebar": "true",
# "codebgcolor": "#fafcfa",
# "bodyfont": "Arial",
#}
# }

# The name of the Pygments (syntax highlighting) style to use.
#pygments_style = 'trac'
# pygments_style = 'trac'
2 changes: 1 addition & 1 deletion examples/add_command_line_argument.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ def _(parser):
type=str,
env_var="LOCUST_MY_ARGUMENT",
default="",
help="It's working"
help="It's working",
)


8 changes: 6 additions & 2 deletions examples/basic.py
Original file line number Diff line number Diff line change
@@ -4,22 +4,26 @@
def index(l):
l.client.get("/")


def stats(l):
l.client.get("/stats/requests")


class UserTasks(TaskSet):
# one can specify tasks like this
tasks = [index, stats]

# but it might be convenient to use the @task decorator
@task
def page404(self):
self.client.get("/does_not_exist")



class WebsiteUser(HttpUser):
"""
User class that does requests to the locust web server running on localhost
"""

host = "http://127.0.0.1:8089"
wait_time = between(2, 5)
tasks = [UserTasks]
8 changes: 2 additions & 6 deletions examples/browse_docs_sequence_test.py
Original file line number Diff line number Diff line change
@@ -16,19 +16,15 @@ def index_page(self):
r = self.client.get("/")
pq = PyQuery(r.content)
link_elements = pq(".toctree-wrapper a.internal")
self.toc_urls = [
l.attrib["href"] for l in link_elements
]
self.toc_urls = [l.attrib["href"] for l in link_elements]

@task
def load_page(self, url=None):
url = random.choice(self.toc_urls)
r = self.client.get(url)
pq = PyQuery(r.content)
link_elements = pq("a.internal")
self.urls_on_current_page = [
l.attrib["href"] for l in link_elements
]
self.urls_on_current_page = [l.attrib["href"] for l in link_elements]

@task
def load_sub_page(self):
24 changes: 10 additions & 14 deletions examples/browse_docs_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This locust test script example will simulate a user
# This locust test script example will simulate a user
# browsing the Locust documentation on https://docs.locust.io/

import random
@@ -11,26 +11,22 @@ def on_start(self):
# assume all users arrive at the index page
self.index_page()
self.urls_on_current_page = self.toc_urls

@task(10)
def index_page(self):
r = self.client.get("/")
pq = PyQuery(r.content)
link_elements = pq(".toctree-wrapper a.internal")
self.toc_urls = [
l.attrib["href"] for l in link_elements
]

self.toc_urls = [l.attrib["href"] for l in link_elements]

@task(50)
def load_page(self, url=None):
url = random.choice(self.toc_urls)
r = self.client.get(url)
pq = PyQuery(r.content)
link_elements = pq("a.internal")
self.urls_on_current_page = [
l.attrib["href"] for l in link_elements
]

self.urls_on_current_page = [l.attrib["href"] for l in link_elements]

@task(30)
def load_sub_page(self):
url = random.choice(self.urls_on_current_page)
@@ -40,9 +36,9 @@ def load_sub_page(self):
class AwesomeUser(HttpUser):
tasks = [BrowseDocumentation]
host = "https://docs.locust.io/en/latest/"
# we assume someone who is browsing the Locust docs,
# generally has a quite long waiting time (between
# 20 and 600 seconds), since there's a bunch of text

# we assume someone who is browsing the Locust docs,
# generally has a quite long waiting time (between
# 20 and 600 seconds), since there's a bunch of text
# on each page
wait_time = between(20, 600)
10 changes: 7 additions & 3 deletions examples/custom_shape/double_wave.py
Original file line number Diff line number Diff line change
@@ -35,9 +35,13 @@ def tick(self):
run_time = round(self.get_run_time())

if run_time < self.time_limit:
user_count = ((self.peak_one_users - self.min_users) * math.e ** -((run_time/(self.time_limit/10*2/3))-5) ** 2
+ (self.peak_two_users - self.min_users) * math.e ** - ((run_time/(self.time_limit/10*2/3))-10) ** 2
+ self.min_users)
user_count = (
(self.peak_one_users - self.min_users)
* math.e ** -(((run_time / (self.time_limit / 10 * 2 / 3)) - 5) ** 2)
+ (self.peak_two_users - self.min_users)
* math.e ** -(((run_time / (self.time_limit / 10 * 2 / 3)) - 10) ** 2)
+ self.min_users
)
return (round(user_count), round(user_count))
else:
return None
12 changes: 6 additions & 6 deletions examples/custom_shape/stages.py
Original file line number Diff line number Diff line change
@@ -30,12 +30,12 @@ class StagesShape(LoadTestShape):
"""

stages = [
{'duration': 60, 'users': 10, 'spawn_rate': 10},
{'duration': 100, 'users': 50, 'spawn_rate': 10},
{'duration': 180, 'users': 100, 'spawn_rate': 10},
{'duration': 220, 'users': 30, 'spawn_rate': 10},
{'duration': 230, 'users': 10, 'spawn_rate': 10},
{'duration': 240, 'users': 1, 'spawn_rate': 1},
{"duration": 60, "users": 10, "spawn_rate": 10},
{"duration": 100, "users": 50, "spawn_rate": 10},
{"duration": 180, "users": 100, "spawn_rate": 10},
{"duration": 220, "users": 30, "spawn_rate": 10},
{"duration": 230, "users": 10, "spawn_rate": 10},
{"duration": 240, "users": 1, "spawn_rate": 1},
]

def tick(self):
Loading