Skip to content

Commit

Permalink
Merge pull request #1559 from locustio/remove-legacy-code-that-was-on…
Browse files Browse the repository at this point in the history
…ly-needed-for-py2

Remove legacy code that was only needed for py2
  • Loading branch information
cyberw authored Sep 13, 2020
2 parents f2c7874 + cb2ed04 commit 532f33a
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/custom_xmlrpc_client/xmlrpc_locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class XmlRpcUser(User):
abstract = True

def __init__(self, *args, **kwargs):
super(XmlRpcUser, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.client = XmlRpcClient(self.host)
self.client._locust_environment = self.environment

Expand Down
2 changes: 1 addition & 1 deletion examples/multiple_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MultipleHostsUser(HttpUser):
abstract = True

def __init__(self, *args, **kwargs):
super(MultipleHostsUser, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.api_client = HttpSession(base_url=os.environ["API_HOST"])


Expand Down
2 changes: 1 addition & 1 deletion locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HttpSession(requests.Session):
"""

def __init__(self, base_url, request_success, request_failure, *args, **kwargs):
super(HttpSession, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

self.base_url = base_url
self.request_success = request_success
Expand Down
6 changes: 2 additions & 4 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re
import socket
import json
Expand Down Expand Up @@ -372,7 +370,7 @@ def status_code(self) -> int:
def _content(self):
if self.headers is None:
return None
return super(FastResponse, self)._content()
return super()._content()


class ErrorResponse(object):
Expand All @@ -396,7 +394,7 @@ class LocustUserAgent(UserAgent):
valid_response_codes = frozenset([200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 301, 302, 303, 307])

def __init__(self, **kwargs):
super(LocustUserAgent, self).__init__(**kwargs)
super().__init__(**kwargs)

def _urlopen(self, request):
"""Override _urlopen() in order to make it use the response_type attribute"""
Expand Down
2 changes: 1 addition & 1 deletion locust/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Events:
: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])
:param tb: Traceback object (from e.__traceback__)
"""

report_to_master = EventHook
Expand Down
2 changes: 1 addition & 1 deletion locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def __init__(self, environment):
"""
:param environment: Environment instance
"""
super(LocalRunner, self).__init__(environment)
super().__init__(environment)

# register listener thats logs the exception for the local runner
def on_user_error(user_instance, exception, tb):
Expand Down
2 changes: 1 addition & 1 deletion locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class MyUnauthorizedUser(FastHttpUser):

class TestFastHttpCatchResponse(WebserverTestCase):
def setUp(self):
super(TestFastHttpCatchResponse, self).setUp()
super().setUp()

class MyUser(FastHttpUser):
host = "http://127.0.0.1:%i" % self.port
Expand Down
4 changes: 2 additions & 2 deletions locust/test/test_locust_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class TestTaskSet(LocustTestCase):
def setUp(self):
super(TestTaskSet, self).setUp()
super().setUp()

class MyUser(User):
host = "127.0.0.1"
Expand Down Expand Up @@ -728,7 +728,7 @@ class MyUser(HttpUser):

class TestCatchResponse(WebserverTestCase):
def setUp(self):
super(TestCatchResponse, self).setUp()
super().setUp()

class MyUser(HttpUser):
host = "http://127.0.0.1:%i" % self.port
Expand Down
10 changes: 5 additions & 5 deletions locust/test/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,11 @@ def tick(self):

class TestMasterRunner(LocustTestCase):
def setUp(self):
super(TestMasterRunner, self).setUp()
super().setUp()
self.environment = Environment(events=locust.events, catch_exceptions=False)

def tearDown(self):
super(TestMasterRunner, self).tearDown()
super().tearDown()

def get_runner(self):
return self.environment.create_master_runner("*", 5557)
Expand Down Expand Up @@ -1189,7 +1189,7 @@ def test_exception_is_caught(self):

class MyTaskSet(TaskSet):
def __init__(self, *a, **kw):
super(MyTaskSet, self).__init__(*a, **kw)
super().__init__(*a, **kw)
self._task_queue = [self.will_error, self.will_stop]

@task(1)
Expand Down Expand Up @@ -1240,12 +1240,12 @@ def test_master_reset_connection(self):

class TestWorkerRunner(LocustTestCase):
def setUp(self):
super(TestWorkerRunner, self).setUp()
super().setUp()
# self._report_to_master_event_handlers = [h for h in events.report_to_master._handlers]

def tearDown(self):
# events.report_to_master._handlers = self._report_to_master_event_handlers
super(TestWorkerRunner, self).tearDown()
super().tearDown()

def get_runner(self, environment=None, user_classes=[]):
if environment is None:
Expand Down
2 changes: 1 addition & 1 deletion locust/test/test_sequential_taskset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TestTaskSet(LocustTestCase):
def setUp(self):
super(TestTaskSet, self).setUp()
super().setUp()

class MyUser(User):
host = "127.0.0.1"
Expand Down
4 changes: 2 additions & 2 deletions locust/test/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_stats_history(self):

class TestStatsEntryResponseTimesCache(unittest.TestCase):
def setUp(self, *args, **kwargs):
super(TestStatsEntryResponseTimesCache, self).setUp(*args, **kwargs)
super().setUp(*args, **kwargs)
self.stats = RequestStats()

def test_response_times_cached(self):
Expand Down Expand Up @@ -617,7 +617,7 @@ def parse_string_output(self, text):
return tokens

def setUp(self, *args, **kwargs):
super(TestStatsEntry, self).setUp(*args, **kwargs)
super().setUp(*args, **kwargs)
self.stats = RequestStats()

def test_fail_ratio_with_no_failures(self):
Expand Down
24 changes: 12 additions & 12 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _check_csv_headers(self, headers, exp_fn_prefix):

class TestWebUI(LocustTestCase, _HeaderCheckMixin):
def setUp(self):
super(TestWebUI, self).setUp()
super().setUp()

parser = get_parser(default_config_files=[])
self.environment.parsed_options = parser.parse_args([])
Expand All @@ -54,7 +54,7 @@ def setUp(self):
self.web_port = self.web_ui.server.server_port

def tearDown(self):
super(TestWebUI, self).tearDown()
super().tearDown()
self.web_ui.stop()
self.runner.quit()

Expand Down Expand Up @@ -175,7 +175,7 @@ def test_reset_stats(self):
try:
raise Exception("A cool test exception")
except Exception as e:
tb = sys.exc_info()[2]
tb = e.__traceback__
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))

