Python 3 fix: DeprecationWarning: Please use assertRaisesRegex instead

This commit is contained in:
hugovk 2014-03-12 15:18:24 +02:00
parent 20b9bdedd2
commit 506bee4fe4

View file

@ -5,6 +5,7 @@ Integration (not unit) tests for pylast.py
import argparse import argparse
import os import os
from random import choice from random import choice
import sys
import time import time
import unittest import unittest
@ -30,6 +31,16 @@ class TestPyLast(unittest.TestCase):
secrets = None secrets = None
# Based on django/utils/six.py to remove Python 3's
# "DeprecationWarning: Please use assertRaisesRegex instead"
if sys.version_info[0] == 2:
_assertRaisesRegex = "assertRaisesRegexp"
else:
_assertRaisesRegex = "assertRaisesRegex"
def assertRaisesRegex(self, *args, **kwargs):
return getattr(self, self._assertRaisesRegex)(*args, **kwargs)
def unix_timestamp(self): def unix_timestamp(self):
return int(time.time()) return int(time.time())
@ -756,7 +767,7 @@ class TestPyLast(unittest.TestCase):
artist = self.network.get_artist("Test Artist") artist = self.network.get_artist("Test Artist")
# Act/Assert # Act/Assert
with self.assertRaisesRegexp(pylast.WSError, 'deprecated'): with self.assertRaisesRegex(pylast.WSError, 'deprecated'):
artist.get_images() artist.get_images()
def helper_validate_results(self, a, b, c): def helper_validate_results(self, a, b, c):