Ejemplo n.º 1
0
 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')
Ejemplo n.º 2
0
    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})
Ejemplo n.º 3
0
 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')
Ejemplo n.º 4
0
 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')
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
 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'])
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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'])
Ejemplo n.º 9
0
 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)