|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# --- BEGIN_HEADER --- |
| 4 | +# |
| 5 | +# test_mig_shared_compat - unit test of the corresponding mig shared module |
| 6 | +# Copyright (C) 2003-2024 The MiG Project by the Science HPC Center at UCPH |
| 7 | +# |
| 8 | +# This file is part of MiG. |
| 9 | +# |
| 10 | +# MiG is free software: you can redistribute it and/or modify |
| 11 | +# it under the terms of the GNU General Public License as published by |
| 12 | +# the Free Software Foundation; either version 2 of the License, or |
| 13 | +# (at your option) any later version. |
| 14 | +# |
| 15 | +# MiG is distributed in the hope that it will be useful, |
| 16 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +# GNU General Public License for more details. |
| 19 | +# |
| 20 | +# You should have received a copy of the GNU General Public License |
| 21 | +# along with this program; if not, write to the Free Software |
| 22 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
| 23 | +# USA. |
| 24 | +# |
| 25 | +# --- END_HEADER --- |
| 26 | +# |
| 27 | + |
| 28 | +"""Unit tests for the migrid module pointed to in the filename""" |
| 29 | + |
| 30 | +import binascii |
| 31 | +import os |
| 32 | +import sys |
| 33 | + |
| 34 | +from tests.support import PY2, MigTestCase, testmain |
| 35 | + |
| 36 | +from mig.shared.base import force_default_fs_coding_rec, force_default_str_coding_rec |
| 37 | + |
| 38 | +DUMMY_BYTECHARS = b'DEADBEEF' |
| 39 | +DUMMY_BYTESRAW = binascii.unhexlify('DEADBEEF') # 4 bytes |
| 40 | +DUMMY_UNICODE = u'UniCode123½¾µßðþđŋħĸþł@ª€£$¥©®' |
| 41 | + |
| 42 | + |
| 43 | +if PY2: |
| 44 | + def _strbytes(value): |
| 45 | + assert isinstance(value, str) |
| 46 | + return value |
| 47 | +else: |
| 48 | + def _strbytes(value): |
| 49 | + assert isinstance(value, str) |
| 50 | + return bytes(value, 'utf8') |
| 51 | + |
| 52 | + |
| 53 | +class MigSharedBase__force_default_fs_coding_rec(MigTestCase): |
| 54 | + """Unit tests of mig.shared.base force_default_fs_coding_rec()""" |
| 55 | + |
| 56 | + def test_encode_a_string(self): |
| 57 | + output = force_default_fs_coding_rec('foobar') |
| 58 | + |
| 59 | + self.assertEqual(output, _strbytes('foobar')) |
| 60 | + |
| 61 | + def test_encode_within_a_dict(self): |
| 62 | + output = force_default_fs_coding_rec({ 'key': 'value' }) |
| 63 | + |
| 64 | + self.assertEqual(output, { _strbytes('key'): _strbytes('value') }) |
| 65 | + |
| 66 | + def test_encode_within_a_list(self): |
| 67 | + output = force_default_fs_coding_rec(['foo', 'bar', 'baz']) |
| 68 | + |
| 69 | + self.assertEqual(output, [_strbytes('foo'), _strbytes('bar'), _strbytes('baz')]) |
| 70 | + |
| 71 | + def test_encode_within_a_tuple(self): |
| 72 | + output = force_default_fs_coding_rec(('foo', 'bar', 'baz')) |
| 73 | + |
| 74 | + self.assertEqual(output, (_strbytes('foo'), _strbytes('bar'), _strbytes('baz'))) |
| 75 | + |
| 76 | + |
| 77 | +class MigSharedBase__force_default_str_coding_rec(MigTestCase): |
| 78 | + """Unit tests of mig.shared.base force_default_str_coding_rec()""" |
| 79 | + |
| 80 | + def test_encode_a_string(self): |
| 81 | + output = force_default_str_coding_rec('foobar') |
| 82 | + |
| 83 | + self.assertEqual(output, 'foobar') |
| 84 | + |
| 85 | + def test_encode_within_a_dict(self): |
| 86 | + output = force_default_str_coding_rec({ 'key': 'value' }) |
| 87 | + |
| 88 | + self.assertEqual(output, { 'key': 'value' }) |
| 89 | + |
| 90 | + def test_encode_within_a_list(self): |
| 91 | + output = force_default_str_coding_rec(['foo', 'bar', 'baz']) |
| 92 | + |
| 93 | + self.assertEqual(output, ['foo', 'bar', 'baz']) |
| 94 | + |
| 95 | + def test_encode_within_a_tuple(self): |
| 96 | + output = force_default_str_coding_rec(('foo', 'bar', 'baz')) |
| 97 | + |
| 98 | + self.assertEqual(output, ('foo', 'bar', 'baz')) |
| 99 | + |
| 100 | + |
| 101 | +if __name__ == '__main__': |
| 102 | + testmain() |
0 commit comments