|
19 | 19 | #
|
20 | 20 | # You should have received a copy of the GNU General Public License
|
21 | 21 | # along with this program; if not, write to the Free Software
|
22 |
| -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 22 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 23 | +# USA. |
23 | 24 | #
|
24 |
| -# -- END_HEADER --- |
| 25 | +# --- END_HEADER --- |
25 | 26 | #
|
26 | 27 |
|
27 |
| -"""Unit test compat functions""" |
| 28 | +"""Unit tests for the migrid module pointed to in the filename""" |
28 | 29 |
|
29 | 30 | import binascii
|
30 | 31 | import os
|
|
33 | 34 | sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), ".")))
|
34 | 35 | from support import MigTestCase, testmain
|
35 | 36 |
|
36 |
| -from mig.shared.compat import ensure_native_string |
| 37 | +from mig.shared.compat import PY2, ensure_native_string |
37 | 38 |
|
38 | 39 | DUMMY_BYTECHARS = b'DEADBEEF'
|
39 | 40 | DUMMY_BYTESRAW = binascii.unhexlify('DEADBEEF') # 4 bytes
|
| 41 | +DUMMY_UNICODE = u'UniCode123½¾µßðþđŋħĸþł@ª€£$¥©®' |
40 | 42 |
|
41 | 43 | class MigSharedCompat__ensure_native_string(MigTestCase):
|
42 |
| - # TODO: Add docstrings to this class and its methods |
| 44 | + """Unit test helper for the migrid code pointed to in class name""" |
| 45 | + |
43 | 46 | def test_char_bytes_conversion(self):
|
44 | 47 | actual = ensure_native_string(DUMMY_BYTECHARS)
|
| 48 | + self.assertIs(type(actual), str) |
45 | 49 | self.assertEqual(actual, 'DEADBEEF')
|
46 | 50 |
|
47 | 51 | def test_raw_bytes_conversion(self):
|
48 | 52 | with self.assertRaises(UnicodeDecodeError):
|
49 | 53 | ensure_native_string(DUMMY_BYTESRAW)
|
50 | 54 |
|
| 55 | + def test_unicode_conversion(self): |
| 56 | + actual = ensure_native_string(DUMMY_UNICODE) |
| 57 | + self.assertEqual(type(actual), str) |
| 58 | + if PY2: |
| 59 | + self.assertEqual(actual, DUMMY_UNICODE.encode("utf8")) |
| 60 | + else: |
| 61 | + self.assertEqual(actual, DUMMY_UNICODE) |
| 62 | + |
51 | 63 |
|
52 | 64 | if __name__ == '__main__':
|
53 | 65 | testmain()
|
0 commit comments