diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-08-16 18:35:58 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-08-16 18:35:58 +0200 |
commit | f93cd6a33505095aae3aaae4e14d5f9cb30184f6 (patch) | |
tree | eb144bebc0b74c3db1fc566d1a96c098080f8bbc /test/test_certutils.py | |
parent | 6d1b601ddf070ef1335be1804386fa0f4a2fcbd4 (diff) | |
download | mitmproxy-f93cd6a33505095aae3aaae4e14d5f9cb30184f6.tar.gz mitmproxy-f93cd6a33505095aae3aaae4e14d5f9cb30184f6.tar.bz2 mitmproxy-f93cd6a33505095aae3aaae4e14d5f9cb30184f6.zip |
always use with statement to open files
Diffstat (limited to 'test/test_certutils.py')
-rw-r--r-- | test/test_certutils.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/test/test_certutils.py b/test/test_certutils.py index 95a7280e..55fcc1dc 100644 --- a/test/test_certutils.py +++ b/test/test_certutils.py @@ -116,11 +116,15 @@ class TestDummyCert: class TestSSLCert: def test_simple(self): - c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert"), "rb").read()) + with open(tutils.test_data.path("data/text_cert"), "rb") as f: + d = f.read() + c = certutils.SSLCert.from_pem(d) assert c.cn == "google.com" assert len(c.altnames) == 436 - c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_2"), "rb").read()) + with open(tutils.test_data.path("data/text_cert_2"), "rb") as f: + d = f.read() + c = certutils.SSLCert.from_pem(d) assert c.cn == "www.inode.co.nz" assert len(c.altnames) == 2 assert c.digest("sha1") @@ -134,12 +138,15 @@ class TestSSLCert: c.has_expired def test_err_broken_sans(self): - c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_weird1"), "rb").read()) + with open(tutils.test_data.path("data/text_cert_weird1"), "rb") as f: + d = f.read() + c = certutils.SSLCert.from_pem(d) # This breaks unless we ignore a decoding error. c.altnames def test_der(self): - d = file(tutils.test_data.path("data/dercert"),"rb").read() + with open(tutils.test_data.path("data/dercert"), "rb") as f: + d = f.read() s = certutils.SSLCert.from_der(d) assert s.cn |