Skip to content

Commit

Permalink
Merge pull request rollbar#420 from rollbar/merge-pr419
Browse files Browse the repository at this point in the history
Replace unittest2 with unittest
  • Loading branch information
brianr authored Feb 24, 2023
2 parents b901726 + ebe4d3d commit c3b6510
Show file tree
Hide file tree
Showing 28 changed files with 258 additions and 345 deletions.
17 changes: 0 additions & 17 deletions .codeclimate.yml

This file was deleted.

322 changes: 145 additions & 177 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions UPGRADE_FROM_RATCHET.md

This file was deleted.

19 changes: 0 additions & 19 deletions default.nix

This file was deleted.

26 changes: 23 additions & 3 deletions rollbar/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
import unittest2
import unittest
import sys


SNOWMAN = b'\xe2\x98\x83'
SNOWMAN_UNICODE = SNOWMAN.decode('utf8')


class BaseTest(unittest2.TestCase):
class BaseTest(unittest.TestCase):
pass


class SkipAsyncTestLoader(unittest.TestLoader):
"""
Python 2 does not have the async keyword, so when tests are run under python 2.7 the loader
will fail with a syntaxerror. This loader class does the following:
- try to load as normal
- if loading fails because of a syntax error in python < 3.4, skip the file.
"""
def _get_module_from_name(self, name):
try:
return super(SkipAsyncTestLoader, self)._get_module_from_name(name)
except SyntaxError as e:
if sys.version_info < (3, 5):
return None
else:
raise


def discover():
return unittest2.defaultTestLoader.discover(__name__)
loader = SkipAsyncTestLoader()
suite = loader.discover(__name__)
return suite
4 changes: 2 additions & 2 deletions rollbar/test/asgi_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest2
import unittest


def _load_tests(loader, tests, pattern):
return unittest2.TestSuite()
return unittest.TestSuite()


if sys.version_info < (3, 5):
Expand Down
6 changes: 6 additions & 0 deletions rollbar/test/asgi_tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import unittest
import sys

from rollbar.test import BaseTest

ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 5)


@unittest.skipUnless(ALLOWED_PYTHON_VERSION, 'ASGI implementation requires Python3.5+')
class IntegrationTest(BaseTest):
def test_should_integrate_if__integrate_defined(self):
from rollbar.contrib.asgi.integration import IntegrationBase
Expand Down
10 changes: 5 additions & 5 deletions rollbar/test/asgi_tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
except ImportError:
import mock

import unittest2
import unittest

import rollbar
from rollbar.lib._async import AsyncMock
Expand All @@ -17,7 +17,7 @@
ASYNC_REPORT_ENABLED = sys.version_info >= (3, 6)


@unittest2.skipUnless(ALLOWED_PYTHON_VERSION, 'ASGI implementation requires Python3.5+')
@unittest.skipUnless(ALLOWED_PYTHON_VERSION, 'ASGI implementation requires Python3.5+')
class ReporterMiddlewareTest(BaseTest):
default_settings = copy.deepcopy(rollbar.SETTINGS)

Expand Down Expand Up @@ -62,7 +62,7 @@ def test_should_add_framework_name_to_payload(self, mock_send_payload, *mocks):

self.assertIn('asgi', payload['data']['framework'])

