Source

pip-testing / tests / test_search.txt

Basic setup::

    >>> from pip.commands.search import compare_versions, highest_version, translate_hits

Test version comparison::

    >>> compare_versions('1.0', '1.1')
    -1
    >>> compare_versions('1.1', '1.0')
    1
    >>> compare_versions('1.1a1', '1.1')
    -1
    >>> highest_version(['1.0', '2.0', '0.1'])
    '2.0'
    >>> highest_version(['1.0a1', '1.0'])
    '1.0'

Test hit translation (pypi xmlrpc to custom list)::

    >>> pypi_hits = [{'_pypi_ordering': 100, 'name': 'foo', 'summary': 'foo summary', 'version': '1.0'},
    ...              {'_pypi_ordering': 200, 'name': 'foo', 'summary': 'foo summary v2', 'version': '2.0'},
    ...              {'_pypi_ordering': 50, 'name': 'bar', 'summary': 'bar summary', 'version': '1.0'}]

    >>> print translate_hits(pypi_hits)
    [{'score': 200, 'versions': ['1.0', '2.0'], 'name': 'foo', 'summary': 'foo summary v2'}, {'score': 50, 'versions': ['1.0'], 'name': 'bar', 'summary': 'bar summary'}]