<commit_before># coding=utf-8
import os

from lxml import etree
from django.test import TestCase

from corehq.apps.app_manager.models import Application
from corehq.apps.app_manager.tests.util import SuiteMixin
from corehq.apps.app_manager.translations import escape_output_value

import commcare_translations


class AppManagerTranslationsTest(TestCase, SuiteMixin):
    root = os.path.dirname(__file__)
    file_path = ('data', 'suite')

    def test_escape_output_value(self):
        test_cases = [
            ('hello', '<value>hello</value>'),
            ('abc < def > abc', '<value>abc &lt; def &gt; abc</value>'),
            ("bee's knees", "<value>bee's knees</value>"),
            ('unfortunate <xml expression', '<value>unfortunate &lt;xml expression</value>'),
            (u'क्लिक', '<value>&#2325;&#2381;&#2354;&#2367;&#2325;</value>'),
            ('&#39', '<value>&amp;#39</value>'),
            ('Here is a ref <output value="/data/no_media" /> with some trailing text & bad < xml.',
             '<value>Here is a ref <output value="/data/no_media"/> with some trailing text &amp; bad &lt; xml.</value>')

        ]
        for input, expected_output in test_cases:
            self.assertEqual(expected_output, etree.tostring(escape_output_value(input)))

    def test_language_names(self):
        app_json = self.get_json('app')
        app_json['langs'] = ['en', 'fra', 'hin', 'pol']
        app = Application.wrap(app_json)
        app.create_suite()
        app_strings = app.create_app_strings('default')
        app_strings_dict = commcare_translations.loads(app_strings)
        self.assertEqual(app_strings_dict['en'], 'English')
        self.assertEqual(app_strings_dict['fra'], u'Français')
        self.assertEqual(app_strings_dict['hin'], u'हिंदी')
        self.assertEqual(app_strings_dict['pol'], 'polski')<commit_msg>quote tests<commit_after># coding=utf-8
import os

from lxml import etree
from django.test import TestCase

from corehq.apps.app_manager.models import Application
from corehq.apps.app_manager.tests.util import SuiteMixin
from corehq.apps.app_manager.translations import escape_output_value

import commcare_translations


class AppManagerTranslationsTest(TestCase, SuiteMixin):
    root = os.path.dirname(__file__)
    file_path = ('data', 'suite')

    def test_escape_output_value(self):
        test_cases = [
            ('hello', '<value>hello</value>'),
            ('abc < def > abc', '<value>abc &lt; def &gt; abc</value>'),
            ("bee's knees", "<value>bee's knees</value>"),
            ('unfortunate <xml expression', '<value>unfortunate &lt;xml expression</value>'),
            (u'क्लिक', '<value>&#2325;&#2381;&#2354;&#2367;&#2325;</value>'),
            ('&#39', '<value>&amp;#39</value>'),
            ('Here is a ref <output value="/data/no_media" /> with some "trailing" text & that\'s some bad < xml.',
             '<value>Here is a ref <output value="/data/no_media"/> with some "trailing" text &amp; that\'s some bad &lt; xml.</value>')

        ]
        for input, expected_output in test_cases:
            self.assertEqual(expected_output, etree.tostring(escape_output_value(input)))

    def test_language_names(self):
        app_json = self.get_json('app')
        app_json['langs'] = ['en', 'fra', 'hin', 'pol']
        app = Application.wrap(app_json)
        app.create_suite()
        app_strings = app.create_app_strings('default')
        app_strings_dict = commcare_translations.loads(app_strings)
        self.assertEqual(app_strings_dict['en'], 'English')
        self.assertEqual(app_strings_dict['fra'], u'Français')
        self.assertEqual(app_strings_dict['hin'], u'हिंदी')
        self.assertEqual(app_strings_dict['pol'], 'polski')
{'fraction_non_alphanumeric': 0.15462814339218833, 'fraction_numerical': 0.01337613697164259, 'mean_word_length': 3.526634382566586, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5541479', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1163, 'n_words': 240}