issue2061_fix_DeprecationWarning_in_unit_tests

This commit is contained in:
zhenghaitao
2016-04-08 15:18:42 +08:00
parent 75ed978cec
commit bf15c88811

View File

@@ -8,6 +8,7 @@ $ nosetests -v
"""
import os
import sys
import time
import unittest
@@ -44,7 +45,7 @@ class ApiExceptionTests(unittest.TestCase):
self.pet_api.add_pet(body=self.pet)
self.pet_api.delete_pet(pet_id=self.pet.id)
with self.assertRaisesRegexp(ApiException, "Pet not found"):
with self.checkRaiseRegex(ApiException, "Pet not found"):
self.pet_api.get_pet_by_id(pet_id=self.pet.id)
try:
@@ -52,12 +53,12 @@ class ApiExceptionTests(unittest.TestCase):
except ApiException as e:
self.assertEqual(e.status, 404)
self.assertEqual(e.reason, "Not Found")
self.assertRegexpMatches(e.body, "Pet not found")
self.checkRegex(e.body, "Pet not found")
def test_500_error(self):
self.pet_api.add_pet(body=self.pet)
with self.assertRaisesRegexp(ApiException, "Internal Server Error"):
with self.checkRaiseRegex(ApiException, "Internal Server Error"):
self.pet_api.upload_file(
pet_id=self.pet.id,
additional_metadata="special",
@@ -73,4 +74,17 @@ class ApiExceptionTests(unittest.TestCase):
except ApiException as e:
self.assertEqual(e.status, 500)
self.assertEqual(e.reason, "Internal Server Error")
self.assertRegexpMatches(e.body, "Error 500 Internal Server Error")
self.checkRegex(e.body, "Error 500 Internal Server Error")
def checkRaiseRegex(self, expected_exception, expected_regex):
if sys.version_info < (3, 0):
return self.assertRaisesRegexp(expected_exception, expected_regex)
return self.assertRaisesRegex(expected_exception, expected_regex)
def checkRegex(self, text, expected_regex):
if sys.version_info < (3, 0):
return self.assertRegexpMatches(text, expected_regex)
return self.assertRegex(text, expected_regex)