Expand All @@ -198,7 +198,7 @@ def test_exceptions(self):
try:
raise Exception("A cool test exception")
except Exception as e:
tb = sys.exc_info()[2]
tb = e.__traceback__
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))

Expand All @@ -213,7 +213,7 @@ def test_exceptions_csv(self):
try:
raise Exception("Test exception")
except Exception as e:
tb = sys.exc_info()[2]
tb = e.__traceback__
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))

Expand Down Expand Up @@ -356,7 +356,7 @@ def test_report_exceptions(self):
try:
raise Exception("Test exception")
except Exception as e:
tb = sys.exc_info()[2]
tb = e.__traceback__
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))
self.runner.log_exception("local", str(e), "".join(traceback.format_tb(tb)))
self.stats.log_request("GET", "/test", 120, 5612)
Expand All @@ -367,7 +367,7 @@ def test_report_exceptions(self):

class TestWebUIAuth(LocustTestCase):
def setUp(self):
super(TestWebUIAuth, self).setUp()
super().setUp()

parser = get_parser(default_config_files=[])
options = parser.parse_args(["--web-auth", "john:doe"])
Expand All @@ -379,7 +379,7 @@ def setUp(self):
self.web_port = self.web_ui.server.server_port

def tearDown(self):
super(TestWebUIAuth, self).tearDown()
super().tearDown()
self.web_ui.stop()
self.runner.quit()

Expand All @@ -399,7 +399,7 @@ def test_index_with_basic_auth_enabled_blank_credentials(self):

