diff --git a/test/Makefile b/test/Makefile index 755beeb8..8328d5fb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -30,7 +30,7 @@ check-3.3: check-bytecode check-3.5: check-bytecode #: Run working tests from Python 3.4 -check-3.4: check-bytecode check-2.7-ok +check-3.4: check-bytecode check-3.4-ok check-2.7-ok $(PYTHON) test_pythonlib.py --bytecode-3.4 --verify $(COMPILE) #: Check deparsing only, but from a different Python version @@ -78,6 +78,10 @@ check-native-short: check-2.7-ok: $(PYTHON) test_pythonlib.py --ok-2.7 --verify $(COMPILE) +#: Run longer Python 2.7's lib files known to be okay +check-3.4-ok: + $(PYTHON) test_pythonlib.py --ok-3.4 --verify $(COMPILE) + clean: clean-py-dis clean-dis clean-unverified clean-dis: diff --git a/test/ok_lib3.4/antigravity.py b/test/ok_lib3.4/antigravity.py new file mode 100644 index 00000000..7670187f --- /dev/null +++ b/test/ok_lib3.4/antigravity.py @@ -0,0 +1,17 @@ + +import webbrowser +import hashlib + +webbrowser.open("http://xkcd.com/353/") + +def geohash(latitude, longitude, datedow): + '''Compute geohash() using the Munroe algorithm. + + >>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68') + 37.857713 -122.544543 + + ''' + # http://xkcd.com/426/ + h = hashlib.md5(datedow).hexdigest() + p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h[16:32])] + print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:])) diff --git a/test/ok_lib3.4/antigravity.pyc b/test/ok_lib3.4/antigravity.pyc new file mode 100644 index 00000000..74bdfb82 Binary files /dev/null and b/test/ok_lib3.4/antigravity.pyc differ diff --git a/test/ok_lib3.4/bisect.py b/test/ok_lib3.4/bisect.py new file mode 100644 index 00000000..4a4d0525 --- /dev/null +++ b/test/ok_lib3.4/bisect.py @@ -0,0 +1,92 @@ +"""Bisection algorithms.""" + +def insort_right(a, x, lo=0, hi=None): + """Insert item x in list a, and keep it sorted assuming a is sorted. + + If x is already in a, insert it to the right of the rightmost x. + + Optional args lo (default 0) and hi (default len(a)) bound the + slice of a to be searched. + """ + + if lo < 0: + raise ValueError('lo must be non-negative') + if hi is None: + hi = len(a) + while lo < hi: + mid = (lo+hi)//2 + if x < a[mid]: hi = mid + else: lo = mid+1 + a.insert(lo, x) + +insort = insort_right # backward compatibility + +def bisect_right(a, x, lo=0, hi=None): + """Return the index where to insert item x in list a, assuming a is sorted. + + The return value i is such that all e in a[:i] have e <= x, and all e in + a[i:] have e > x. So if x already appears in the list, a.insert(x) will + insert just after the rightmost x already there. + + Optional args lo (default 0) and hi (default len(a)) bound the + slice of a to be searched. + """ + + if lo < 0: + raise ValueError('lo must be non-negative') + if hi is None: + hi = len(a) + while lo < hi: + mid = (lo+hi)//2 + if x < a[mid]: hi = mid + else: lo = mid+1 + return lo + +bisect = bisect_right # backward compatibility + +def insort_left(a, x, lo=0, hi=None): + """Insert item x in list a, and keep it sorted assuming a is sorted. + + If x is already in a, insert it to the left of the leftmost x. + + Optional args lo (default 0) and hi (default len(a)) bound the + slice of a to be searched. + """ + + if lo < 0: + raise ValueError('lo must be non-negative') + if hi is None: + hi = len(a) + while lo < hi: + mid = (lo+hi)//2 + if a[mid] < x: lo = mid+1 + else: hi = mid + a.insert(lo, x) + + +def bisect_left(a, x, lo=0, hi=None): + """Return the index where to insert item x in list a, assuming a is sorted. + + The return value i is such that all e in a[:i] have e < x, and all e in + a[i:] have e >= x. So if x already appears in the list, a.insert(x) will + insert just before the leftmost x already there. + + Optional args lo (default 0) and hi (default len(a)) bound the + slice of a to be searched. + """ + + if lo < 0: + raise ValueError('lo must be non-negative') + if hi is None: + hi = len(a) + while lo < hi: + mid = (lo+hi)//2 + if a[mid] < x: lo = mid+1 + else: hi = mid + return lo + +# Overwrite above definitions with a fast C implementation +try: + from _bisect import * +except ImportError: + pass diff --git a/test/ok_lib3.4/bisect.pyc b/test/ok_lib3.4/bisect.pyc new file mode 100644 index 00000000..a9a6d1b1 Binary files /dev/null and b/test/ok_lib3.4/bisect.pyc differ diff --git a/test/test_pythonlib.py b/test/test_pythonlib.py index c6a0bba2..70eec7f6 100755 --- a/test/test_pythonlib.py +++ b/test/test_pythonlib.py @@ -70,6 +70,12 @@ test_options = { PYC, 'base_2.7', 2.7), } +for vers in (2.7, 3.4): + pythonlib = "ok_lib%s" % vers + key = "ok-%s" % vers + test_options[key] = (os.path.join(src_dir, pythonlib), PYC, key, vers) + pass + for vers in (2.5, 2.6, 2.7, 3.2, 3.3, 3.4): bytecode = "bytecode_%s" % vers key = "bytecode-%s" % vers