Fix pytest 5.x compatibility

This commit is contained in:
shortcutme 2019-07-03 18:36:41 +02:00
parent ff32f822ba
commit eb2627721e
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
6 changed files with 28 additions and 28 deletions

View File

@ -62,7 +62,7 @@ class TestBigfile:
piece = io.BytesIO(f.read(1024 * 1024))
f.close()
site.content_manager.verifyPiece(inner_path, i * 1024 * 1024, piece)
assert "Invalid hash" in str(err)
assert "Invalid hash" in str(err.value)
def testSparseFile(self, site):
inner_path = "sparsefile"

View File

@ -66,7 +66,7 @@ class TestContent:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
assert "Include too large" in str(err)
assert "Include too large" in str(err.value)
# Reset
data_dict["files"]["data.json"]["size"] = 505
@ -78,7 +78,7 @@ class TestContent:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
assert "File not allowed" in str(err)
assert "File not allowed" in str(err.value)
# Reset
del data_dict["files"]["notallowed.exe"]
@ -94,7 +94,7 @@ class TestContent:
# Bad privatekey
with pytest.raises(SignError) as err:
site.content_manager.sign(inner_path, privatekey="5aaa3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMnaa", filewrite=False)
assert "Private key invalid" in str(err)
assert "Private key invalid" in str(err.value)
# Good privatekey
content = site.content_manager.sign(inner_path, privatekey=self.privatekey, filewrite=False)
@ -172,7 +172,7 @@ class TestContent:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
assert "Wrong site address" in str(err)
assert "Wrong site address" in str(err.value)
# Wrong inner_path
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
@ -184,7 +184,7 @@ class TestContent:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
assert "Wrong inner_path" in str(err)
assert "Wrong inner_path" in str(err.value)
# Everything right again
data_dict["address"] = "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"
@ -224,14 +224,14 @@ class TestContent:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(inner_path, data, ignore_same=False)
assert "Invalid relative path" in str(err)
assert "Invalid relative path" in str(err.value)
@pytest.mark.parametrize("key", ["ignore", "optional"])
def testSignUnsafePattern(self, site, key):
site.content_manager.contents["content.json"][key] = "([a-zA-Z]+)*"
with pytest.raises(UnsafePatternError) as err:
site.content_manager.sign("content.json", privatekey=self.privatekey, filewrite=False)
assert "Potentially unsafe" in str(err)
assert "Potentially unsafe" in str(err.value)
def testVerifyUnsafePattern(self, site, crypt_bitcoin_lib):
@ -239,10 +239,10 @@ class TestContent:
with pytest.raises(UnsafePatternError) as err:
with site.storage.open("data/test_include/content.json") as data:
site.content_manager.verifyFile("data/test_include/content.json", data, ignore_same=False)
assert "Potentially unsafe" in str(err)
assert "Potentially unsafe" in str(err.value)
site.content_manager.contents["data/users/content.json"]["user_contents"]["permission_rules"]["([a-zA-Z]+)*"] = {"max_size": 0}
with pytest.raises(UnsafePatternError) as err:
with site.storage.open("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json") as data:
site.content_manager.verifyFile("data/users/1C5sgvWaSgfaTpV5kjBCnCiKtENNMYo69q/content.json", data, ignore_same=False)
assert "Potentially unsafe" in str(err)
assert "Potentially unsafe" in str(err.value)

View File

