|
4 | 4 |
|
5 | 5 | import unittest
|
6 | 6 | import re
|
| 7 | +import sys |
7 | 8 |
|
8 | 9 | from pusher import Pusher
|
9 | 10 | from pusher.http import Request
|
@@ -50,27 +51,16 @@ def test_post_signature_generation(self):
|
50 | 51 |
|
51 | 52 | json_dumps_mock.assert_called_once_with({u"foo": u"bar"})
|
52 | 53 |
|
53 |
| - # Copied wholesale from https://github.com/python/cpython/blob/2d305e1c46abfcd609bf8b2dff8d2065e6af8ab2/Lib/unittest/case.py#L1279-L1289 |
54 |
| - # This can be removed when we no longer support Python 2.6 |
55 |
| - def assertRegexpMatches(self, text, expected_regex, msg=None): |
56 |
| - """Fail the test unless the text matches the regular expression.""" |
57 |
| - if isinstance(expected_regex, (str, bytes)): |
58 |
| - assert expected_regex, "expected_regex must not be empty." |
59 |
| - expected_regex = re.compile(expected_regex) |
60 |
| - if not expected_regex.search(text): |
61 |
| - standardMsg = "Regex didn't match: %r not found in %r" % ( |
62 |
| - expected_regex.pattern, text) |
63 |
| - # _formatMessage ensures the longMessage option is respected |
64 |
| - msg = self._formatMessage(msg, standardMsg) |
65 |
| - raise self.failureException(msg) |
66 |
| - |
67 | 54 | def test_x_pusher_library_header(self):
|
68 | 55 | conf = Pusher.from_url(u'http://key:secret@somehost/apps/4')
|
69 | 56 | req = Request(conf._pusher_client, u'GET', u'/some/obscure/api', {u'foo': u'bar'})
|
70 | 57 | self.assertTrue('X-Pusher-Library' in req.headers)
|
71 | 58 | pusherLib = req.headers['X-Pusher-Library']
|
72 |
| - self.assertRegexpMatches(pusherLib, r'^pusher-http-python \d+(\.\d+)+(rc\d+)?$') |
73 |
| - |
| 59 | + regex = r'^pusher-http-python \d+(\.\d+)+(rc\d+)?$' |
| 60 | + if sys.version_info < (3,): |
| 61 | + self.assertRegexpMatches(pusherLib, regex) |
| 62 | + else: |
| 63 | + self.assertRegex(pusherLib, regex) |
74 | 64 |
|
75 | 65 | if __name__ == '__main__':
|
76 | 66 | unittest.main()
|
0 commit comments