<commit_before># -*- coding: utf-8 -*-

import unittest
from os import environ
from flask import Flask
from coaster.app import _additional_config, configure, load_config_from_file


class TestCoasterUtils(unittest.TestCase):
    def setUp(self):
        self.app = Flask(__name__)

    def test_load_config_from_file(self):
        load_config_from_file(self.app, "settings.py")
        self.assertEqual(self.app.config['SETTINGS_KEY'], "settings")

    def test_additional_settings_from_file(self):
        env = 'COASTER_ENV'
        environ[env] = "gibberish"
        self.assertEqual(_additional_config.get(environ[env]), None)
        for k, v in _additional_config.items():
            environ[env] = k
            self.assertEqual(_additional_config.get(environ[env]), v)

    def test_configure(self):
        env = 'COASTER_ENV'
        environ[env] = "testing"
        configure(self.app, env)
        self.assertEqual(self.app.config['SETTINGS_KEY'], "settings")
        self.assertEqual(self.app.config['TEST_KEY'], "test")

if __name__ == '__main__':
    unittest.main()<commit_msg>100% coverage for coaster.app<commit_after># -*- coding: utf-8 -*-

import unittest
from os import environ
from flask import Flask
from coaster.app import _additional_config, configure, load_config_from_file, SandboxedFlask


class TestCoasterUtils(unittest.TestCase):
    def setUp(self):
        self.app = Flask(__name__)

    def test_load_config_from_file(self):
        load_config_from_file(self.app, "settings.py")
        self.assertEqual(self.app.config['SETTINGS_KEY'], "settings")

    def test_additional_settings_from_file(self):
        env = 'COASTER_ENV'
        environ[env] = "gibberish"
        self.assertEqual(_additional_config.get(environ[env]), None)
        for k, v in _additional_config.items():
            environ[env] = k
            self.assertEqual(_additional_config.get(environ[env]), v)

    def test_configure(self):
        env = 'COASTER_ENV'
        environ[env] = "testing"
        configure(self.app, env)
        self.assertEqual(self.app.config['SETTINGS_KEY'], "settings")
        self.assertEqual(self.app.config['TEST_KEY'], "test")

    def test_load_config_from_file_IOError(self):
        app = Flask(__name__)
        load_config_from_file(app, "notfound.py")


class TestSandBoxedFlask(unittest.TestCase):
    def setUp(self):
        self.app = SandboxedFlask(__name__)

    def test_sandboxed_flask(self):
        rv = self.app.create_jinja_environment()
        self.assertFalse(rv.tests['odd'](4))


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.11859838274932614, 'fraction_numerical': 0.0023103581055063534, 'mean_word_length': 3.4793103448275864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7203248', 'n_tokens_mistral': 838, 'n_tokens_neox': 824, 'n_words': 148}