diff options
| author | Marc-André Lemburg <mal@egenix.com> | 2001-01-17 17:09:53 +0000 |
|---|---|---|
| committer | Marc-André Lemburg <mal@egenix.com> | 2001-01-17 17:09:53 +0000 |
| commit | 3598f0c3abe6b488d7ee3ce78884f150c1414a4c (patch) | |
| tree | a62a61c3c350419c1c53aaa86dba61368f52a5ed /Lib | |
| parent | 4c68833a3423650b8dc8d69eec5f5b572f5cf80f (diff) | |
| download | cpython-3598f0c3abe6b488d7ee3ce78884f150c1414a4c.tar.gz | |
This patch adds a new builtin unistr() which behaves like str()
except that it always returns Unicode objects.
A new C API PyObject_Unicode() is also provided.
This closes patch #101664.
Written by Marc-Andre Lemburg. Copyright assigned to Guido van Rossum.
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/output/test_builtin | 1 | ||||
| -rw-r--r-- | Lib/test/test_b2.py | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/output/test_builtin b/Lib/test/output/test_builtin index 1c3b69c838..29c6f862f9 100644 --- a/Lib/test/output/test_builtin +++ b/Lib/test/output/test_builtin @@ -45,6 +45,7 @@ repr round setattr str +unistr tuple type vars diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py index 5546d8a562..9871652171 100644 --- a/Lib/test/test_b2.py +++ b/Lib/test/test_b2.py @@ -214,6 +214,17 @@ if str(()) != '()': raise TestFailed, 'str(())' if str([]) != '[]': raise TestFailed, 'str([])' if str({}) != '{}': raise TestFailed, 'str({})' +print 'unistr' +if unistr('') <> u'': raise TestFailed, 'unistr(\'\')' +if unistr('a') <> u'a': raise TestFailed, 'unistr(\'a\')' +if unistr(u'') <> u'': raise TestFailed, 'unistr(u\'\')' +if unistr(u'a') <> u'a': raise TestFailed, 'unistr(u\'a\')' +if unistr(0) <> u'0': raise TestFailed, 'unistr(0)' +if unistr(0L) <> u'0': raise TestFailed, 'unistr(0L)' +if unistr(()) <> u'()': raise TestFailed, 'unistr(())' +if unistr([]) <> u'[]': raise TestFailed, 'unistr([])' +if unistr({}) <> u'{}': raise TestFailed, 'unistr({})' + print 'tuple' if tuple(()) != (): raise TestFailed, 'tuple(())' if tuple((0, 1, 2, 3)) != (0, 1, 2, 3): raise TestFailed, 'tuple((0, 1, 2, 3))' |
