Skip to content

Commit

Permalink
Merge pull request #651 from mbeacom/sort-imports
Browse files Browse the repository at this point in the history
Sort all Python imports
  • Loading branch information
Mark Beacom authored Sep 8, 2017
2 parents e04b348 + 8f94de5 commit a4c377e
Show file tree
Hide file tree
Showing 26 changed files with 113 additions and 93 deletions.
11 changes: 6 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------

Expand Down Expand Up @@ -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__
Expand Down
1 change: 1 addition & 0 deletions examples/basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from locust import HttpLocust, TaskSet, task


def index(l):
l.client.get("/")

Expand Down
3 changes: 2 additions & 1 deletion examples/custom_xmlrpc_client/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import time
import random
import time
from SimpleXMLRPCServer import SimpleXMLRPCServer


def get_time():
time.sleep(random.random())
return time.time()
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_xmlrpc_client/xmlrpc_locustfile.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
3 changes: 2 additions & 1 deletion examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion locust/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from time import time


def memoize(timeout, dynamic_timeout=False):
"""
Memoization decorator with support for timeout.
Expand Down Expand Up @@ -28,4 +29,3 @@ def clear_cache():
wrapper.clear_cache = clear_cache
return wrapper
return decorator

11 changes: 6 additions & 5 deletions locust/clients.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 12 additions & 13 deletions locust/core.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand Down Expand Up @@ -352,4 +352,3 @@ def client(self):
Locust instance.
"""
return self.locust.client

2 changes: 2 additions & 0 deletions locust/inspectlocust.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion locust/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import sys
import socket
import sys

host = socket.gethostname()

Expand Down
28 changes: 14 additions & 14 deletions locust/main.py
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
1 change: 1 addition & 0 deletions locust/rpc/protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import msgpack


class Message(object):
def __init__(self, message_type, data, node_id):
self.type = message_type
Expand Down
3 changes: 2 additions & 1 deletion locust/rpc/socketrpc.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down
2 changes: 2 additions & 0 deletions locust/rpc/zmqrpc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import zmq.green as zmq

from .protocol import Message


class BaseSocket(object):

def send(self, msg):
Expand Down
12 changes: 6 additions & 6 deletions locust/runners.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions locust/stats.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 4 additions & 3 deletions locust/test/test_client.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)

8 changes: 5 additions & 3 deletions locust/test/test_locust_class.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 3 additions & 1 deletion locust/test/test_main.py
Original file line number Diff line number Diff line change
@@ -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)))
Expand Down
14 changes: 6 additions & 8 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down Expand Up @@ -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)

11 changes: 6 additions & 5 deletions locust/test/test_stats.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 1 addition & 0 deletions locust/test/test_taskratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading

0 comments on commit a4c377e

Please sign in to comment.