mirror of
https://github.com/Tiendil/pynames.git
synced 2025-09-21 20:30:48 +02:00
Версия 0.2.3
This commit is contained in:
parent
20c3baa828
commit
b09704a4f4
4 changed files with 7 additions and 13 deletions
|
@ -23,9 +23,8 @@ class FromListGenerator(BaseGenerator):
|
|||
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')
|
||||
names_data = json.load(f)
|
||||
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()))
|
||||
|
|
|
@ -48,14 +48,14 @@ class TestName(unittest.TestCase):
|
|||
|
||||
test_file_path = os.path.join(root_dir, 'tests', 'fixtures', 'test_from_list_generator.json')
|
||||
|
||||
with open(test_file_path) as f:
|
||||
with open(test_file_path, 'rb') as f:
|
||||
target_content = f.read()
|
||||
|
||||
with file_adapter(test_file_path) as f:
|
||||
self.assertEqual(f.read(), target_content)
|
||||
|
||||
django_file_object = ContentFile(target_content)
|
||||
classic_file_object = open(test_file_path, 'r')
|
||||
classic_file_object = open(test_file_path, 'rb')
|
||||
|
||||
for tested_file_object in [django_file_object, classic_file_object]:
|
||||
with file_adapter(tested_file_object) as f:
|
||||
|
|
|
@ -51,11 +51,11 @@ def is_file(obj):
|
|||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def file_adapter(file_or_path):
|
||||
def file_adapter(file_or_path, mode='rb'):
|
||||
"""Context manager that works similar to ``open(file_path)``but also accepts already openned file-like objects."""
|
||||
if is_file(file_or_path):
|
||||
file_obj = file_or_path
|
||||
else:
|
||||
file_obj = open(file_or_path, 'rb')
|
||||
file_obj = open(file_or_path, mode)
|
||||
yield file_obj
|
||||
file_obj.close()
|
||||
|
|
7
setup.py
7
setup.py
|
@ -3,7 +3,7 @@ import setuptools
|
|||
|
||||
setuptools.setup(
|
||||
name='Pynames',
|
||||
version='0.2.2',
|
||||
version='0.2.3',
|
||||
description='name generation library',
|
||||
long_description=open('README.rst').read(),
|
||||
url='https://github.com/Tiendil/pynames',
|
||||
|
@ -20,11 +20,6 @@ setuptools.setup(
|
|||
|
||||
'License :: OSI Approved :: BSD License',
|
||||
|
||||
'Programming Language :: Python :: 2',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
|
||||
'Natural Language :: English',
|
||||
'Natural Language :: Russian'],
|
||||
keywords=['gamedev', 'game', 'game development', 'names', 'names generation'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue