Skip to content

Commit

Permalink
- Add python versions, update and refine framework versions
Browse files Browse the repository at this point in the history
- Fix tests so that tests containing py3 syntax are skipped when running on py2
- Update CI matrix, get CI passing on full matrix
  • Loading branch information
brianr committed Feb 24, 2023
1 parent f83ef98 commit 1ffda5c
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 185 deletions.
322 changes: 145 additions & 177 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion rollbar/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import sys


SNOWMAN = b'\xe2\x98\x83'
Expand All @@ -9,5 +10,24 @@ 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 unittest.defaultTestLoader.discover(__name__)
loader = SkipAsyncTestLoader()
suite = loader.discover(__name__)
return suite
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
4 changes: 2 additions & 2 deletions rollbar/test/test_rollbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,8 @@ def _raise(password='sensitive', clear='text'):

self.assertEqual(2, len(payload['data']['body']['trace']['frames'][-1]['argspec']))
self.assertEqual('password', payload['data']['body']['trace']['frames'][-1]['argspec'][0])
self.assertRegex(payload['data']['body']['trace']['frames'][-1]['locals']['password'], r'\*+')
self.assertRegex(payload['data']['body']['trace']['frames'][-1]['locals']['headers']['Authorization'], r'\*+')
six.assertRegex(self, payload['data']['body']['trace']['frames'][-1]['locals']['password'], r'\*+')
six.assertRegex(self, payload['data']['body']['trace']['frames'][-1]['locals']['headers']['Authorization'], r'\*+')
self.assertEqual('clear', payload['data']['body']['trace']['frames'][-1]['argspec'][1])
self.assertEqual('text', payload['data']['body']['trace']['frames'][-1]['locals']['clear'])

Expand Down
9 changes: 8 additions & 1 deletion rollbar/test/test_serializable_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import base64
import copy
import enum
import sys

try:
# Python 3
Expand Down Expand Up @@ -147,7 +148,13 @@ def test_encode_int(self):
def test_encode_empty_tuple(self):
start = ()
expected = ()
self._assertSerialized(start, expected)

skip_id_check = False
# different behavior in 3.11
if sys.version_info >= (3, 11):
skip_id_check = True

self._assertSerialized(start, expected, skip_id_check=skip_id_check)

def test_encode_empty_list(self):
start = []
Expand Down
2 changes: 2 additions & 0 deletions rollbar/test/test_shortener_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def test_shorten_frozenset(self):

def test_shorten_array(self):
expected = 'array(\'l\', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...])'
if sys.version_info >= (3, 10):
expected = '[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]'
self._assert_shortened('array', expected)

def test_shorten_deque(self):
Expand Down
4 changes: 2 additions & 2 deletions rollbar/test/twisted_tests/test_twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_base_case(self, send_payload):
self.proto.dataReceived('8')
self.assertEqual(int(self.tr.value()), 64)

self.assertEqual(send_payload.called, False)
self.assertFalse(send_payload.called)

@mock.patch('rollbar.send_payload')
def test_caught_exception(self, send_payload):
Expand All @@ -63,7 +63,7 @@ def test_caught_exception(self, send_payload):
errors = self.flushLoggedErrors(ValueError)
self.assertEqual(len(errors), 1)

self.assertEqual(send_payload.called, True)
self.assertTrue(send_payload.called)
payload = send_payload.call_args[0][0]
data = payload['data']

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
# always installs the latest version of the package.
'requests>=0.12.1; python_version == "2.7"',
'requests>=0.12.1; python_version >= "3.6"',
'requests<2.26,>=0.12.1; python_version == "3.5"',
'requests<2.22,>=0.12.1; python_version == "3.4"',
'requests>=0.12.1; python_version == "3.5"',
'requests>=0.12.1; python_version == "3.4"',
'six>=1.9.0'
],
tests_require=tests_require,
Expand Down

0 comments on commit 1ffda5c

Please sign in to comment.