def test_genders(self): name = Name( 'ru', {'genders': { 'm': { 'ru': 'ru_m_name' }, 'f': { 'ru': 'ru_f_name' } }}) self.assertEqual(str(name), 'ru_m_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.RU), 'ru_m_name') self.assertEqual(name.get_for(GENDER.FEMALE, LANGUAGE.RU), 'ru_f_name')
def get_name(self, tables): languages = dict((lang, '') for lang in self.languages) for slug in self.template: record = random.choice(tables[slug]) languages = { lang: self.merge_forms(forms, record['languages'][lang]) for lang, forms in languages.items() } genders = dict((gender, languages) for gender in self.genders) return Name(self.native_language, {'genders': genders})
def test_languages(self): name = Name('ru', {'genders': {'m': {'ru': 'ru_m_name', 'en': 'en_m_name'}, 'f': {'ru': 'ru_f_name', 'en': 'en_f_name'}}}) self.assertEqual(unicode(name), 'ru_m_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.RU), 'ru_m_name') self.assertEqual(name.get_for(GENDER.FEMALE, LANGUAGE.RU), 'ru_f_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.EN), 'en_m_name') self.assertEqual(name.get_for(GENDER.FEMALE, LANGUAGE.EN), 'en_f_name') self.assertEqual(name.get_for(GENDER.MALE), 'ru_m_name') self.assertEqual(name.get_for(GENDER.FEMALE), 'ru_f_name')
def test_languages(self): name = Name( 'ru', { 'genders': { 'm': { 'ru': 'ru_m_name', 'en': 'en_m_name' }, 'f': { 'ru': 'ru_f_name', 'en': 'en_f_name' } } }) self.assertEqual(six.text_type(name), 'ru_m_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.RU), 'ru_m_name') self.assertEqual(name.get_for(GENDER.FEMALE, LANGUAGE.RU), 'ru_f_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.EN), 'en_m_name') self.assertEqual(name.get_for(GENDER.FEMALE, LANGUAGE.EN), 'en_f_name') self.assertEqual(name.get_for(GENDER.MALE), 'ru_m_name') self.assertEqual(name.get_for(GENDER.FEMALE), 'ru_f_name')
def __init__(self): super(FromListGenerator, self).__init__() self.names_list = [] self.choices = {} if self.SOURCE is None: error_msg = 'FromListGenerator: you must make subclass of FromListGenerator and define attribute SOURCE in it.' raise NotImplementedError(error_msg) with open(self.SOURCE, encoding='utf-8') as f: names_data = json.load(f, encoding='utf-8') self.native_language = names_data['native_language'] self.languages = set(names_data['languages']) self.full_forms_for_languages = set(names_data.get('full_forms_for_languages', set())) for name_data in names_data['names']: self.names_list.append(Name(self.native_language, name_data)) if not self.names_list: raise exceptions.NoNamesLoadedFromListError(source=self.SOURCE)
def test_forms(self): name = Name('ru', {'genders': {'m': {'ru': ['form_1', 'form_2']}}}) self.assertEqual(name.get_forms_for(GENDER.MALE), ['form_1', 'form_2'])
def test_base(self): name = Name('ru', {'genders': {'m': {'ru': 'ru_name'}}}) self.assertEqual(str(name), 'ru_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.RU), 'ru_name') self.assertEqual(name.get_for(GENDER.MALE), 'ru_name') self.assertEqual(name.get_forms_for(GENDER.MALE), None)
def test_base(self): name = Name('ru', {'genders': {'m': {'ru': 'ru_name'}}}) self.assertEqual(unicode(name), 'ru_name') self.assertEqual(name.get_for(GENDER.MALE, LANGUAGE.RU), 'ru_name') self.assertEqual(name.get_for(GENDER.MALE), 'ru_name') self.assertEqual(name.get_forms_for(GENDER.MALE), None)