diff options
| author | chillaranand <anand21nanda@gmail.com> | 2017-01-21 18:43:44 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-01-25 12:23:46 -0500 |
| commit | d6eaf7c0183cd04b78f2a55e1d60bb7e59598310 (patch) | |
| tree | ab02fd9949d4bfa23e27dea45e213ce334c883f0 /django/test | |
| parent | dc165ec8e5698ffc6dee6b510f1f92c9fd7467fe (diff) | |
Refs #23919 -- Replaced super(ClassName, self) with super().
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/client.py | 34 | ||||
| -rw-r--r-- | django/test/html.py | 2 | ||||
| -rw-r--r-- | django/test/runner.py | 12 | ||||
| -rw-r--r-- | django/test/selenium.py | 6 | ||||
| -rw-r--r-- | django/test/testcases.py | 40 | ||||
| -rw-r--r-- | django/test/utils.py | 14 |
6 files changed, 48 insertions, 60 deletions
diff --git a/django/test/client.py b/django/test/client.py index e793dac775..bdd045c82c 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -40,7 +40,7 @@ class RedirectCycleError(Exception): The test client has been asked to follow a redirect loop. """ def __init__(self, message, last_response): - super(RedirectCycleError, self).__init__(message) + super().__init__(message) self.last_response = last_response self.redirect_chain = last_response.redirect_chain @@ -119,7 +119,7 @@ class ClientHandler(BaseHandler): """ def __init__(self, enforce_csrf_checks=True, *args, **kwargs): self.enforce_csrf_checks = enforce_csrf_checks - super(ClientHandler, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def __call__(self, environ): # Set up middleware if needed. We couldn't do this earlier, because @@ -430,7 +430,7 @@ class Client(RequestFactory): HTML rendered to the end-user. """ def __init__(self, enforce_csrf_checks=False, **defaults): - super(Client, self).__init__(**defaults) + super().__init__(**defaults) self.handler = ClientHandler(enforce_csrf_checks) self.exc_info = None @@ -527,8 +527,7 @@ class Client(RequestFactory): """ Requests a response from the server using GET. """ - response = super(Client, self).get(path, data=data, secure=secure, - **extra) + response = super().get(path, data=data, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -538,9 +537,7 @@ class Client(RequestFactory): """ Requests a response from the server using POST. """ - response = super(Client, self).post(path, data=data, - content_type=content_type, - secure=secure, **extra) + response = super().post(path, data=data, content_type=content_type, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -549,8 +546,7 @@ class Client(RequestFactory): """ Request a response from the server using HEAD. """ - response = super(Client, self).head(path, data=data, secure=secure, - **extra) + response = super().head(path, data=data, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -560,9 +556,7 @@ class Client(RequestFactory): """ Request a response from the server using OPTIONS. """ - response = super(Client, self).options(path, data=data, - content_type=content_type, - secure=secure, **extra) + response = super().options(path, data=data, content_type=content_type, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -572,9 +566,7 @@ class Client(RequestFactory): """ Send a resource to the server using PUT. """ - response = super(Client, self).put(path, data=data, - content_type=content_type, - secure=secure, **extra) + response = super().put(path, data=data, content_type=content_type, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -584,9 +576,7 @@ class Client(RequestFactory): """ Send a resource to the server using PATCH. """ - response = super(Client, self).patch(path, data=data, - content_type=content_type, - secure=secure, **extra) + response = super().patch(path, data=data, content_type=content_type, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -596,9 +586,7 @@ class Client(RequestFactory): """ Send a DELETE request to the server. """ - response = super(Client, self).delete(path, data=data, - content_type=content_type, - secure=secure, **extra) + response = super().delete(path, data=data, content_type=content_type, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response @@ -607,7 +595,7 @@ class Client(RequestFactory): """ Send a TRACE request to the server. """ - response = super(Client, self).trace(path, data=data, secure=secure, **extra) + response = super().trace(path, data=data, secure=secure, **extra) if follow: response = self._handle_redirects(response, **extra) return response diff --git a/django/test/html.py b/django/test/html.py index 319fd87a0f..900aa3d3f0 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -134,7 +134,7 @@ class Element: class RootElement(Element): def __init__(self): - super(RootElement, self).__init__(None, ()) + super().__init__(None, ()) def __str__(self): return ''.join(str(c) for c in self.children) diff --git a/django/test/runner.py b/django/test/runner.py index a0648b2f97..38578e7e0c 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -30,16 +30,16 @@ class DebugSQLTextTestResult(unittest.TextTestResult): def __init__(self, stream, descriptions, verbosity): self.logger = logging.getLogger('django.db.backends') self.logger.setLevel(logging.DEBUG) - super(DebugSQLTextTestResult, self).__init__(stream, descriptions, verbosity) + super().__init__(stream, descriptions, verbosity) def startTest(self, test): self.debug_sql_stream = StringIO() self.handler = logging.StreamHandler(self.debug_sql_stream) self.logger.addHandler(self.handler) - super(DebugSQLTextTestResult, self).startTest(test) + super().startTest(test) def stopTest(self, test): - super(DebugSQLTextTestResult, self).stopTest(test) + super().stopTest(test) self.logger.removeHandler(self.handler) if self.showAll: self.debug_sql_stream.seek(0) @@ -47,12 +47,12 @@ class DebugSQLTextTestResult(unittest.TextTestResult): self.stream.writeln(self.separator2) def addError(self, test, err): - super(DebugSQLTextTestResult, self).addError(test, err) + super().addError(test, err) self.debug_sql_stream.seek(0) self.errors[-1] = self.errors[-1] + (self.debug_sql_stream.read(),) def addFailure(self, test, err): - super(DebugSQLTextTestResult, self).addFailure(test, err) + super().addFailure(test, err) self.debug_sql_stream.seek(0) self.failures[-1] = self.failures[-1] + (self.debug_sql_stream.read(),) @@ -333,7 +333,7 @@ class ParallelTestSuite(unittest.TestSuite): self.subsuites = partition_suite_by_case(suite) self.processes = processes self.failfast = failfast - super(ParallelTestSuite, self).__init__() + super().__init__() def run(self, result): """ diff --git a/django/test/selenium.py b/django/test/selenium.py index e1415339dd..2b14678b23 100644 --- a/django/test/selenium.py +++ b/django/test/selenium.py @@ -18,7 +18,7 @@ class SeleniumTestCaseBase(type(LiveServerTestCase)): Dynamically create new classes and add them to the test module when multiple browsers specs are provided (e.g. --selenium=firefox,chrome). """ - test_class = super(SeleniumTestCaseBase, cls).__new__(cls, name, bases, attrs) + test_class = super().__new__(cls, name, bases, attrs) # If the test class is either browser-specific or a test base, return it. if test_class.browser or not any(name.startswith('test') and callable(value) for name, value in attrs.items()): return test_class @@ -60,7 +60,7 @@ class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase): def setUpClass(cls): cls.selenium = cls.create_webdriver() cls.selenium.implicitly_wait(cls.implicit_wait) - super(SeleniumTestCase, cls).setUpClass() + super().setUpClass() @classmethod def _tearDownClassInternal(cls): @@ -69,7 +69,7 @@ class SeleniumTestCase(LiveServerTestCase, metaclass=SeleniumTestCaseBase): # kept a connection alive. if hasattr(cls, 'selenium'): cls.selenium.quit() - super(SeleniumTestCase, cls)._tearDownClassInternal() + super()._tearDownClassInternal() @contextmanager def disable_implicit_wait(self): diff --git a/django/test/testcases.py b/django/test/testcases.py index 02398433d9..4c1d778795 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -66,10 +66,10 @@ class _AssertNumQueriesContext(CaptureQueriesContext): def __init__(self, test_case, num, connection): self.test_case = test_case self.num = num - super(_AssertNumQueriesContext, self).__init__(connection) + super().__init__(connection) def __exit__(self, exc_type, exc_value, traceback): - super(_AssertNumQueriesContext, self).__exit__(exc_type, exc_value, traceback) + super().__exit__(exc_type, exc_value, traceback) if exc_type is not None: return executed = len(self) @@ -157,7 +157,7 @@ class SimpleTestCase(unittest.TestCase): @classmethod def setUpClass(cls): - super(SimpleTestCase, cls).setUpClass() + super().setUpClass() if cls._overridden_settings: cls._cls_overridden_context = override_settings(**cls._overridden_settings) cls._cls_overridden_context.enable() @@ -183,7 +183,7 @@ class SimpleTestCase(unittest.TestCase): if hasattr(cls, '_cls_overridden_context'): cls._cls_overridden_context.disable() delattr(cls, '_cls_overridden_context') - super(SimpleTestCase, cls).tearDownClass() + super().tearDownClass() def __call__(self, result=None): """ @@ -203,7 +203,7 @@ class SimpleTestCase(unittest.TestCase): except Exception: result.addError(self, sys.exc_info()) return - super(SimpleTestCase, self).__call__(result) + super().__call__(result) if not skipped: try: self._post_teardown() @@ -799,7 +799,7 @@ class TransactionTestCase(SimpleTestCase): run with the correct set of applications for the test case. * If the class has a 'fixtures' attribute, installing these fixtures. """ - super(TransactionTestCase, self)._pre_setup() + super()._pre_setup() if self.available_apps is not None: apps.set_available_apps(self.available_apps) setting_changed.send( @@ -881,7 +881,7 @@ class TransactionTestCase(SimpleTestCase): """ try: self._fixture_teardown() - super(TransactionTestCase, self)._post_teardown() + super()._post_teardown() if self._should_reload_connections(): # Some DB cursors include SQL statements as part of cursor # creation. If you have a test that does a rollback, the effect @@ -980,7 +980,7 @@ class TestCase(TransactionTestCase): @classmethod def setUpClass(cls): - super(TestCase, cls).setUpClass() + super().setUpClass() if not connections_support_transactions(): return cls.cls_atomics = cls._enter_atomics() @@ -1008,7 +1008,7 @@ class TestCase(TransactionTestCase): cls._rollback_atomics(cls.cls_atomics) for conn in connections.all(): conn.close() - super(TestCase, cls).tearDownClass() + super().tearDownClass() @classmethod def setUpTestData(cls): @@ -1018,21 +1018,21 @@ class TestCase(TransactionTestCase): def _should_reload_connections(self): if connections_support_transactions(): return False - return super(TestCase, self)._should_reload_connections() + return super()._should_reload_connections() def _fixture_setup(self): if not connections_support_transactions(): # If the backend does not support transactions, we should reload # class data before each test self.setUpTestData() - return super(TestCase, self)._fixture_setup() + return super()._fixture_setup() assert not self.reset_sequences, 'reset_sequences cannot be used on TestCase instances' self.atomics = self._enter_atomics() def _fixture_teardown(self): if not connections_support_transactions(): - return super(TestCase, self)._fixture_teardown() + return super()._fixture_teardown() try: for db_name in reversed(self._databases_names()): if self._should_check_constraints(connections[db_name]): @@ -1141,7 +1141,7 @@ class FSFilesHandler(WSGIHandler): def __init__(self, application): self.application = application self.base_url = urlparse(self.get_base_url()) - super(FSFilesHandler, self).__init__() + super().__init__() def _should_handle(self, path): """ @@ -1167,7 +1167,7 @@ class FSFilesHandler(WSGIHandler): return self.serve(request) except Http404: pass - return super(FSFilesHandler, self).get_response(request) + return super().get_response(request) def serve(self, request): os_rel_path = self.file_path(request.path) @@ -1181,7 +1181,7 @@ class FSFilesHandler(WSGIHandler): def __call__(self, environ, start_response): if not self._should_handle(get_path_info(environ)): return self.application(environ, start_response) - return super(FSFilesHandler, self).__call__(environ, start_response) + return super().__call__(environ, start_response) class _StaticFilesHandler(FSFilesHandler): @@ -1222,7 +1222,7 @@ class LiveServerThread(threading.Thread): self.error = None self.static_handler = static_handler self.connections_override = connections_override - super(LiveServerThread, self).__init__() + super().__init__() def run(self): """ @@ -1280,7 +1280,7 @@ class LiveServerTestCase(TransactionTestCase): @classmethod def setUpClass(cls): - super(LiveServerTestCase, cls).setUpClass() + super().setUpClass() connections_override = {} for conn in connections.all(): # If using in-memory sqlite databases, pass the connections to @@ -1331,7 +1331,7 @@ class LiveServerTestCase(TransactionTestCase): def tearDownClass(cls): cls._tearDownClassInternal() cls._live_server_modified_settings.disable() - super(LiveServerTestCase, cls).tearDownClass() + super().tearDownClass() class SerializeMixin: @@ -1354,9 +1354,9 @@ class SerializeMixin: "in the base class.".format(cls.__name__)) cls._lockfile = open(cls.lockfile) locks.lock(cls._lockfile, locks.LOCK_EX) - super(SerializeMixin, cls).setUpClass() + super().setUpClass() @classmethod def tearDownClass(cls): - super(SerializeMixin, cls).tearDownClass() + super().tearDownClass() cls._lockfile.close() diff --git a/django/test/utils.py b/django/test/utils.py index ef837ce5c7..43ce455762 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -65,7 +65,7 @@ class ContextList(list): return subcontext[key] raise KeyError(key) else: - return super(ContextList, self).__getitem__(key) + return super().__getitem__(key) def get(self, key, default=None): try: @@ -394,7 +394,7 @@ class override_settings(TestContextDecorator): """ def __init__(self, **kwargs): self.options = kwargs - super(override_settings, self).__init__() + super().__init__() def enable(self): # Keep this code at the beginning to leave the settings unchanged @@ -487,7 +487,7 @@ class modify_settings(override_settings): else: raise ValueError("Unsupported action: %s" % action) self.options[name] = value - super(modify_settings, self).enable() + super().enable() class override_system_checks(TestContextDecorator): @@ -501,7 +501,7 @@ class override_system_checks(TestContextDecorator): self.registry = registry self.new_checks = new_checks self.deployment_checks = deployment_checks - super(override_system_checks, self).__init__() + super().__init__() def enable(self): self.old_checks = self.registry.registered_checks @@ -654,7 +654,7 @@ class ignore_warnings(TestContextDecorator): self.filter_func = warnings.filterwarnings else: self.filter_func = warnings.simplefilter - super(ignore_warnings, self).__init__() + super().__init__() def enable(self): self.catch_warnings = warnings.catch_warnings() @@ -806,7 +806,7 @@ class override_script_prefix(TestContextDecorator): """ def __init__(self, prefix): self.prefix = prefix - super(override_script_prefix, self).__init__() + super().__init__() def enable(self): self.old_prefix = get_script_prefix() @@ -850,7 +850,7 @@ class isolate_apps(TestContextDecorator): def __init__(self, *installed_apps, **kwargs): self.installed_apps = installed_apps - super(isolate_apps, self).__init__(**kwargs) + super().__init__(**kwargs) def enable(self): self.old_apps = Options.default_apps |
