Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes | Private Member Functions
test.test_multibytecodec_support.TestBase_Mapping Class Reference
Inheritance diagram for test.test_multibytecodec_support.TestBase_Mapping:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def open_mapping_file
def test_mapping_file
def test_mapping_supplemental
def test_errorhandle

Static Public Attributes

list pass_enctest = []
list pass_dectest = []
list supmaps = []
list codectests = []

Private Member Functions

def _test_mapping_file_plain
def _test_mapping_file_ucm
def _testpoint

Detailed Description

Definition at line 283 of file test_multibytecodec_support.py.


Constructor & Destructor Documentation

Definition at line 289 of file test_multibytecodec_support.py.

00289 
00290     def __init__(self, *args, **kw):
00291         unittest.TestCase.__init__(self, *args, **kw)
00292         try:
00293             self.open_mapping_file().close() # test it to report the error early
00294         except (IOError, HTTPException):
00295             self.skipTest("Could not retrieve "+self.mapfileurl)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

Definition at line 305 of file test_multibytecodec_support.py.

00305 
00306     def _test_mapping_file_plain(self):
00307         unichrs = lambda s: ''.join(map(chr, map(eval, s.split('+'))))
00308         urt_wa = {}
00309 
00310         with self.open_mapping_file() as f:
00311             for line in f:
00312                 if not line:
00313                     break
00314                 data = line.split('#')[0].strip().split()
00315                 if len(data) != 2:
00316                     continue
00317 
00318                 csetval = eval(data[0])
00319                 if csetval <= 0x7F:
00320                     csetch = bytes([csetval & 0xff])
00321                 elif csetval >= 0x1000000:
00322                     csetch = bytes([(csetval >> 24), ((csetval >> 16) & 0xff),
00323                                     ((csetval >> 8) & 0xff), (csetval & 0xff)])
00324                 elif csetval >= 0x10000:
00325                     csetch = bytes([(csetval >> 16), ((csetval >> 8) & 0xff),
00326                                     (csetval & 0xff)])
00327                 elif csetval >= 0x100:
00328                     csetch = bytes([(csetval >> 8), (csetval & 0xff)])
00329                 else:
00330                     continue
00331 
00332                 unich = unichrs(data[1])
00333                 if ord(unich) == 0xfffd or unich in urt_wa:
00334                     continue
00335                 urt_wa[unich] = csetch
00336 
00337                 self._testpoint(csetch, unich)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 338 of file test_multibytecodec_support.py.

00338 
00339     def _test_mapping_file_ucm(self):
00340         with self.open_mapping_file() as f:
00341             ucmdata = f.read()
00342         uc = re.findall('<a u="([A-F0-9]{4})" b="([0-9A-F ]+)"/>', ucmdata)
00343         for uni, coded in uc:
00344             unich = chr(int(uni, 16))
00345             codech = bytes(int(c, 16) for c in coded.split())
00346             self._testpoint(codech, unich)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_multibytecodec_support.TestBase_Mapping._testpoint (   self,
  csetch,
  unich 
) [private]

Definition at line 351 of file test_multibytecodec_support.py.

00351 
00352     def _testpoint(self, csetch, unich):
00353         if (csetch, unich) not in self.pass_enctest:
00354             self.assertEqual(unich.encode(self.encoding), csetch)
00355         if (csetch, unich) not in self.pass_dectest:
00356             self.assertEqual(str(csetch, self.encoding), unich)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 296 of file test_multibytecodec_support.py.

00296 
00297     def open_mapping_file(self):
00298         return support.open_urlresource(self.mapfileurl)

Here is the caller graph for this function:

Definition at line 357 of file test_multibytecodec_support.py.

00357 
00358     def test_errorhandle(self):
00359         for source, scheme, expected in self.codectests:
00360             if isinstance(source, bytes):
00361                 func = source.decode
00362             else:
00363                 func = source.encode
00364             if expected:
00365                 if isinstance(source, bytes):
00366                     result = func(self.encoding, scheme)
00367                     self.assertTrue(type(result) is str, type(result))
00368                     self.assertEqual(result, expected,
00369                                      '%a.decode(%r, %r)=%a != %a'
00370                                      % (source, self.encoding, scheme, result,
00371                                         expected))
00372                 else:
00373                     result = func(self.encoding, scheme)
00374                     self.assertTrue(type(result) is bytes, type(result))
00375                     self.assertEqual(result, expected,
00376                                      '%a.encode(%r, %r)=%a != %a'
00377                                      % (source, self.encoding, scheme, result,
00378                                         expected))
00379             else:
00380                 self.assertRaises(UnicodeError, func, self.encoding, scheme)

Here is the call graph for this function:

Definition at line 299 of file test_multibytecodec_support.py.

00299 
00300     def test_mapping_file(self):
00301         if self.mapfileurl.endswith('.xml'):
00302             self._test_mapping_file_ucm()
00303         else:
00304             self._test_mapping_file_plain()

Here is the call graph for this function:

Definition at line 347 of file test_multibytecodec_support.py.

00347 
00348     def test_mapping_supplemental(self):
00349         for mapping in self.supmaps:
00350             self._testpoint(*mapping)

Here is the call graph for this function:


Member Data Documentation

Definition at line 287 of file test_multibytecodec_support.py.

Reimplemented in test.test_codecmaps_jp.TestCP932Map.

Definition at line 286 of file test_multibytecodec_support.py.


The documentation for this class was generated from the following file: