00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 """Some tools for running tests based on MongoDB server version."""
00016
00017 def _padded(iter, length, padding=0):
00018 l = list(iter)
00019 if len(l) < length:
00020 for _ in range(length - len(l)):
00021 l.append(0)
00022 return l
00023
00024 def _parse_version_string(version_string):
00025 mod = 0
00026 if version_string.endswith("+"):
00027 version_string = version_string[0:-1]
00028 mod = 1
00029 elif version_string.endswith("-pre-"):
00030 version_string = version_string[0:-5]
00031 mod = -1
00032 elif version_string.endswith("-"):
00033 version_string = version_string[0:-1]
00034 mod = -1
00035
00036 if version_string.find('-rc') != -1:
00037 version_string = version_string[0:version_string.find('-rc')]
00038 mod = -1
00039
00040 version = [int(part) for part in version_string.split(".")]
00041 version = _padded(version, 3)
00042 version.append(mod)
00043
00044 return tuple(version)
00045
00046
00047 def version(connection):
00048 return _parse_version_string(connection.server_info()["version"])
00049
00050 def at_least(connection, min_version):
00051 return version(connection) >= tuple(_padded(min_version, 4))