Fix xrange / range compat. issue

For Py2.x in test_core, use range everywhere but redefine in
compatibility, as requested.