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')))
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')))
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.')
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.")
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')))
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))
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')))
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')))
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))
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')))