@ -103,7 +103,7 @@ class TestContentUser:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
assert "Include too large" in str(err)
assert "Include too large" in str(err.value)
# Give more space based on address
users_content["user_contents"]["permissions"]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9"] = {"max_size": 20000}
@ -135,7 +135,7 @@ class TestContentUser:
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
assert "Include too large" in str(err)
assert "Include too large" in str(err.value)
users_content["user_contents"]["permission_rules"][".*"]["max_size"] = 10000 # Reset
# Test max optional size exception
@ -157,7 +157,7 @@ class TestContentUser:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
assert "Include optional files too large" in str(err)
assert "Include optional files too large" in str(err.value)
data_dict["files_optional"]["peanut-butter-jelly-time.gif"]["size"] = 1024 * 1024 # Reset
# hello.exe = Not allowed
@ -169,7 +169,7 @@ class TestContentUser:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
assert "Optional file not allowed" in str(err)
assert "Optional file not allowed" in str(err.value)
del data_dict["files_optional"]["hello.exe"] # Reset
# Includes not allowed in user content
@ -181,7 +181,7 @@ class TestContentUser:
data = io.BytesIO(json.dumps(data_dict).encode())
with pytest.raises(VerifyError) as err:
site.content_manager.verifyFile(user_inner_path, data, ignore_same=False)
assert "Includes not allowed" in str(err)
assert "Includes not allowed" in str(err.value)
def testCert(self, site):
# user_addr = "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C"
@ -238,7 +238,7 @@ class TestContentUser:
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
)
assert "Valid signs: 0/1" in str(err)
assert "Valid signs: 0/1" in str(err.value)
del site.content_manager.contents["data/users/content.json"]["user_contents"]["permissions"][cert_user_id] # Reset
# Test invalid cert
@ -253,7 +253,7 @@ class TestContentUser:
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
)
assert "Invalid cert" in str(err)
assert "Invalid cert" in str(err.value)
# Test banned user, signed by the site owner
user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % (
@ -313,7 +313,7 @@ class TestContentUser:
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
)
assert "Invalid domain in cert_user_id" in str(err)
assert "Invalid domain in cert_user_id" in str(err.value)
# Test removed cert
del user_content["cert_user_id"]
@ -330,7 +330,7 @@ class TestContentUser:
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
)
assert "Missing cert_user_id" in str(err)
assert "Missing cert_user_id" in str(err.value)
def testCertSignersPattern(self, site):
@ -366,7 +366,7 @@ class TestContentUser:
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
)
assert "Invalid cert signer: 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" in str(err)
assert "Invalid cert signer: 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" in str(err.value)
# Removed cert_signers_pattern
del rules_content["user_contents"]["cert_signers_pattern"]
@ -376,7 +376,7 @@ class TestContentUser:
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
io.BytesIO(json.dumps(signed_content).encode()), ignore_same=False
)
assert "Invalid cert signer: 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" in str(err)
assert "Invalid cert signer: 14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet" in str(err.value)
def testNewFile(self, site):

View File

@ -129,4 +129,4 @@ class TestNoparallel:
with pytest.raises(Exception) as err:
raiseException()
assert str(err) == "Test error!"
assert str(err.value) == "Test error!"

View File

@ -15,10 +15,10 @@ class TestSafeRe:
def testUnsafeMatch(self, pattern):
with pytest.raises(SafeRe.UnsafePatternError) as err:
SafeRe.match(pattern, "aaaaaaaaaaaaaaaaaaaaaaaa!")
assert "Potentially unsafe" in str(err)
assert "Potentially unsafe" in str(err.value)
@pytest.mark.parametrize("pattern", ["^(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)(.*a)$"])
def testUnsafeRepetition(self, pattern):
with pytest.raises(SafeRe.UnsafePatternError) as err:
SafeRe.match(pattern, "aaaaaaaaaaaaaaaaaaaaaaaa!")
assert "More than" in str(err)
assert "More than" in str(err.value)

View File

@ -126,9 +126,9 @@ class TestUpnpPunch(object):
def test_parse_for_errors_bad_rsp(self, httplib_response):
rsp = httplib_response(status=500)
with pytest.raises(upnp.IGDError) as exc:
with pytest.raises(upnp.IGDError) as err:
upnp._parse_for_errors(rsp)
assert 'Unable to parse' in str(exc)
assert 'Unable to parse' in str(err.value)
def test_parse_for_errors_error(self, httplib_response):
soap_error = ('<document>'
@ -136,9 +136,9 @@ class TestUpnpPunch(object):
'<errorDescription>Bad request</errorDescription>'
'</document>')
rsp = httplib_response(status=500, body=soap_error)
with pytest.raises(upnp.IGDError) as exc:
with pytest.raises(upnp.IGDError) as err:
upnp._parse_for_errors(rsp)
assert 'SOAP request error' in str(exc)
assert 'SOAP request error' in str(err.value)
def test_parse_for_errors_good_rsp(self, httplib_response):
rsp = httplib_response(status=200)