# Path: randtalkbot/i18n.py
# def get_languages_names(codes):
#     """Raises:
#         LanguageNotFoundError: If unable to recognize some language.
# 
#     Returns:
#         str: Comma-separated list of languages' names.
#     """
#     names = map(_get_language_name, codes)
#     return ', '.join(names)
# 
# def get_languages_codes(names):
#     """Raises:
#         LanguageNotFoundError: If unable to recognize some language.
# 
#     Returns:
#         list<str>: Deduplicated list of languages' codes.
#     """
#     names = ''.join([c for c in names if c not in QUOTES])
# 
#     if names.strip().lower() in SAME_LANGUAGE_NAMES:
#         return ['same']
# 
#     names = [name.strip() for name in names.split(',')]
#     compact_names = filter(bool, names)
#     languages_codes = map(_get_language_code, compact_names)
#     unique_languages_codes = _get_deduplicated(languages_codes)
#     return unique_languages_codes
# 
# def get_translation(languages):
#     if not languages:
#         languages = ['en']
# 
#     try:
#         translation_instance = gettext.translation(
#             'randtalkbot',
#             localedir=LOCALE_DIR,
#             languages=languages,
#             )
#     except OSError:
#         translation_instance = gettext.translation(
#             'randtalkbot',
#             localedir=LOCALE_DIR,
#             languages=['en'],
#             )
# 
#     return translation_instance.gettext
# 
# class LanguageNotFoundError(Exception):
#     def __init__(self, name):
#         super(LanguageNotFoundError, self).__init__('Language \"{0}\" wasn\'t found.'.format(name))
#         self.name = name


import unittest
from unittest.mock import call, patch
from randtalkbot.i18n import get_languages_names, get_languages_codes, get_translation, \
    LanguageNotFoundError

    def test_get_languages_codes__has_no_iso639_1_code(self):
        with self.assertRaises(LanguageNotFoundError):
            get_languages_codes('zza')

    @patch('randtalkbot.i18n.gettext')
    @patch('randtalkbot.i18n.LOCALE_DIR', 'foo_locale_dir')
    def test_get_translation__no_languages(self, gettext):
        self.assertEqual(get_translation([]), gettext.translation.return_value.gettext)
        gettext.translation.assert_called_once_with(
            'randtalkbot',
            localedir='foo_locale_dir',
            languages=['en'],
            )

    @patch('randtalkbot.i18n.gettext')
    @patch('randtalkbot.i18n.LOCALE_DIR', 'foo_locale_dir')
    def test_get_translation__ok(self, gettext):
        self.assertEqual(get_translation(['foo']), gettext.translation.return_value.gettext)
        gettext.translation.assert_called_once_with(
            'randtalkbot',
            localedir='foo_locale_dir',
            languages=['foo'],
            )

    @patch('randtalkbot.i18n.gettext')
    @patch('randtalkbot.i18n.LOCALE_DIR', 'foo_locale_dir')
    def test_get_translation__not_supported_language(self, gettext):
        gettext.translation.side_effect = OSError
        with self.assertRaises(OSError):

# Path: randtalkbot/i18n.py
# def get_languages_names(codes):
#     """Raises:
#         LanguageNotFoundError: If unable to recognize some language.
# 
#     Returns:
#         str: Comma-separated list of languages' names.
#     """
#     names = map(_get_language_name, codes)
#     return ', '.join(names)
# 
# def get_languages_codes(names):
#     """Raises:
#         LanguageNotFoundError: If unable to recognize some language.
# 
#     Returns:
#         list<str>: Deduplicated list of languages' codes.
#     """
#     names = ''.join([c for c in names if c not in QUOTES])
# 
#     if names.strip().lower() in SAME_LANGUAGE_NAMES:
#         return ['same']
# 
#     names = [name.strip() for name in names.split(',')]
#     compact_names = filter(bool, names)
#     languages_codes = map(_get_language_code, compact_names)
#     unique_languages_codes = _get_deduplicated(languages_codes)
#     return unique_languages_codes
# 
# def get_translation(languages):
#     if not languages:
#         languages = ['en']
# 
#     try:
#         translation_instance = gettext.translation(
#             'randtalkbot',
#             localedir=LOCALE_DIR,
#             languages=languages,
#             )
#     except OSError:
#         translation_instance = gettext.translation(
#             'randtalkbot',
#             localedir=LOCALE_DIR,
#             languages=['en'],
#             )
# 
#     return translation_instance.gettext
# 
# class LanguageNotFoundError(Exception):
#     def __init__(self, name):
#         super(LanguageNotFoundError, self).__init__('Language \"{0}\" wasn\'t found.'.format(name))
#         self.name = name


# Path: tests/test_i18n.py
import unittest
from unittest.mock import call, patch
from randtalkbot.i18n import get_languages_names, get_languages_codes, get_translation, \
    LanguageNotFoundError


    def test_get_languages_codes__has_no_iso639_1_code(self):
        with self.assertRaises(LanguageNotFoundError):
            get_languages_codes('zza')

    @patch('randtalkbot.i18n.gettext')
    @patch('randtalkbot.i18n.LOCALE_DIR', 'foo_locale_dir')
    def test_get_translation__no_languages(self, gettext):
        self.assertEqual(get_translation([]), gettext.translation.return_value.gettext)
        gettext.translation.assert_called_once_with(
            'randtalkbot',
            localedir='foo_locale_dir',
            languages=['en'],
            )

    @patch('randtalkbot.i18n.gettext')
    @patch('randtalkbot.i18n.LOCALE_DIR', 'foo_locale_dir')
    def test_get_translation__ok(self, gettext):
        self.assertEqual(get_translation(['foo']), gettext.translation.return_value.gettext)
        gettext.translation.assert_called_once_with(
            'randtalkbot',
            localedir='foo_locale_dir',
            languages=['foo'],
            )

    @patch('randtalkbot.i18n.gettext')
    @patch('randtalkbot.i18n.LOCALE_DIR', 'foo_locale_dir')
    def test_get_translation__not_supported_language(self, gettext):
        gettext.translation.side_effect = OSError
        with self.assertRaises(OSError):

            get_translation(['foo'])