Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_assert_version():
# Minimum required version
ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0", ["0.1.2"])
# Too high version
with pytest.raises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0", ["0.1.2"])
# Too low version
with pytest.raises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0", ["0.1.2"])
# Blacklisted version
with pytest.raises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.1.2-1", "0.1.0", "0.2.0", ["0.1.2"])
def test_assert_version():
# Minimum required version
ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0", ["0.1.2"])
# Too high version
with pytest.raises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0", ["0.1.2"])
# Too low version
with pytest.raises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0", ["0.1.2"])
# Blacklisted version
with pytest.raises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.1.2-1", "0.1.0", "0.2.0", ["0.1.2"])
def is_available():
"""
Return whether the IPFS daemon is reachable or not
"""
global __is_available
if not isinstance(__is_available, bool):
try:
ipfshttpclient.connect()
except ipfshttpclient.exceptions.Error as error:
__is_available = False
# Make sure version incompatiblity is displayed to the user
if isinstance(error, ipfshttpclient.exceptions.VersionMismatch):
raise
else:
__is_available = True
return __is_available
def test_assert_version(self):
# Minimum required version
ipfshttpclient.assert_version("0.1.0", "0.1.0", "0.2.0")
# Too high version
with self.assertRaises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.2.0", "0.1.0", "0.2.0")
# Too low version
with self.assertRaises(ipfshttpclient.exceptions.VersionMismatch):
ipfshttpclient.assert_version("0.0.5", "0.1.0", "0.2.0")
Parameters
----------
version : str
The actual version of an IPFS daemon
minimum : str
The minimal IPFS daemon version to allowed
maximum : str
The maximum IPFS daemon version to allowed
"""
# Convert version strings to integer tuples
version = list(map(int, version.split('-', 1)[0].split('.')))
minimum = list(map(int, minimum.split('-', 1)[0].split('.')))
maximum = list(map(int, maximum.split('-', 1)[0].split('.')))
if minimum > version or version >= maximum:
raise exceptions.VersionMismatch(version, minimum, maximum)
for blacklisted in blacklist:
blacklisted = list(map(int, blacklisted.split('-', 1)[0].split('.')))
if version == blacklisted:
raise exceptions.VersionMismatch(version, minimum, maximum)
Parameters
----------
version : str
The version of an IPFS daemon.
minimum : str
The minimal IPFS version to allow.
maximum : str
The maximum IPFS version to allow.
"""
# Convert version strings to integer tuples
version = list(map(int, version.split('-', 1)[0].split('.')))
minimum = list(map(int, minimum.split('-', 1)[0].split('.')))
maximum = list(map(int, maximum.split('-', 1)[0].split('.')))
if minimum > version or version >= maximum:
raise exceptions.VersionMismatch(version, minimum, maximum)
The minimal IPFS daemon version to allowed
maximum : str
The maximum IPFS daemon version to allowed
"""
# Convert version strings to integer tuples
version = list(map(int, version.split('-', 1)[0].split('.')))
minimum = list(map(int, minimum.split('-', 1)[0].split('.')))
maximum = list(map(int, maximum.split('-', 1)[0].split('.')))
if minimum > version or version >= maximum:
raise exceptions.VersionMismatch(version, minimum, maximum)
for blacklisted in blacklist:
blacklisted = list(map(int, blacklisted.split('-', 1)[0].split('.')))
if version == blacklisted:
raise exceptions.VersionMismatch(version, minimum, maximum)