summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2020-08-15 00:09:31 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2020-08-15 00:09:31 +0100
commit66df0bd2242b04125bc008142de749b962991675 (patch)
tree033f0da80d004beeb646a720450da371230133e6
parent36bb54f01d0b5a0fef4c3843b366b5d78b8c04bb (diff)
downloadswig-66df0bd2242b04125bc008142de749b962991675.tar.gz
Convert python test scripts to be Python 2 and 3 compatible
Unicode testing
-rw-r--r--Examples/test-suite/python/director_wstring_runme.py8
-rw-r--r--Examples/test-suite/python/li_cwstring_runme.py18
-rw-r--r--Examples/test-suite/python/li_std_wstream_runme.py2
-rw-r--r--Examples/test-suite/python/li_std_wstring_inherit_runme.py10
-rw-r--r--Examples/test-suite/python/li_std_wstring_runme.py6
-rw-r--r--Examples/test-suite/python/unicode_strings_runme.py14
6 files changed, 28 insertions, 30 deletions
diff --git a/Examples/test-suite/python/director_wstring_runme.py b/Examples/test-suite/python/director_wstring_runme.py
index b6e25f4d5..5facc1f1d 100644
--- a/Examples/test-suite/python/director_wstring_runme.py
+++ b/Examples/test-suite/python/director_wstring_runme.py
@@ -7,20 +7,20 @@ class B(A):
A.__init__(self, string)
def get_first(self):
- return A.get_first(self) + u" world!"
+ return A.get_first(self) + " world!"
def process_text(self, s):
self.smem = s
-b = B(u"hello")
+b = B("hello")
b.get(0)
-if b.get_first() != u"hello world!":
+if b.get_first() != "hello world!":
raise RuntimeError("b.get_first(): {}".format(b.get_first()))
b.call_process_func()
-if b.smem != u"hello":
+if b.smem != "hello":
raise RuntimeError("smem: {}".format(smem))
diff --git a/Examples/test-suite/python/li_cwstring_runme.py b/Examples/test-suite/python/li_cwstring_runme.py
index 5dd7b9b20..9216445c6 100644
--- a/Examples/test-suite/python/li_cwstring_runme.py
+++ b/Examples/test-suite/python/li_cwstring_runme.py
@@ -1,28 +1,28 @@
from li_cwstring import *
-if count(u"ab\0ab\0ab\0", 0) != 3:
+if count("ab\0ab\0ab\0", 0) != 3:
raise RuntimeError
-if test1() != u"Hello World":
+if test1() != "Hello World":
raise RuntimeError
-if test2() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
+if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
raise RuntimeError
-if test3("hello") != u"hello-suffix":
+if test3("hello") != "hello-suffix":
raise RuntimeError
-if test4("hello") != u"hello-suffix":
+if test4("hello") != "hello-suffix":
raise RuntimeError
-if test5(4) != u"xxxx":
+if test5(4) != "xxxx":
raise RuntimeError
-if test6(10) != u"xxxxx":
+if test6(10) != "xxxxx":
raise RuntimeError
-if test7() != u"Hello world!":
+if test7() != "Hello world!":
raise RuntimeError
-if test8() != u" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
+if test8() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_":
raise RuntimeError
diff --git a/Examples/test-suite/python/li_std_wstream_runme.py b/Examples/test-suite/python/li_std_wstream_runme.py
index a83561a84..0ecdddbf8 100644
--- a/Examples/test-suite/python/li_std_wstream_runme.py
+++ b/Examples/test-suite/python/li_std_wstream_runme.py
@@ -5,7 +5,7 @@ a = A()
o = wostringstream()
-o << a << u" " << 2345 << u" " << 1.435 << wends
+o << a << " " << 2345 << " " << 1.435 << wends
if o.str() != "A class 2345 1.435\0":
raise RuntimeError("str failed: \"%s\"".format(o.str()))
diff --git a/Examples/test-suite/python/li_std_wstring_inherit_runme.py b/Examples/test-suite/python/li_std_wstring_inherit_runme.py
index 5a8569a6f..bd585890c 100644
--- a/Examples/test-suite/python/li_std_wstring_inherit_runme.py
+++ b/Examples/test-suite/python/li_std_wstring_inherit_runme.py
@@ -1,10 +1,10 @@
import li_std_wstring_inherit
import sys
-x = u"hello"
+x = "hello"
-s = li_std_wstring_inherit.wstring(u"he")
-s = s + u"llo"
+s = li_std_wstring_inherit.wstring("he")
+s = s + "llo"
if s != x:
raise RuntimeError("bad string mapping {} {}".format(s, x))
@@ -33,12 +33,12 @@ if not li_std_wstring_inherit.is_python_builtin():
b = li_std_wstring_inherit.B("hi")
-b.name = li_std_wstring_inherit.wstring(u"hello")
+b.name = li_std_wstring_inherit.wstring("hello")
if b.name != "hello":
raise RuntimeError("bad string mapping")
b.a = li_std_wstring_inherit.A("hello")
-if b.a != u"hello":
+if b.a != "hello":
raise RuntimeError("bad string mapping")
diff --git a/Examples/test-suite/python/li_std_wstring_runme.py b/Examples/test-suite/python/li_std_wstring_runme.py
index c6210e2de..ef2085c66 100644
--- a/Examples/test-suite/python/li_std_wstring_runme.py
+++ b/Examples/test-suite/python/li_std_wstring_runme.py
@@ -5,10 +5,10 @@ def check_equal(a, b):
if a != b:
raise RuntimeError("failed {} {}".format(a, b))
-h = u"h"
+h = "h"
check_equal(li_std_wstring.test_wcvalue(h), h)
-x = u"abc"
+x = "abc"
check_equal(li_std_wstring.test_ccvalue(x), x)
check_equal(li_std_wstring.test_cvalue(x), x)
@@ -72,7 +72,7 @@ except TypeError:
# Check surrogateescape
if sys.version_info[0:2] > (3, 1):
- x = u"h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo"
+ x = "h\udce9llo" # surrogate escaped representation of C char*: "h\xe9llo"
if li_std_wstring.non_utf8_c_str() != x:
raise RuntimeError("surrogateescape not working")
if li_std_wstring.size_wstring(x) != 5 and len(x) != 5:
diff --git a/Examples/test-suite/python/unicode_strings_runme.py b/Examples/test-suite/python/unicode_strings_runme.py
index 4e661f00e..108d0d2c9 100644
--- a/Examples/test-suite/python/unicode_strings_runme.py
+++ b/Examples/test-suite/python/unicode_strings_runme.py
@@ -2,12 +2,8 @@ import sys
import unicode_strings
-# The 'u' string prefix isn't valid in Python 3.0 - 3.2 and is redundant
-# in 3.3+. Since this file is run through 2to3 before testing, though,
-# mark this as a unicode string in 2.x so it'll become a str in 3.x.
-test_string = u"h\udce9llo w\u00f6rld"
-
if sys.version_info[0:2] >= (3, 1):
+ test_string = "h\udce9llo w\u00f6rld"
if unicode_strings.non_utf8_c_str() != test_string:
raise ValueError("Test comparison mismatch")
if unicode_strings.non_utf8_std_string() != test_string:
@@ -22,15 +18,17 @@ if sys.version_info[0:2] < (3, 0):
check(unicode_strings.charstring("hello1"), "hello1")
check(unicode_strings.charstring(str(u"hello2")), "hello2")
check(unicode_strings.charstring(u"hello3"), "hello3")
- check(unicode_strings.charstring(unicode("hello4")), "hello4")
+ check(unicode_strings.charstring(str("hello4")), "hello4")
unicode_strings.charstring(u"hell\xb05")
unicode_strings.charstring(u"hell\u00f66")
+ low_surrogate_string = u"\udcff"
+else:
+ low_surrogate_string = "\udcff"
-low_surrogate_string = u"\udcff"
try:
unicode_strings.instring(low_surrogate_string)
# Will succeed with Python 2
-except TypeError, e:
+except TypeError as e:
# Python 3 will fail the PyUnicode_AsUTF8String conversion resulting in a TypeError.
# The real error is actually:
# UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed