示例#1
0
    def assertRoundtrips(self, bcp47_code, new_bcp47_code=None):
        lc = LanguageCode(bcp47_code, 'bcp47')
        new_bcp47_code = new_bcp47_code or bcp47_code

        self.assertEqual(new_bcp47_code, lc.encode('bcp47'),
                        "BCP47 code '%s' did not round trip to '%s' properly (it encoded to '%s' instead)!"
                         % (bcp47_code, new_bcp47_code, lc.encode('bcp47')))
示例#2
0
    def assertRoundtrips(self, bcp47_code, new_bcp47_code=None):
        lc = LanguageCode(bcp47_code, 'bcp47')
        new_bcp47_code = new_bcp47_code or bcp47_code

        self.assertEqual(
            new_bcp47_code, lc.encode('bcp47'),
            "BCP47 code '%s' did not round trip to '%s' properly (it encoded to '%s' instead)!"
            % (bcp47_code, new_bcp47_code, lc.encode('bcp47')))
示例#3
0
    def test_aliases(self):
        lc = LanguageCode('bm', 'iso-639-1')
        aliases = lc.aliases()

        self.assertIn('iso-639-1', aliases,
                      "Alias not found.")
        self.assertIn('unisubs', aliases,
                      "Alias not found.")

        self.assertEqual('bm', aliases['iso-639-1'],
                         'Incorrect alias.')
        self.assertEqual('bam', aliases['unisubs'],
                         'Incorrect alias.')
示例#4
0
    def test_encode(self):
        lc = LanguageCode('en', 'iso-639-1')

        self.assertEqual('en', lc.encode('iso-639-1'),
                         "Incorrect encoded value.")

        lc = LanguageCode('bm', 'iso-639-1')

        self.assertEqual('bm', lc.encode('iso-639-1'),
                         "Incorrect encoded value.")

        self.assertEqual('bam', lc.encode('unisubs'),
                         "Incorrect encoded value.")
示例#5
0
 def assertEncodesAs(self, unisubs_code, bcp47_code):
     lc = LanguageCode(unisubs_code, 'unisubs')
     self.assertEqual(
         bcp47_code, lc.encode('bcp47'),
         "Unisubs code '%s' did not encode to BCP47 code '%s' (it encoded to '%s' instead)!"
         % (unisubs_code, bcp47_code, lc.encode('bcp47')))
示例#6
0
 def assertLossilyDecodesAs(self, bcp47_code, unilangs_code):
     lc = LanguageCode(bcp47_code, 'bcp47-lossy')
     self.assertEqual(
         unilangs_code, lc.encode('unisubs'),
         "BCP47 code '%s' did not lossily decode to unilangs code '%s'!" %
         (bcp47_code, unilangs_code))
示例#7
0
 def assertDecodesAs(self, bcp47_code, unilangs_code):
     lc = LanguageCode(bcp47_code, 'bcp47')
     self.assertEqual(
         unilangs_code, lc.encode('unisubs'),
         "BCP47 code '%s' did not decode to unilangs code '%s' (it decoded to '%s')!"
         % (bcp47_code, unilangs_code, lc.encode('unisubs')))
示例#8
0
 def assertEncodesAs(self, unisubs_code, bcp47_code):
     lc = LanguageCode(unisubs_code, 'unisubs')
     self.assertEqual(bcp47_code, lc.encode('bcp47'),
                     "Unisubs code '%s' did not encode to BCP47 code '%s' (it encoded to '%s' instead)!"
                      % (unisubs_code, bcp47_code, lc.encode('bcp47')))
示例#9
0
 def assertLossilyDecodesAs(self, bcp47_code, unilangs_code):
     lc = LanguageCode(bcp47_code, 'bcp47-lossy')
     self.assertEqual(unilangs_code, lc.encode('unisubs'),
                      "BCP47 code '%s' did not lossily decode to unilangs code '%s'!"
                      % (bcp47_code, unilangs_code))
示例#10
0
 def assertDecodesAs(self, bcp47_code, unilangs_code):
     lc = LanguageCode(bcp47_code, 'bcp47')
     self.assertEqual(unilangs_code, lc.encode('unisubs'),
                      "BCP47 code '%s' did not decode to unilangs code '%s' (it decoded to '%s')!"
                      % (bcp47_code, unilangs_code, lc.encode('unisubs')))