<commit_before># -*- coding: utf-8 -*-
import os
import shutil
import unittest
import tempfile

from flask import current_app

from flask_reveal.app import FlaskReveal
from flask_reveal.config import REVEAL_CONFIG, REVEAL_META
from flask_reveal.blueprints.utils import load_markdown_slides
from flask_reveal.blueprints.reveal import reveal_blueprint


class FlaskRevealTestCase(unittest.TestCase):
    slides = ['Slide1', 'Slide2', 'Slide3']

    def create_presentation_structure(self, slides=None):
        presentation_root = tempfile.mkdtemp()
        media_root = tempfile.mkdtemp()
        fd, img_file = tempfile.mkstemp('.jpg', dir=media_root)

        os.close(fd)

        for index, slide in enumerate(slides):
            fd, _ = tempfile.mkstemp('.md', str(index), presentation_root)
            with os.fdopen(fd, 'w') as file:
                file.write(slide)

        return presentation_root, media_root, os.path.basename(img_file)

    def create_app(self, presentation_root, media_root):
        app = FlaskReveal('flask_reveal')
        app.config['PRESENTATION_ROOT'] = presentation_root
        app.config['MEDIA_ROOT'] = media_root
        app.config['TESTING'] = True

        return app

    def setUp(self):
        self.presentation_root, self.media_root, self.img_file = self.create_presentation_structure(self.slides)
        self.app = self.create_app(self.presentation_root, self.media_root)
        self.client = self.app.test_client()

    def tearDown(self):
        shutil.rmtree(self.presentation_root)

    def test_current_app(self):
        with self.app.app_context():
            self.assertEqual(current_app.name, 'flask_reveal')

    def test_blueprint_loading(self):
        with self.app.app_context():
            self.assertDictEqual(current_app.blueprints, {'reveal': reveal_blueprint})

    def test_default_config_loading(self):
        with self.app.app_context():
            self.assertDictEqual(current_app.config['REVEAL_META'], REVEAL_META)
            self.assertDictEqual(current_app.config['REVEAL_CONFIG'], REVEAL_CONFIG)

    def test_presentation_view_status(self):
        with self.client.get('/') as response:
            self.assertEqual(response.status, '200 OK')

    def test_get_img_view_status(self):
        with self.client.get('/img/{0}'.format(self.img_file)) as response:<commit_msg>refactoring tests to use load_user_config<commit_after># -*- coding: utf-8 -*-
import os
import shutil
import unittest
import tempfile

from flask import current_app

from flask_reveal.app import FlaskReveal
from flask_reveal.config import REVEAL_CONFIG, REVEAL_META
from flask_reveal.blueprints.utils import load_markdown_slides
from flask_reveal.blueprints.reveal import reveal_blueprint


class FlaskRevealTestCase(unittest.TestCase):
    slides = ['Slide1', 'Slide2', 'Slide3']

    def create_presentation_structure(self, slides=None):
        presentation_root = tempfile.mkdtemp()
        media_root = tempfile.mkdtemp()

        fd, img_file = tempfile.mkstemp('.jpg', dir=media_root)

        os.close(fd)

        with open(os.path.join(presentation_root, 'config.py'), 'w') as config_file:
            config_file.write('# test')

        for index, slide in enumerate(slides):
            fd, _ = tempfile.mkstemp('.md', str(index), presentation_root)
            with os.fdopen(fd, 'w') as file:
                file.write(slide)

        return presentation_root, media_root, os.path.basename(img_file)

    def create_test_client(self, presentation_root, media_root):
        app = FlaskReveal('flask_reveal')

        app.load_user_config(presentation_root, media_root)
        app.config['TESTING'] = True

        return app.test_client()

    def setUp(self):
        self.app = FlaskReveal('flask_reveal')

        self.app.config['TESTING'] = True

        self.presentation_root, self.media_root, self.img_file = self.create_presentation_structure(self.slides)

    def tearDown(self):
        shutil.rmtree(self.presentation_root)

    def test_current_app(self):
        with self.app.app_context():
            self.assertEqual(current_app.name, 'flask_reveal')

    def test_blueprint_loading(self):
        with self.app.app_context():
            self.assertDictEqual(current_app.blueprints, {'reveal': reveal_blueprint})

    def test_default_config_loading(self):
        with self.app.app_context():
            self.assertDictEqual(current_app.config['REVEAL_META'], REVEAL_META)
            self.assertDictEqual(current_app.config['REVEAL_CONFIG'], REVEAL_CONFIG)

    def test_presentation_view_status(self):
        client = self.create_test_client(self.presentation_root, self.media_root)

        with client.get('/') as response:
            self.assertEqual(response.status, '200 OK')

    def test_get_img_view_status(self):
        client = self.create_test_client(self.presentation_root, self.media_root)

        with client.get('/img/{0}'.format(self.img_file)) as response:
{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.0032141422257934912, 'mean_word_length': 3.4734950584007187, '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': '5613875', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1527, 'n_words': 280}