@unittest2.skipUnless(ASYNC_REPORT_ENABLED, 'Requires Python 3.6+')
@unittest.skipUnless(ASYNC_REPORT_ENABLED, 'Requires Python 3.6+')
@mock.patch('rollbar.lib._async.report_exc_info', new_callable=AsyncMock)
@mock.patch('rollbar.report_exc_info')
def test_should_use_async_report_exc_info_if_default_handler(
Expand All @@ -81,7 +81,7 @@ def test_should_use_async_report_exc_info_if_default_handler(
self.assertTrue(async_report_exc_info.called)
self.assertFalse(sync_report_exc_info.called)

@unittest2.skipUnless(ASYNC_REPORT_ENABLED, 'Requires Python 3.6+')
@unittest.skipUnless(ASYNC_REPORT_ENABLED, 'Requires Python 3.6+')
@mock.patch('rollbar.lib._async.report_exc_info', new_callable=AsyncMock)
@mock.patch('rollbar.report_exc_info')
def test_should_use_async_report_exc_info_if_any_async_handler(
Expand All @@ -100,7 +100,7 @@ def test_should_use_async_report_exc_info_if_any_async_handler(
self.assertTrue(async_report_exc_info.called)
self.assertFalse(sync_report_exc_info.called)

@unittest2.skipUnless(ASYNC_REPORT_ENABLED, 'Requires Python 3.6+')
@unittest.skipUnless(ASYNC_REPORT_ENABLED, 'Requires Python 3.6+')
@mock.patch('logging.Logger.warning')
@mock.patch('rollbar.lib._async.report_exc_info', new_callable=AsyncMock)
@mock.patch('rollbar.report_exc_info')
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/asgi_tests/test_spec.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import inspect
import sys

import unittest2
import unittest

from rollbar.test import BaseTest

ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 5)


@unittest2.skipUnless(ALLOWED_PYTHON_VERSION, 'ASGI implementation requires Python3.5+')
@unittest.skipUnless(ALLOWED_PYTHON_VERSION, 'ASGI implementation requires Python3.5+')
class ASGISpecTest(BaseTest):
def test_asgi_v3_middleware_is_single_callable_coroutine(self):
from rollbar.contrib.asgi import ReporterMiddleware
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/async_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest2
import unittest


def _load_tests(loader, tests, pattern):
return unittest2.TestSuite()
return unittest.TestSuite()


if sys.version_info < (3, 6):
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/async_tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
except ImportError:
import mock

import unittest2
import unittest

import rollbar
from rollbar.lib._async import AsyncMock
Expand All @@ -15,7 +15,7 @@
ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 6)


@unittest2.skipUnless(ALLOWED_PYTHON_VERSION, 'Async support requires Python3.6+')
@unittest.skipUnless(ALLOWED_PYTHON_VERSION, 'Async support requires Python3.6+')
class AsyncLibTest(BaseTest):
default_settings = copy.deepcopy(rollbar.SETTINGS)

Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/fastapi_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest2
import unittest


def _load_tests(loader, tests, pattern):
return unittest2.TestSuite()
return unittest.TestSuite()


if sys.version_info < (3, 6):
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/fastapi_tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
except ImportError:
FASTAPI_INSTALLED = False

import unittest2
import unittest

import rollbar
from rollbar.test import BaseTest

ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 6)


@unittest2.skipUnless(
@unittest.skipUnless(
FASTAPI_INSTALLED and ALLOWED_PYTHON_VERSION,
'FastAPI LoggerMiddleware requires Python3.6+',
)
Expand Down
8 changes: 4 additions & 4 deletions rollbar/test/fastapi_tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
except ImportError:
FASTAPI_INSTALLED = False

import unittest2
import unittest

import rollbar
from rollbar.lib._async import AsyncMock
Expand All @@ -23,7 +23,7 @@
ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 6)


@unittest2.skipUnless(
@unittest.skipUnless(
FASTAPI_INSTALLED and ALLOWED_PYTHON_VERSION, 'FastAPI requires Python3.6+'
)
class ReporterMiddlewareTest(BaseTest):
Expand Down Expand Up @@ -258,7 +258,7 @@ async def root():
'Failed to report asynchronously. Trying to report synchronously.'
)

@unittest2.skipUnless(
@unittest.skipUnless(
sys.version_info >= (3, 6), 'Global request access requires Python 3.6+'
)
@mock.patch('rollbar.contrib.starlette.middleware.store_current_request')
Expand Down Expand Up @@ -305,7 +305,7 @@ async def read_root():
scope = store_current_request.call_args[0][0]
self.assertDictContainsSubset(expected_scope, scope)

@unittest2.skipUnless(
@unittest.skipUnless(
sys.version_info >= (3, 6), 'Global request access is supported in Python 3.6+'
)
def test_should_return_current_request(self):
Expand Down
12 changes: 6 additions & 6 deletions rollbar/test/fastapi_tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FASTAPI_INSTALLED = False
ALLOWED_FASTAPI_VERSION = False

import unittest2
import unittest

import rollbar
from rollbar.lib._async import AsyncMock
Expand All @@ -27,7 +27,7 @@
ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 6)


@unittest2.skipUnless(
@unittest.skipUnless(
FASTAPI_INSTALLED and ALLOWED_PYTHON_VERSION, 'FastAPI requires Python3.6+'
)
class LoggingRouteUnsupportedFastAPIVersionTest(BaseTest):
Expand Down Expand Up @@ -64,10 +64,10 @@ def test_should_disable_loading_route_handler_if_fastapi_is_too_old(self):
fastapi.__version__ = fastapi_version


@unittest2.skipUnless(
@unittest.skipUnless(
FASTAPI_INSTALLED and ALLOWED_PYTHON_VERSION, 'FastAPI requires Python3.6+'
)
@unittest2.skipUnless(ALLOWED_FASTAPI_VERSION, 'FastAPI v0.41.0+ is required')
@unittest.skipUnless(ALLOWED_FASTAPI_VERSION, 'FastAPI v0.41.0+ is required')
class LoggingRouteTest(BaseTest):
default_settings = copy.deepcopy(rollbar.SETTINGS)

Expand Down Expand Up @@ -686,7 +686,7 @@ def test_should_warn_if_middleware_in_use(self):
' This can cause in duplicate occurrences.'
)

@unittest2.skipUnless(
@unittest.skipUnless(
sys.version_info >= (3, 6), 'Global request access requires Python 3.6+'
)
@mock.patch('rollbar.contrib.fastapi.routing.store_current_request')
Expand Down Expand Up @@ -733,7 +733,7 @@ async def read_root():
scope = store_current_request.call_args[0][0]
self.assertDictContainsSubset(expected_scope, scope)

@unittest2.skipUnless(
@unittest.skipUnless(
sys.version_info >= (3, 6), 'Global request access is supported in Python 3.6+'
)
def test_should_return_current_request(self):
Expand Down
6 changes: 3 additions & 3 deletions rollbar/test/fastapi_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
except ImportError:
FASTAPI_INSTALLED = False

import unittest2
import unittest

from rollbar.test import BaseTest

ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 6)


@unittest2.skipUnless(
@unittest.skipUnless(
FASTAPI_INSTALLED and ALLOWED_PYTHON_VERSION, 'FastAPI requires Python3.6+'
)
class UtilsMiddlewareTest(BaseTest):
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_should_return_empty_list_if_rollbar_middlewares_not_installed(self):
self.assertListEqual(middlewares, [])


@unittest2.skipUnless(
@unittest.skipUnless(
FASTAPI_INSTALLED and ALLOWED_PYTHON_VERSION, 'FastAPI requires Python3.6+'
)
class UtilsBareRoutingTest(BaseTest):
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/starlette_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys
import unittest2
import unittest


def _load_tests(loader, tests, pattern):
return unittest2.TestSuite()
return unittest.TestSuite()


if sys.version_info < (3, 6):
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/starlette_tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
except ImportError:
STARLETTE_INSTALLED = False

import unittest2
import unittest

import rollbar
from rollbar.test import BaseTest

ALLOWED_PYTHON_VERSION = sys.version_info >= (3, 6)


@unittest2.skipUnless(
@unittest.skipUnless(
STARLETTE_INSTALLED and ALLOWED_PYTHON_VERSION,
'Starlette LoggerMiddleware requires Python3.6+',
)
Expand Down
Loading

0 comments on commit c3b6510

Please sign in to comment.