Commits

Amaury Forgeot d'Arc committed 1b96f59

Add a way to run applevel tests with python 3: --appdirect=/path/to/python3
This implies -A, of course

Fix range() tests to pass on python3.

Comments (0)

Files changed (3)

 from inspect import isclass, getmro
 from pypy.tool.udir import udir
 from pypy.tool.autopath import pypydir
-from pypy.tool import leakfinder
+from pypy.tool import leakfinder, runsubprocess
 
 # pytest settings
 rsyncdirs = ['.', '../lib-python', '../lib_pypy', '../demo']
 option = None
 
 def pytest_report_header():
-    return "pytest-%s from %s" %(pytest.__version__, pytest.__file__)
+    return "pytest-%s from %s" % (pytest.__version__, pytest.__file__)
 
 def pytest_configure(config):
     global option
     option = config.option
+    if option.appdirect:
+        option.runappdirect = True
 
 def _set_platform(opt, opt_str, value, parser):
     from pypy.config.translationoption import PLATFORMS
     group.addoption('-A', '--runappdirect', action="store_true",
            default=False, dest="runappdirect",
            help="run applevel tests directly on python interpreter (not through PyPy)")
+    group.addoption('--appdirect', type="string",
+           help="run applevel tests directly with the specified interpreter")
     group.addoption('--direct', action="store_true",
            default=False, dest="rundirect",
            help="run pexpect tests directly")
     if option.runappdirect:
         py.test.skip("translation test, skipped for appdirect")
 
+def run_with_python(python, target):
+    helpers = """if 1:
+    def raises(exc, func, *args, **kwargs):
+        try:
+            func(*args, **kwargs)
+        except exc:
+            pass
+        else:
+            raise AssertionError("DID NOT RAISE")
+"""
+    source = py.code.Source(target)[1:].deindent()
+    res, stdout, stderr = runsubprocess.run_subprocess(
+        python, ["-c", helpers + str(source)])
+    print source
+    print >> sys.stdout, stdout
+    print >> sys.stderr, stderr
+    if res > 0:
+        raise AssertionError("Subprocess failed")
 
 class OpErrKeyboardInterrupt(KeyboardInterrupt):
     pass
     def runtest(self):
         target = self.obj
         if self.config.option.runappdirect:
+            if self.config.option.appdirect:
+                return run_with_python(self.config.option.appdirect, target)
             return target()
         space = gettestobjspace()
         filename = self._getdynfilename(target)
     def runtest(self):
         target = self.obj
         if self.config.option.runappdirect:
+            if self.config.option.appdirect:
+                return run_with_python(self.config.option.appdirect, target)
             return target()
         space = target.im_self.space
         filename = self._getdynfilename(target)

pypy/module/__builtin__/test/test_range.py

       raises(TypeError, range,  1, 2, 3, 4)
 
    def test_range_one(self):
-      assert range(1) == [0]
+      assert list(range(1)) == [0]
 
    def test_range_posstartisstop(self):
-      assert range(1, 1) == []
+      assert list(range(1, 1)) == []
 
    def test_range_negstartisstop(self):
-      assert range(-1, -1) == []
+      assert list(range(-1, -1)) == []
 
    def test_range_zero(self):
-      assert range(0) == []
+      assert list(range(0)) == []
 
    def test_range_twoargs(self):
-      assert range(1, 2) == [1]
+      assert list(range(1, 2)) == [1]
       
    def test_range_decreasingtwoargs(self):
-      assert range(3, 1) == []
+      assert list(range(3, 1)) == []
 
    def test_range_negatives(self):
-      assert range(-3) == []
+      assert list(range(-3)) == []
 
    def test_range_decreasing_negativestep(self):
-      assert range(5, -2, -1) == [5, 4, 3, 2, 1, 0 , -1]
+      assert list(range(5, -2, -1)) == [5, 4, 3, 2, 1, 0 , -1]
 
    def test_range_posfencepost1(self):
-       assert range (1, 10, 3) == [1, 4, 7]
+       assert list(range(1, 10, 3)) == [1, 4, 7]
 
    def test_range_posfencepost2(self):
-       assert range (1, 11, 3) == [1, 4, 7, 10]
+       assert list(range(1, 11, 3)) == [1, 4, 7, 10]
 
    def test_range_posfencepost3(self):
-       assert range (1, 12, 3) == [1, 4, 7, 10]
+       assert list(range(1, 12, 3)) == [1, 4, 7, 10]
 
    def test_range_negfencepost1(self):
