Skip to content

Commit ca9c6f0

Browse files
committed
GSM encoding, change the tests to follow the TS23.038 spec exactly
1 parent 1826f54 commit ca9c6f0

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

messaging/test/test_gsm_encoding.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
u'ù': (0x00f9, 0x06),
3333
u'ì': (0x00ec, 0x07),
3434
u'ò': (0x00f2, 0x08),
35-
u'ç': (0x00e7, 0x09),
35+
u'Ç': (0x00c7, 0x09), # LATIN CAPITAL LETTER C WITH CEDILLA
3636
unichr(0x000a): (0x000a, 0x0a), # Linefeed
3737
u'Ø': (0x00d8, 0x0b),
3838
u'ø': (0x00f8, 0x0c),
@@ -183,7 +183,7 @@
183183
}
184184

185185
QUIRK_MAP = {
186-
u'Ç': (0x00c7, 0x09), # LATIN CAPITAL LETTER C WITH CEDILLA
186+
u'ç': (0x00e7, 0x09),
187187
}
188188

189189
BAD = -1
@@ -214,8 +214,8 @@ def test_encoding_supported_greek_unicode_gsm(self):
214214
# Note: Conversion is one way, hence no corresponding decode test
215215

216216
for key in GREEK_MAP.keys():
217-
# Use 'ignore' so that we see the code tested, not an exception
218-
s_gsm = key.encode('gsm0338', 'ignore')
217+
# Use 'replace' so that we trigger the mapping
218+
s_gsm = key.encode('gsm0338', 'replace')
219219

220220
if len(s_gsm) == 1:
221221
i_gsm = ord(s_gsm)
@@ -228,8 +228,8 @@ def test_encoding_supported_quirk_unicode_gsm(self):
228228
# Note: Conversion is one way, hence no corresponding decode test
229229

230230
for key in QUIRK_MAP.keys():
231-
# Use 'ignore' so that we see the code tested, not an exception
232-
s_gsm = key.encode('gsm0338', 'ignore')
231+
# Use 'replace' so that we trigger the mapping
232+
s_gsm = key.encode('gsm0338', 'replace')
233233

234234
if len(s_gsm) == 1:
235235
i_gsm = ord(s_gsm)
@@ -251,21 +251,17 @@ def test_decoding_supported_unicode_gsm(self):
251251
self.assertEqual(MAP[key][0], ord(s_unicode))
252252

253253
def test_is_gsm_text_true(self):
254-
_MAP = dict(MAP.items() + GREEK_MAP.items() + QUIRK_MAP.items())
255-
256-
for key in _MAP.keys():
254+
for key in MAP.keys():
257255
if key == unichr(0x00a0):
258256
continue
259257
self.assertEqual(messaging.sms.gsm0338.is_gsm_text(key), True)
260258

261259
def test_is_gsm_text_false(self):
262-
_MAP = dict(MAP.items() + GREEK_MAP.items() + QUIRK_MAP.items())
263-
264260
self.assertEqual(
265261
messaging.sms.gsm0338.is_gsm_text(unichr(0x00a0)), False)
266262

267263
for i in xrange(1, 0xffff + 1):
268-
if unichr(i) not in _MAP:
264+
if unichr(i) not in MAP:
269265
# Note: it's a little odd, but on error we want to see values
270266
if messaging.sms.gsm0338.is_gsm_text(unichr(i)) is not False:
271267
self.assertEqual(BAD, i)

0 commit comments

Comments
 (0)