Test the ``SortMixin`` class, which provides an ``insert_sorted``
method to insert items into a list in proper sorted order. As
long as only the ``insert_sorted`` method is used on the list,
it should be in the same order as the ``sorted`` builtin would
give applied to an arbitrary list with the same items. Note that
we use the ``upgrade_builtins`` method to ensure that ``sorted``
is in the builtin namespace even in earlier Python versions where
the standard builtin is not available.

    >>> from plib.stdlib import SortMixin, upgrade_builtins
    >>> upgrade_builtins()
    >>> class SortList(SortMixin, list):
    ...     pass
    ... 
    >>> def build_sortlist(l1, l2):
    ...     for item in l1:
    ...         l2.insert_sorted(item)
    ...         print l2
    ... 
    >>> l1 = ['c', 'b', 'e', 'a', 'd']
    >>> l2 = SortList()
    >>> build_sortlist(l1, l2)
    ['c']
    ['b', 'c']
    ['b', 'c', 'e']
    ['a', 'b', 'c', 'e']
    ['a', 'b', 'c', 'd', 'e']
    >>> l2 == sorted(l1)
    True

The default sorting function is the ``cmp`` builtin, so strings
should sort alphabetically, as above, but integers should sort
by value.

    >>> l1 = [3, 2, 5, 1, 4]
    >>> l2 = SortList()
    >>> build_sortlist(l1, l2)
    [3]
    [2, 3]
    [2, 3, 5]
    [1, 2, 3, 5]
    [1, 2, 3, 4, 5]
    >>> l2 == sorted(l1)
    True
    >>> l1 = [222, 1300, 51, 7, 411]
    >>> l2 = SortList()
    >>> build_sortlist(l1, l2)
    [222]
    [222, 1300]
    [51, 222, 1300]
    [7, 51, 222, 1300]
    [7, 51, 222, 411, 1300]
    >>> l2 == sorted(l1)
    True

We can supply a custom comparison function; let's test that
we can get integers to sort by their string representations,
instead of by value. Contrast the sort order with the previous
case.

    >>> def testcmp(x, y):
    ...     return cmp(str(x), str(y))
    ... 
    >>> def build_sortlist2(l1, l2):
    ...     for item in l1:
    ...         l2.insert_sorted(item, sortfunc=testcmp)
    ...         print l2
    ... 
    >>> l1 = [222, 1300, 51, 7, 411]
    >>> l2 = SortList()
    >>> build_sortlist2(l1, l2)
    [222]
    [1300, 222]
    [1300, 222, 51]
    [1300, 222, 51, 7]
    [1300, 222, 411, 51, 7]

Again, the sort should give the same results as the ``sorted``
builtin with our custom comparison. (Note that we use ``key=str``
here instead of ``cmp=testcmp`` so that in Python versions < 2.4,
where the ``sorted`` function is implemented in ``plib.stdlib``,
the test will work without having to special-case for the
parameter names being different--``sortfunc`` for the ``plib.stdlib``
implementation vs. ``cmp`` for the 2.4 and later builtin.)

    >>> l2 == sorted(l1, key=str)
    True

We can get the same result by using the ``key`` parameter.

    >>> def build_sortlist3(l1, l2):
    ...     for item in l1:
    ...         l2.insert_sorted(item, key=str)
    ...         print l2
    ... 
    >>> l1 = [222, 1300, 51, 7, 411]
    >>> l2 = SortList()
    >>> build_sortlist3(l1, l2)
    [222]
    [1300, 222]
    [1300, 222, 51]
    [1300, 222, 51, 7]
    [1300, 222, 411, 51, 7]
    >>> l2 == sorted(l1, key=str)
    True
