summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Chan <alex@alexwlchan.net>2017-06-03 08:48:04 +0100
committerAlex Chan <alex@alexwlchan.net>2017-06-03 08:48:04 +0100
commit78812eac517d06db6b766cbadefda7267315944e (patch)
treeeabb38713fbffb19984d177aa3f30c845320cf7c
parent23edb7986d47150f620edb68c5a563baec7bda40 (diff)
downloadurllib3-78812eac517d06db6b766cbadefda7267315944e.tar.gz
Rewrite test_connection.py to be pytest-style
-rw-r--r--test/test_connection.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/test/test_connection.py b/test/test_connection.py
index f41e0e71..be50f6c4 100644
--- a/test/test_connection.py
+++ b/test/test_connection.py
@@ -1,6 +1,7 @@
import datetime
import mock
-import sys
+
+import pytest
from urllib3.connection import (
CertificateError,
@@ -8,25 +9,22 @@ from urllib3.connection import (
RECENT_DATE
)
-if sys.version_info >= (2, 7):
- import unittest
-else:
- import unittest2 as unittest
-
-class TestConnection(unittest.TestCase):
+class TestConnection(object):
"""
Tests in this suite should not make any network requests or connections.
"""
def test_match_hostname_no_cert(self):
cert = None
asserted_hostname = 'foo'
- self.assertRaises(ValueError, _match_hostname, cert, asserted_hostname)
+ with pytest.raises(ValueError):
+ _match_hostname(cert, asserted_hostname)
def test_match_hostname_empty_cert(self):
cert = {}
asserted_hostname = 'foo'
- self.assertRaises(ValueError, _match_hostname, cert, asserted_hostname)
+ with pytest.raises(ValueError):
+ _match_hostname(cert, asserted_hostname)
def test_match_hostname_match(self):
cert = {'subjectAltName': [('DNS', 'foo')]}
@@ -40,13 +38,13 @@ class TestConnection(unittest.TestCase):
with mock.patch('urllib3.connection.log.error') as mock_log:
_match_hostname(cert, asserted_hostname)
except CertificateError as e:
- self.assertEqual(str(e), "hostname 'bar' doesn't match 'foo'")
+ assert str(e) == "hostname 'bar' doesn't match 'foo'"
mock_log.assert_called_once_with(
'Certificate did not match expected hostname: %s. '
'Certificate: %s',
'bar', {'subjectAltName': [('DNS', 'foo')]}
)
- self.assertEqual(e._peer_cert, cert)
+ assert e._peer_cert == cert
def test_recent_date(self):
# This test is to make sure that the RECENT_DATE value
@@ -54,8 +52,4 @@ class TestConnection(unittest.TestCase):
# When this test fails update urllib3.connection.RECENT_DATE
# according to the rules defined in that file.
two_years = datetime.timedelta(days=365 * 2)
- self.assertGreater(RECENT_DATE, (datetime.datetime.today() - two_years).date())
-
-
-if __name__ == '__main__':
- unittest.main()
+ assert RECENT_DATE > (datetime.datetime.today() - two_years).date()