# Path: linux_story/helper_functions.py
# def wrap_in_box(lines):
#     """Wrap lines in an ascii box"""
# 
#     def reduction(memo, line):
#         line_length = len(strip_formatting(line))
#         return memo if line_length < memo else line_length
# 
#     def format_line(line):
#         num_padding = max_characters - len(strip_formatting(line))
#         return "| {} |".format(line + (" " * num_padding))
# 
#     max_characters = reduce(reduction, lines, 0)
#     outer_line = " {} ".format("-" * (max_characters + 2))
# 
#     new_lines = map(format_line, lines)
# 
#     return [outer_line] + new_lines + [outer_line + "\n"]
# 
# def get_language_dirs():
#     """
#     Get possible language directories to be searched for, based on
#     the environment variables: LANGUAGE, LC_ALL, LC_MESSAGES and LANG.
#     The result is memoized for future use.
# 
#     This function is inspired by python gettext.py.
# 
#     Returns:
#         dirs (array) - an array of language directories
#     """
# 
#     global language_dirs
#     if language_dirs is not None:
#         return language_dirs
# 
#     languages = []
#     for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
#         val = os.environ.get(envar)
#         if val:
#             languages = val.split(':')
#             break
#     if 'C' in languages:
#         languages.remove('C')
# 
#     # now normalize and expand the languages
#     nelangs = []
#     for lang in languages:
#         for nelang in gettext._expand_lang(lang):
#             if nelang not in nelangs:
#                 nelangs.append(nelang)
# 
#     language_dirs = nelangs
#     return language_dirs


import pytest
from test.test_support import EnvironmentVarGuard
from linux_story.helper_functions import wrap_in_box, get_language_dirs
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Test helper functions




@pytest.yield_fixture
def test_env():
    with EnvironmentVarGuard() as env:
        yield env


def test_wrap_in_box():
    output = wrap_in_box([
        '{{gb:This is a long string}}',
        'Short {{lb:string}}',
    ])

    assert output == [
        " ----------------------- ",
        "| {{gb:This is a long string}} |",
        "| Short {{lb:string}}          |",
        " ----------------------- \n",
    ]


def test_get_language_dirs(test_env):
    test_env['LANG'] = 'en_GB.UTF-8'


# Path: linux_story/helper_functions.py
# def wrap_in_box(lines):
#     """Wrap lines in an ascii box"""
# 
#     def reduction(memo, line):
#         line_length = len(strip_formatting(line))
#         return memo if line_length < memo else line_length
# 
#     def format_line(line):
#         num_padding = max_characters - len(strip_formatting(line))
#         return "| {} |".format(line + (" " * num_padding))
# 
#     max_characters = reduce(reduction, lines, 0)
#     outer_line = " {} ".format("-" * (max_characters + 2))
# 
#     new_lines = map(format_line, lines)
# 
#     return [outer_line] + new_lines + [outer_line + "\n"]
# 
# def get_language_dirs():
#     """
#     Get possible language directories to be searched for, based on
#     the environment variables: LANGUAGE, LC_ALL, LC_MESSAGES and LANG.
#     The result is memoized for future use.
# 
#     This function is inspired by python gettext.py.
# 
#     Returns:
#         dirs (array) - an array of language directories
#     """
# 
#     global language_dirs
#     if language_dirs is not None:
#         return language_dirs
# 
#     languages = []
#     for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
#         val = os.environ.get(envar)
#         if val:
#             languages = val.split(':')
#             break
#     if 'C' in languages:
#         languages.remove('C')
# 
#     # now normalize and expand the languages
#     nelangs = []
#     for lang in languages:
#         for nelang in gettext._expand_lang(lang):
#             if nelang not in nelangs:
#                 nelangs.append(nelang)
# 
#     language_dirs = nelangs
#     return language_dirs


# Path: disabled-tests/linux_story/test_helper_functions.py
import pytest
from test.test_support import EnvironmentVarGuard
from linux_story.helper_functions import wrap_in_box, get_language_dirs

# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Test helper functions




@pytest.yield_fixture
def test_env():
    with EnvironmentVarGuard() as env:
        yield env


def test_wrap_in_box():
    output = wrap_in_box([
        '{{gb:This is a long string}}',
        'Short {{lb:string}}',
    ])

    assert output == [
        " ----------------------- ",
        "| {{gb:This is a long string}} |",
        "| Short {{lb:string}}          |",
        " ----------------------- \n",
    ]


def test_get_language_dirs(test_env):
    test_env['LANG'] = 'en_GB.UTF-8'


    language_dirs = get_language_dirs()