<commit_before>import os
import tempfile
import shutil
import unittest
import textwrap
import json
import datetime

from .. import web

TMP_PREFIX = 'orgviz-test-'


def totimestamp(dt):
    zero = datetime.datetime.fromtimestamp(0)
    return (dt - zero).total_seconds()


class TestWebEventsData(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.tmpdir = tempfile.mkdtemp(prefix=TMP_PREFIX)
        cls.org_file = os.path.join(cls.tmpdir, 'test.org')
        web.app.config['ORG_FILE_COMMON'] = [cls.org_file]
        cls.app = web.app.test_client()

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.tmpdir)

    def write_org_file(self, text):
        with open(self.org_file, 'w') as f:
            f.write(textwrap.dedent(text))

    def test_single_event(self):
        self.write_org_file("""
        * Node title<commit_msg>Improve reliability of test by clearing cache<commit_after>import os
import tempfile
import shutil
import unittest
import textwrap
import json
import datetime

from .. import web

TMP_PREFIX = 'orgviz-test-'


def totimestamp(dt):
    zero = datetime.datetime.fromtimestamp(0)
    return (dt - zero).total_seconds()


class TestWebEventsData(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.tmpdir = tempfile.mkdtemp(prefix=TMP_PREFIX)
        cls.org_file = os.path.join(cls.tmpdir, 'test.org')
        web.app.config['ORG_FILE_COMMON'] = [cls.org_file]
        cls.app = web.app.test_client()

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.tmpdir)

    def setUp(self):
        web.cache.clear()

    def write_org_file(self, text):
        with open(self.org_file, 'w') as f:
            f.write(textwrap.dedent(text))

    def test_single_event(self):
        self.write_org_file("""
        * Node title
{'fraction_non_alphanumeric': 0.11153427638737759, 'fraction_numerical': 0.001088139281828074, 'mean_word_length': 3.0957683741648108, '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': '888815', 'n_tokens_mistral': 625, 'n_tokens_neox': 611, 'n_words': 124}