class TestWebUIWithTLS(LocustTestCase):
def setUp(self):
super(TestWebUIWithTLS, self).setUp()
super().setUp()
tls_cert, tls_key = create_tls_cert("127.0.0.1")
self.tls_cert_file = NamedTemporaryFile(delete=False)
self.tls_key_file = NamedTemporaryFile(delete=False)
Expand All @@ -424,7 +424,7 @@ def setUp(self):
self.web_port = self.web_ui.server.server_port

def tearDown(self):
super(TestWebUIWithTLS, self).tearDown()
super().tearDown()
self.web_ui.stop()
self.runner.quit()
os.unlink(self.tls_cert_file.name)
Expand All @@ -445,7 +445,7 @@ class TestWebUIFullHistory(LocustTestCase, _HeaderCheckMixin):
STATS_FAILURES_FILENAME = "{}_failures.csv".format(STATS_BASE_NAME)

def setUp(self):
super(TestWebUIFullHistory, self).setUp()
super().setUp()
self.remove_files_if_exists()

parser = get_parser(default_config_files=[])
Expand All @@ -463,7 +463,7 @@ def setUp(self):
self.web_port = self.web_ui.server.server_port

def tearDown(self):
super(TestWebUIFullHistory, self).tearDown()
super().tearDown()
self.web_ui.stop()
self.runner.quit()
self.remove_files_if_exists()
Expand Down
4 changes: 2 additions & 2 deletions locust/test/test_zmqrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

class ZMQRPC_tests(LocustTestCase):
def setUp(self):
super(ZMQRPC_tests, self).setUp()
super().setUp()
self.server = zmqrpc.Server("127.0.0.1", 0)
self.client = zmqrpc.Client("localhost", self.server.port, "identity")

def tearDown(self):
self.server.close()
self.client.close()
super(ZMQRPC_tests, self).tearDown()
super().tearDown()

def test_constructor(self):
self.assertEqual(self.server.socket.getsockopt(zmq.TCP_KEEPALIVE), 1)
Expand Down
4 changes: 2 additions & 2 deletions locust/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ class WebserverTestCase(LocustTestCase):
"""

def setUp(self):
super(WebserverTestCase, self).setUp()
super().setUp()
self._web_server = gevent.pywsgi.WSGIServer(("127.0.0.1", 0), app, log=None)
gevent.spawn(lambda: self._web_server.serve_forever())
gevent.sleep(0.01)
self.port = self._web_server.server_port

def tearDown(self):
super(WebserverTestCase, self).tearDown()
super().tearDown()
self._web_server.stop_accepting()
self._web_server.stop()
6 changes: 3 additions & 3 deletions locust/user/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def run(self):
self.on_start()
except InterruptTaskSet as e:
if e.reschedule:
raise RescheduleTaskImmediately(e.reschedule).with_traceback(sys.exc_info()[2])
raise RescheduleTaskImmediately(e.reschedule).with_traceback(e.__traceback__)
else:
raise RescheduleTask(e.reschedule).with_traceback(sys.exc_info()[2])
raise RescheduleTask(e.reschedule).with_traceback(e.__traceback__)

while True:
try:
Expand All @@ -298,7 +298,7 @@ def run(self):
self.on_stop()
raise
except Exception as e:
self.user.environment.events.user_error.fire(user_instance=self, exception=e, tb=sys.exc_info()[2])
self.user.environment.events.user_error.fire(user_instance=self, exception=e, tb=e.__traceback__)
if self.user.environment.catch_exceptions:
logger.error("%s\n%s", e, traceback.format_exc())
self.wait()
Expand Down
4 changes: 2 additions & 2 deletions locust/user/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ForumPage(TaskSet):
_taskset_instance = None

def __init__(self, environment):
super(User, self).__init__()
super().__init__()
self.environment = environment

def on_start(self):
Expand Down Expand Up @@ -219,7 +219,7 @@ class by using the :py:func:`@task decorator <locust.task>` on methods, or by se
"""

def __init__(self, *args, **kwargs):
super(HttpUser, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
if self.host is None:
raise LocustError(
"You must specify the base host. Either in the host attribute in the User class, or on the command line using the --host option."
Expand Down

0 comments on commit 532f33a

Please sign in to comment.