-       assert range (-1, -10, -3) == [-1, -4, -7]
+       assert list(range(-1, -10, -3)) == [-1, -4, -7]
 
    def test_range_negfencepost2(self):
-       assert range (-1, -11, -3) == [-1, -4, -7, -10]
+       assert list(range(-1, -11, -3)) == [-1, -4, -7, -10]
 
    def test_range_negfencepost3(self):
-       assert range (-1, -12, -3) == [-1, -4, -7, -10]
+       assert list(range(-1, -12, -3)) == [-1, -4, -7, -10]
 
    def test_range_decreasing_negativelargestep(self):
-       assert range(5, -2, -3) == [5, 2, -1]
+       assert list(range(5, -2, -3)) == [5, 2, -1]
 
    def test_range_increasing_positivelargestep(self):
-       assert range(-5, 2, 3) == [-5, -2, 1]
+       assert list(range(-5, 2, 3)) == [-5, -2, 1]
 
    def test_range_zerostep(self):
        raises(ValueError, range, 1, 5, 0)
    def test_range_wrong_type(self):
        raises(TypeError, range, "42")
 
-   def test_range_object_with___int__(self):
+   def test_range_object_with___index__(self):
        class A(object):
-           def __int__(self):
+           def __index__(self):
                return 5
 
-       assert range(A()) == [0, 1, 2, 3, 4]
-       assert range(0, A()) == [0, 1, 2, 3, 4]
-       assert range(0, 10, A()) == [0, 5]
+       assert list(range(A())) == [0, 1, 2, 3, 4]
+       assert list(range(0, A())) == [0, 1, 2, 3, 4]
+       assert list(range(0, 10, A())) == [0, 5]
 
    def test_range_long(self):
        import sys
-       assert range(-2**100) == []
-       assert range(0, -2**100) == []
-       assert range(0, 2**100, -1) == []
-       assert range(0, 2**100, -1) == []
+       assert list(range(-2**100)) == []
+       assert list(range(0, -2**100)) == []
+       assert list(range(0, 2**100, -1)) == []
+       assert list(range(0, 2**100, -1)) == []
 
-       a = long(10 * sys.maxint)
-       assert range(a, a+2) == [a, a+1]
-       assert range(a+2, a, -1L) == [a+2, a+1]
-       assert range(a+4, a, -2) == [a+4, a+2]
-       assert range(a, a*5, a) == [a, 2*a, 3*a, 4*a]
+       a = 10 * sys.maxsize
+       assert list(range(a, a+2)) == [a, a+1]
+       assert list(range(a+2, a, -1)) == [a+2, a+1]
+       assert list(range(a+4, a, -2)) == [a+4, a+2]
+       assert list(range(a, a*5, a)) == [a, 2*a, 3*a, 4*a]
 
    def test_range_cases(self):
        import sys
-       for start in [10, 10 * sys.maxint]:
+       for start in [10, 10 * sys.maxsize]:
            for stop in [start-4, start-1, start, start+1, start+4]:
               for step in [1, 2, 3, 4]:
-                  lst = range(start, stop, step)
+                  lst = list(range(start, stop, step))
                   expected = []
                   a = start
                   while a < stop:
                       a += step
                   assert lst == expected
               for step in [-1, -2, -3, -4]:
-                  lst = range(start, stop, step)
+                  lst = list(range(start, stop, step))
                   expected = []
                   a = start
                   while a > stop:

pypy/tool/pytest/test/test_conftest1.py

 
 import py
+import sys
 
 innertest = py.path.local(__file__).dirpath('conftest1_innertest.py')
 pytest_plugins = "pytester"
         assert "app_test_something" in passed[0].nodeid
         assert "test_method_app" in passed[1].nodeid
 
-    def test_appdirect(self, testdir):
+    def test_runappdirect(self, testdir):
         sorter = testdir.inline_run(innertest, '-k', 'applevel', '--runappdirect')
         passed, skipped, failed = sorter.listoutcomes()
         assert len(passed) == 2
         assert "app_test_something" in passed[0].nodeid
         assert "test_method_app" in passed[1].nodeid
         
+    def test_appdirect(self, testdir):
+        sorter = testdir.inline_run(innertest, '-k', 'applevel',
+                                    '--appdirect=%s' % (sys.executable,))
+        passed, skipped, failed = sorter.listoutcomes()
+        assert len(passed) == 2
+        print passed
+        assert "app_test_something" in passed[0].nodeid
+        assert "test_method_app" in passed[1].nodeid
+