Modify examples to be both Python 2 and 3 compatible
For removing dependency on 2to3
This commit is contained in:
parent
2af35cb4ff
commit
89bee6a7fa
37 changed files with 368 additions and 388 deletions
|
|
@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
print(" Finished importing py2.pkg2")
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py2.pkg2.foo"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
print(" Finished importing py3.pkg2")
|
||||
# commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
# run_except_on_windows(commandline)
|
||||
# commandline = sys.executable + " -m py3.pkg2.foo"
|
||||
|
|
|
|||
|
|
@ -6,24 +6,24 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
print(" Finished importing py2.pkg2")
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
print(" Finished importing py3.pkg2")
|
||||
# commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
# run_except_on_windows(commandline)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,24 +6,24 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2
|
||||
print " Finished importing py2.pkg2"
|
||||
print(" Finished importing py2.pkg2")
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2
|
||||
print " Finished importing py3.pkg2"
|
||||
print(" Finished importing py3.pkg2")
|
||||
# commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
# run_except_on_windows(commandline)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ import sys
|
|||
|
||||
# Test import of a SWIG generated module renamed as the package's __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - module renamed as __init__.py"
|
||||
print("Testing " + testname + " - module renamed as __init__.py")
|
||||
|
||||
if sys.version_info >= (3, 0, 0) and sys.version_info < (3, 3, 0):
|
||||
print " Not importing as Python version is >= 3.0 and < 3.3"
|
||||
print(" Not importing as Python version is >= 3.0 and < 3.3")
|
||||
# Package detection does not work in these versions.
|
||||
# Can be fixed by using this in the interface file:
|
||||
# %module(moduleimport="from . import $module") foo # without -builtin
|
||||
|
|
@ -14,7 +14,7 @@ if sys.version_info >= (3, 0, 0) and sys.version_info < (3, 3, 0):
|
|||
sys.exit(0)
|
||||
|
||||
import pkg1
|
||||
print " Finished importing pkg1"
|
||||
print(" Finished importing pkg1")
|
||||
|
||||
if pkg1.foofunction(123) != 1230:
|
||||
raise RuntimeError("foofunction failed")
|
||||
|
|
@ -23,4 +23,4 @@ fc = pkg1.FooClass()
|
|||
if fc.foomethod(1) != 6:
|
||||
raise RuntimeError("foomethod failed")
|
||||
|
||||
print " Finished testing pkg1"
|
||||
print(" Finished testing pkg1")
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ import subprocess
|
|||
import sys
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - namespace packages"
|
||||
print("Testing " + testname + " - namespace packages")
|
||||
|
||||
if sys.version_info < (3, 3, 0):
|
||||
print " Not importing nstest as Python version is < 3.3"
|
||||
print(" Not importing nstest as Python version is < 3.3")
|
||||
sys.exit(0)
|
||||
|
||||
import nstest
|
||||
|
||||
print " Finished importing nstest"
|
||||
print(" Finished importing nstest")
|
||||
|
||||
nstest.main()
|
||||
|
|
|
|||
|
|
@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) with -relativeimport"
|
||||
print("Testing " + testname + " - %module(package=...) with -relativeimport")
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2.bar
|
||||
print " Finished importing py2.pkg2.bar"
|
||||
print(" Finished importing py2.pkg2.bar")
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py2.pkg2.pkg3.foo"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2.bar
|
||||
print " Finished importing py3.pkg2.bar"
|
||||
print(" Finished importing py3.pkg2.bar")
|
||||
commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py3.pkg2.pkg3.foo"
|
||||
|
|
|
|||
|
|
@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2.bar
|
||||
print " Finished importing py2.pkg2.bar"
|
||||
print(" Finished importing py2.pkg2.bar")
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py2.pkg2.pkg3.pkg4.foo"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2.bar
|
||||
print " Finished importing py3.pkg2.bar"
|
||||
print(" Finished importing py3.pkg2.bar")
|
||||
commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py3.pkg2.pkg3.pkg4.foo"
|
||||
|
|
|
|||
|
|
@ -6,26 +6,26 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of modules content from within __init__.py
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) with -relativeimport"
|
||||
print("Testing " + testname + " - %module(package=...) with -relativeimport")
|
||||
|
||||
if sys.version_info < (2, 5):
|
||||
print " Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'"
|
||||
print(" Skipping test as Python version is < 2.5 and does not support relative import syntax: 'from . import x'")
|
||||
sys.exit(0)
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
import py2.pkg2.bar
|
||||
print " Finished importing py2.pkg2.bar"
|
||||
print(" Finished importing py2.pkg2.bar")
|
||||
commandline = sys.executable + " -m py2.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py2.pkg2.pkg3.foo"
|
||||
run_except_on_windows(commandline)
|
||||
else:
|
||||
import py3.pkg2.bar
|
||||
print " Finished importing py3.pkg2.bar"
|
||||
print(" Finished importing py3.pkg2.bar")
|
||||
commandline = sys.executable + " -m py3.pkg2.bar"
|
||||
run_except_on_windows(commandline)
|
||||
commandline = sys.executable + " -m py3.pkg2.pkg3.foo"
|
||||
|
|
|
|||
|
|
@ -6,21 +6,21 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
# Test import of same modules from different packages
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
|
||||
|
||||
import pkg2.foo
|
||||
print " Finished importing pkg2.foo"
|
||||
print(" Finished importing pkg2.foo")
|
||||
|
||||
var2 = pkg2.foo.Pkg2_Foo()
|
||||
|
||||
classname = str(type(var2))
|
||||
if classname.find("pkg2.foo.Pkg2_Foo") == -1:
|
||||
raise RuntimeError("failed type checking: " + classname)
|
||||
print " Successfully created object pkg2.foo.Pkg2_Foo"
|
||||
print(" Successfully created object pkg2.foo.Pkg2_Foo")
|
||||
|
||||
commandline = sys.executable + " -m pkg2.foo"
|
||||
run_except_on_windows(commandline)
|
||||
|
|
|
|||
|
|
@ -6,20 +6,20 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - %module(package=...) + python 'import' in __init__.py"
|
||||
print("Testing " + testname + " - %module(package=...) + python 'import' in __init__.py")
|
||||
|
||||
import pkg1.pkg2.foo
|
||||
print " Finished importing pkg1.pkg2.foo"
|
||||
print(" Finished importing pkg1.pkg2.foo")
|
||||
|
||||
var2 = pkg1.pkg2.foo.Pkg2_Foo()
|
||||
|
||||
classname = str(type(var2))
|
||||
if classname.find("pkg1.pkg2.foo.Pkg2_Foo") == -1:
|
||||
raise RuntimeError("failed type checking: " + classname)
|
||||
print " Successfully created object pkg1.pkg2.foo.Pkg2_Foo"
|
||||
print(" Successfully created object pkg1.pkg2.foo.Pkg2_Foo")
|
||||
|
||||
commandline = sys.executable + " -m pkg1.pkg2.foo"
|
||||
run_except_on_windows(commandline)
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - split modules"
|
||||
print("Testing " + testname + " - split modules")
|
||||
|
||||
import pkg1.foo
|
||||
|
||||
print " Finished importing pkg1.foo"
|
||||
print(" Finished importing pkg1.foo")
|
||||
|
||||
if not(pkg1.foo.count() == 3):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ def run_except_on_windows(commandline, env=None):
|
|||
if os.name != "nt" and sys.platform != "cygwin":
|
||||
# Strange failures on windows/cygin/mingw
|
||||
subprocess.check_call(commandline, env=env, shell=True)
|
||||
print(" Finished running: " + commandline)
|
||||
print((" Finished running: " + commandline))
|
||||
|
||||
testname = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
|
||||
print "Testing " + testname + " - split modules"
|
||||
print("Testing " + testname + " - split modules")
|
||||
|
||||
import pkg1.foo
|
||||
|
||||
print " Finished importing pkg1.foo"
|
||||
print(" Finished importing pkg1.foo")
|
||||
|
||||
if not(pkg1.foo.count() == 3):
|
||||
raise RuntimeError("test failed")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue