def test_with_country(self): self.assertTrue( Language('Portuguese (BR)').country == Country('Brazil')) self.assertTrue(Language('pt_BR').country == Country('Brazil')) self.assertTrue(Language('fr - France').country == Country('France')) self.assertTrue( Language('fra', country='FR').country == Country('France')) self.assertTrue( Language('fra', country=Country('FRA')).country == Country( 'France'))
def test_attrs(self): language = Language('French') self.assertTrue(language.alpha2 == 'fr') self.assertTrue(language.alpha3 == 'fre') self.assertTrue(language.terminologic == 'fra') self.assertTrue(language.name == 'French') self.assertTrue(language.french_name == u'français')
def test_external_subtitles(self): results = [ s for s in scan(test_dir)[0][1] if isinstance(s, ExternalSubtitle) ] self.assertTrue(len(results) == 3) for l in ('fre', 'eng', 'und'): self.assertTrue(any([s.language == Language(l) for s in results]))
def test_embedded_subtitles(self): results = [ s for s in scan(test_dir)[0][1] if isinstance(s, EmbeddedSubtitle) ] self.assertTrue(len(results) == 8) for l in ('fre', 'eng', 'ita', 'spa', 'hun', 'ger', 'jpn', 'und'): self.assertTrue(any([s.language == Language(l) for s in results]))
def test_list_index(self): languages = [Language('fr'), Language('en-US'), Language('en-GB')] self.assertTrue(languages.index(Language('fr')) == 0) self.assertTrue(languages.index(Language('en-US')) == 1) self.assertTrue(languages.index(Language('en-GB')) == 2) with self.assertRaises(ValueError): languages.index(Language('fr-BE'))
def test_list_contains(self): languages = list( [Language('fr'), Language('en-US'), Language('en-GB')]) self.assertTrue(Language('fr') in languages) self.assertTrue(Language('en-US') in languages) self.assertTrue(Language('en') not in languages) self.assertTrue(Language('fr-BE') not in languages)
def test_eq(self): language = Language('French') self.assertTrue(language == Language('fr')) self.assertTrue(language == Language('fre')) self.assertTrue(language == Language('fra')) self.assertTrue(language == Language('Français'))
def test_language_set_intersect(self): languages = language_set(['fr', 'en-US', 'en-GB']) self.assertTrue(len(languages & language_set([Language('en')])) == 2) self.assertTrue(len(language_set([Language('en')]) & languages) == 2) self.assertTrue(len(languages & language_set([Language('fr')])) == 1)
def test_language_set_contains(self): languages = language_set(['fr', 'en-US', 'en-GB']) self.assertTrue(Language('fr') in languages) self.assertTrue(Language('en-US') in languages) self.assertTrue(Language('en') not in languages) self.assertTrue(Language('fr-BE') in languages)
def test_language_list_index(self): languages = language_list(['fr', 'en-US', 'en-GB']) self.assertTrue(languages.index(Language('fr')) == 0) self.assertTrue(languages.index(Language('en-US')) == 1) self.assertTrue(languages.index(Language('en-GB')) == 2) self.assertTrue(languages.index(Language('fr-BE')) == 0)
def test_missing(self): with self.assertRaises(ValueError): Language('zzz')
def test_hash(self): self.assertTrue(hash(Language('French')) == hash('fre'))
def test_ne_with_country(self): self.assertTrue(Language('Portuguese') != Language('Portuguese (BR)')) self.assertTrue(Language('English (US)') != Language('English (GB)'))
def test_eq_with_country(self): self.assertTrue( Language('Portuguese (BR)') == Language('Portuguese - Brazil')) self.assertTrue(Language('English') == Language('en'))
def test_in(self): self.assertTrue( Language('Portuguese (BR)') in Language('Portuguese - Brazil')) self.assertTrue(Language('Portuguese (BR)') in Language('Portuguese')) self.assertTrue( Language('Portuguese') not in Language('Portuguese (BR)'))
def test_ne(self): self.assertTrue(Language('French') != Language('en'))