Marc Abramowitz avatar Marc Abramowitz committed 77164fe

Add test for scripttest.backwardscompat.string

Refs https://bitbucket.org/ianb/scripttest/issue/9/

Comments (0)

Files changed (1)

tests/test_string.py

+import sys
+
+from scripttest.backwardscompat import string
+from nose.plugins.skip import SkipTest
+
+
+ascii_str = ''.join([
+    'This is just some plain ol\' ASCII text with none of those ',
+    'funny "Unicode" characters.\n\nJust good ol\' ASCII text.',
+])
+
+ascii_unicode = u''.join([
+    u'This is a "degenerate" unicode string with just ASCII characters',
+])
+
+utf8_str = ''.join([
+    'Bj\xc3\xb6rk Gu\xc3\xb0mundsd\xc3\xb3ttir ',
+    '[\xcb\x88pj\xc5\x93r\xcc\xa5k ', 
+    '\xcb\x88kv\xca\x8f\xc3\xb0m\xca\x8fnts\xcb\x8cto\xca\x8aht\xc9\xaar]',
+])
+
+
+def skip_test_if_not_python_2():
+    if sys.version_info.major != 2:
+        raise SkipTest
+
+
+def skip_test_if_not_python_3():
+    if sys.version_info.major != 3:
+        raise SkipTest
+
+
+def test_python_2_string_with_ascii_str():
+    skip_test_if_not_python_2()
+
+    assert string(ascii_str) == ascii_str
+
+
+def test_python_2_string_with_utf8_str():
+    skip_test_if_not_python_2()
+
+    assert string(utf8_str) == utf8_str.decode('utf-8')
+
+
+def test_python_2_string_with_ascii_unicode():
+    skip_test_if_not_python_2()
+
+    assert string(ascii_unicode) == ascii_unicode
+
+
+def test_python_2_string_with_utf8_unicode():
+    skip_test_if_not_python_2()
+
+    utf8_unicode = utf8_str.decode('utf-8')
+
+    assert string(utf8_unicode) == utf8_unicode
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.