diff --git a/docs/conf.py b/docs/conf.py index a933a8ebde..901be34b28 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,6 +10,12 @@ import os +# The default replacements for |version| and |release|, also used in various +# other places throughout the built documents. +# +# The short X.Y version. +from locust import __version__ + # General configuration # --------------------- @@ -38,11 +44,6 @@ 'requests': ('http://requests.readthedocs.org/en/latest/', None), } -# The default replacements for |version| and |release|, also used in various -# other places throughout the built documents. -# -# The short X.Y version. -from locust import __version__ # The full version, including alpha/beta/rc tags. release = __version__ diff --git a/examples/basic.py b/examples/basic.py index 8850aeb498..c34610e8df 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -1,5 +1,6 @@ from locust import HttpLocust, TaskSet, task + def index(l): l.client.get("/") diff --git a/examples/custom_xmlrpc_client/server.py b/examples/custom_xmlrpc_client/server.py index 536c5852fa..84cd035fe7 100644 --- a/examples/custom_xmlrpc_client/server.py +++ b/examples/custom_xmlrpc_client/server.py @@ -1,7 +1,8 @@ -import time import random +import time from SimpleXMLRPCServer import SimpleXMLRPCServer + def get_time(): time.sleep(random.random()) return time.time() diff --git a/examples/custom_xmlrpc_client/xmlrpc_locustfile.py b/examples/custom_xmlrpc_client/xmlrpc_locustfile.py index 21e78aa840..f117acd779 100644 --- a/examples/custom_xmlrpc_client/xmlrpc_locustfile.py +++ b/examples/custom_xmlrpc_client/xmlrpc_locustfile.py @@ -1,7 +1,7 @@ import time import xmlrpclib -from locust import Locust, events, task, TaskSet +from locust import Locust, TaskSet, events, task class XmlRpcClient(xmlrpclib.ServerProxy): diff --git a/examples/events.py b/examples/events.py index afcecd193b..7b1de7fafe 100644 --- a/examples/events.py +++ b/examples/events.py @@ -5,7 +5,8 @@ track the sum of the content-length header in all successful HTTP responses """ -from locust import HttpLocust, TaskSet, task, events, web +from locust import HttpLocust, TaskSet, events, task, web + class MyTaskSet(TaskSet): @task(2) diff --git a/locust/cache.py b/locust/cache.py index 3b5a4d3419..4852b1d8bc 100644 --- a/locust/cache.py +++ b/locust/cache.py @@ -1,5 +1,6 @@ from time import time + def memoize(timeout, dynamic_timeout=False): """ Memoization decorator with support for timeout. @@ -28,4 +29,3 @@ def clear_cache(): wrapper.clear_cache = clear_cache return wrapper return decorator - diff --git a/locust/clients.py b/locust/clients.py index 1ef13a5f60..13216f54d1 100644 --- a/locust/clients.py +++ b/locust/clients.py @@ -1,13 +1,14 @@ import re import time -from six.moves.urllib.parse import urlparse, urlunparse -import six import requests -from requests import Response, Request +import six +from requests import Request, Response from requests.auth import HTTPBasicAuth -from requests.exceptions import (RequestException, MissingSchema, - InvalidSchema, InvalidURL) +from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema, + RequestException) + +from six.moves.urllib.parse import urlparse, urlunparse from . import events from .exception import CatchResponseError, ResponseError diff --git a/locust/core.py b/locust/core.py index 7f0a117bf6..0bf6b55828 100644 --- a/locust/core.py +++ b/locust/core.py @@ -1,21 +1,21 @@ +import logging +import random +import sys +import traceback +from time import time + import gevent -from gevent import monkey, GreenletExit import six -from six.moves import xrange +from gevent import GreenletExit, monkey -monkey.patch_all(thread=False) - -from time import time -import sys -import random -import traceback -import logging +from six.moves import xrange -from .clients import HttpSession from . import events +from .clients import HttpSession +from .exception import (InterruptTaskSet, LocustError, RescheduleTask, + RescheduleTaskImmediately, StopLocust) -from .exception import LocustError, InterruptTaskSet, RescheduleTask, RescheduleTaskImmediately, StopLocust - +monkey.patch_all(thread=False) logger = logging.getLogger(__name__) @@ -352,4 +352,3 @@ def client(self): Locust instance. """ return self.locust.client - diff --git a/locust/inspectlocust.py b/locust/inspectlocust.py index 15555341e8..51ab1e9184 100644 --- a/locust/inspectlocust.py +++ b/locust/inspectlocust.py @@ -1,9 +1,11 @@ import inspect + import six from .core import Locust, TaskSet from .log import console_logger + def print_task_ratio(locusts, total=False, level=0, parent_ratio=1.0): d = get_task_ratio_dict(locusts, total=total, parent_ratio=parent_ratio) _print_task_ratio(d) diff --git a/locust/log.py b/locust/log.py index 24ffffbef6..5c824f5c18 100644 --- a/locust/log.py +++ b/locust/log.py @@ -1,6 +1,6 @@ import logging -import sys import socket +import sys host = socket.gethostname() diff --git a/locust/main.py b/locust/main.py index ba80bfe863..7bf145b354 100644 --- a/locust/main.py +++ b/locust/main.py @@ -1,23 +1,23 @@ -import locust -from . import runners - -import gevent -import sys -import os -import signal import inspect import logging +import os +import signal import socket +import sys import time from optparse import OptionParser -from . import web -from .log import setup_logging, console_logger -from .stats import stats_printer, print_percentile_stats, print_error_report, print_stats, stats_writer, write_stat_csvs -from .inspectlocust import print_task_ratio, get_task_ratio_dict -from .core import Locust, HttpLocust -from .runners import MasterLocustRunner, SlaveLocustRunner, LocalLocustRunner -from . import events +import gevent + +import locust + +from . import events, runners, web +from .core import HttpLocust, Locust +from .inspectlocust import get_task_ratio_dict, print_task_ratio +from .log import console_logger, setup_logging +from .runners import LocalLocustRunner, MasterLocustRunner, SlaveLocustRunner +from .stats import (print_error_report, print_percentile_stats, print_stats, + stats_printer, stats_writer, write_stat_csvs) _internals = [Locust, HttpLocust] version = locust.__version__ diff --git a/locust/rpc/protocol.py b/locust/rpc/protocol.py index 66ce2c72cf..b30a36f8bc 100644 --- a/locust/rpc/protocol.py +++ b/locust/rpc/protocol.py @@ -1,5 +1,6 @@ import msgpack + class Message(object): def __init__(self, message_type, data, node_id): self.type = message_type diff --git a/locust/rpc/socketrpc.py b/locust/rpc/socketrpc.py index 034efe6ff7..89c5b05ae1 100644 --- a/locust/rpc/socketrpc.py +++ b/locust/rpc/socketrpc.py @@ -1,10 +1,11 @@ -import struct import logging +import struct import gevent from gevent import socket from locust.exception import LocustError + from .protocol import Message logger = logging.getLogger(__name__) diff --git a/locust/rpc/zmqrpc.py b/locust/rpc/zmqrpc.py index 44a3bff13b..07583cb0a7 100644 --- a/locust/rpc/zmqrpc.py +++ b/locust/rpc/zmqrpc.py @@ -1,6 +1,8 @@ import zmq.green as zmq + from .protocol import Message + class BaseSocket(object): def send(self, msg): diff --git a/locust/runners.py b/locust/runners.py index 185bdec109..8600121ff2 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -1,23 +1,23 @@ # -*- coding: utf-8 -*- +import logging +import random import socket import traceback import warnings -import random -import logging -from time import time from hashlib import md5 +from time import time import gevent +import six from gevent import GreenletExit from gevent.pool import Group -import six + from six.moves import xrange from . import events +from .rpc import Message, rpc from .stats import global_stats -from .rpc import rpc, Message - logger = logging.getLogger(__name__) # global locust runner singleton diff --git a/locust/stats.py b/locust/stats.py index fd0cb284fa..568b659189 100644 --- a/locust/stats.py +++ b/locust/stats.py @@ -1,9 +1,11 @@ +import hashlib import time +from itertools import chain + import gevent -import hashlib import six + from six.moves import xrange -from itertools import chain from . import events from .exception import StopLocust diff --git a/locust/test/test_client.py b/locust/test/test_client.py index d76630bcf4..197274aa74 100644 --- a/locust/test/test_client.py +++ b/locust/test/test_client.py @@ -1,10 +1,12 @@ -from requests.exceptions import (RequestException, MissingSchema, - InvalidSchema, InvalidURL) +from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema, + RequestException) from locust.clients import HttpSession from locust.stats import global_stats + from .testcases import WebserverTestCase + class TestHttpSession(WebserverTestCase): def test_get(self): s = HttpSession("http://127.0.0.1:%i" % self.port) @@ -66,4 +68,3 @@ def test_post_redirect(self): get_stats = global_stats.get(url, method="GET") self.assertEqual(1, post_stats.num_requests) self.assertEqual(0, get_stats.num_requests) - diff --git a/locust/test/test_locust_class.py b/locust/test/test_locust_class.py index f2da60a275..e1198f3f93 100644 --- a/locust/test/test_locust_class.py +++ b/locust/test/test_locust_class.py @@ -1,11 +1,13 @@ import six -from locust.core import HttpLocust, Locust, TaskSet, task, events -from locust import ResponseError, InterruptTaskSet -from locust.exception import CatchResponseError, RescheduleTask, RescheduleTaskImmediately, LocustError +from locust import InterruptTaskSet, ResponseError +from locust.core import HttpLocust, Locust, TaskSet, events, task +from locust.exception import (CatchResponseError, LocustError, RescheduleTask, + RescheduleTaskImmediately) from .testcases import LocustTestCase, WebserverTestCase + class TestTaskSet(LocustTestCase): def setUp(self): super(TestTaskSet, self).setUp() diff --git a/locust/test/test_main.py b/locust/test/test_main.py index 902ecde8ff..6686c5d281 100644 --- a/locust/test/test_main.py +++ b/locust/test/test_main.py @@ -1,7 +1,9 @@ -from locust.core import HttpLocust, Locust, TaskSet from locust import main +from locust.core import HttpLocust, Locust, TaskSet + from .testcases import LocustTestCase + class TestTaskSet(LocustTestCase): def test_is_locust(self): self.assertFalse(main.is_locust(("Locust", Locust))) diff --git a/locust/test/test_runners.py b/locust/test/test_runners.py index 31bbeae697..b785410222 100644 --- a/locust/test/test_runners.py +++ b/locust/test/test_runners.py @@ -1,19 +1,18 @@ import unittest import gevent -import mock - -from gevent.queue import Queue from gevent import sleep +from gevent.queue import Queue -from locust.runners import LocalLocustRunner, MasterLocustRunner -from locust.core import Locust, task, TaskSet +import mock +from locust import events +from locust.core import Locust, TaskSet, task from locust.exception import LocustError +from locust.main import parse_options from locust.rpc import Message +from locust.runners import LocalLocustRunner, MasterLocustRunner from locust.stats import global_stats -from locust.main import parse_options from locust.test.testcases import LocustTestCase -from locust import events def mocked_rpc_server(): @@ -246,4 +245,3 @@ def test_message_serialize(self): self.assertEqual(msg.type, rebuilt.type) self.assertEqual(msg.data, rebuilt.data) self.assertEqual(msg.node_id, rebuilt.node_id) - diff --git a/locust/test/test_stats.py b/locust/test/test_stats.py index 41784f2fed..6d4d646f97 100644 --- a/locust/test/test_stats.py +++ b/locust/test/test_stats.py @@ -1,13 +1,14 @@ -import unittest import time +import unittest -from six.moves import xrange - -from .testcases import WebserverTestCase -from locust.stats import RequestStats, StatsEntry, global_stats from locust.core import HttpLocust, TaskSet, task from locust.inspectlocust import get_task_ratio_dict from locust.rpc.protocol import Message +from locust.stats import RequestStats, StatsEntry, global_stats +from six.moves import xrange + +from .testcases import WebserverTestCase + class TestRequestStats(unittest.TestCase): def setUp(self): diff --git a/locust/test/test_taskratio.py b/locust/test/test_taskratio.py index 5081fbf5f8..0a2ed81de2 100644 --- a/locust/test/test_taskratio.py +++ b/locust/test/test_taskratio.py @@ -3,6 +3,7 @@ from locust.core import Locust, TaskSet, task from locust.inspectlocust import get_task_ratio_dict + class TestTaskRatio(unittest.TestCase): def test_task_ratio_command(self): class Tasks(TaskSet): diff --git a/locust/test/test_web.py b/locust/test/test_web.py index 286a7362b1..a070fc4e35 100644 --- a/locust/test/test_web.py +++ b/locust/test/test_web.py @@ -1,20 +1,21 @@ # -*- coding: utf-8 -*- - import csv import json import sys import traceback -from six.moves import StringIO -import requests import gevent +import requests from gevent import wsgi -from locust import web, runners, stats -from locust.runners import LocustRunner +from locust import runners, stats, web from locust.main import parse_options +from locust.runners import LocustRunner +from six.moves import StringIO + from .testcases import LocustTestCase + class TestWebUI(LocustTestCase): def setUp(self): super(TestWebUI, self).setUp() @@ -119,4 +120,3 @@ def test_exceptions_csv(self): self.assertEqual(2, len(rows)) self.assertEqual("Test exception", rows[1][1]) self.assertEqual(2, int(rows[1][0]), "Exception count should be 2") - diff --git a/locust/test/testcases.py b/locust/test/testcases.py index 0b9b261123..7107e3c36b 100644 --- a/locust/test/testcases.py +++ b/locust/test/testcases.py @@ -1,16 +1,18 @@ import base64 -import gevent -import gevent.pywsgi import random +import sys import unittest from copy import copy from io import BytesIO -import sys + +import gevent +import gevent.pywsgi import six +from flask import (Flask, Response, make_response, redirect, request, + send_file, stream_with_context) from locust import events from locust.stats import global_stats -from flask import Flask, request, redirect, make_response, send_file, Response, stream_with_context def safe_repr(obj, short=False): diff --git a/locust/web.py b/locust/web.py index dda162a92d..57cfa5a022 100644 --- a/locust/web.py +++ b/locust/web.py @@ -2,23 +2,24 @@ import csv import json +import logging import os.path -from time import time -from itertools import chain from collections import defaultdict -from six.moves import StringIO, xrange -import six +from itertools import chain +from time import time +import six +from flask import Flask, make_response, render_template, request from gevent import wsgi -from flask import Flask, make_response, request, render_template + +from locust import __version__ as version +from six.moves import StringIO, xrange from . import runners from .cache import memoize from .runners import MasterLocustRunner -from .stats import sort_stats, median_from_dict, requests_csv, distribution_csv -from locust import __version__ as version +from .stats import distribution_csv, median_from_dict, requests_csv, sort_stats -import logging logger = logging.getLogger(__name__) DEFAULT_CACHE_TIME = 2.0 @@ -176,4 +177,3 @@ def exceptions_csv(): def start(locust, options): wsgi.WSGIServer((options.web_host, options.port), app, log=None).serve_forever() - diff --git a/setup.py b/setup.py index bc5c896b66..04d6c293d6 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- +import ast +import os +import re -from setuptools import setup, find_packages -import os, re, ast - +from setuptools import find_packages, setup # parse version from locust/__init__.py _version_re = re.compile(r'__version__\s+=\s+(.*)')