def test_version(version1, version2):
    """ Compares a version with a version string and checks if the first
    is in the range defined by the second. The second version can be
    prefixed by one of =, <, >, >=, <= or != to compare with a range of
    versions.
    """
    version1 = int(version1)
    version2 = str(version2)

    ver1 = version1
    ver2 = int(version2.lstrip('<>=!'))
    op   = version2.rstrip('0123456789')

    if len(op) == 0 or op == '=':
        return ver1 == ver2
    if op == "=" or op == "==":
        return ver1 == ver2
    if op == "<=":
        return ver1 <= ver2
    if op == "<":
        return ver1 < ver2
    if op == ">=":
        return ver1 >= ver2
    if op == ">":
        return ver1 > ver2
    if op == "!=" or op == "<>":
        return ver1 != ver2
    return False