<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
from os import path
import time
import subprocess
import unittest
from tempfile import NamedTemporaryFile

from wdom.testing import get_webdriver, free_port


CURDIR = path.dirname(path.abspath(__file__))
ROOTDIR = path.dirname(path.dirname(path.dirname(CURDIR)))

src_aio = '''
import sys
import asyncio

sys.path.append('{rootdir}')

from wdom.misc import install_asyncio
from wdom.tag import H1
from wdom.document import get_document
from wdom.server_aio import get_app, start_server
from wdom.server import exclude_patterns

install_asyncio()
loop = asyncio.get_event_loop()
doc = get_document()
doc.body.appendChild(H1('FIRST', id='h1'))
doc.add_cssfile('testdir/test.css')
app = get_app(doc)
app.add_static_path('testdir', '{curdir}/testdir')
server = start_server(app, loop=loop, check_time=10)
loop.run_forever()
'''.format(rootdir=ROOTDIR, curdir=CURDIR)

css_path = path.join(CURDIR, 'testdir/test.css')
src_css = '''
h1 {color: #000000;}
'''
src_css_post = '''
h1 {color: #ff0000;}
'''

_src = src_aio.splitlines()
src_tornado = '\n'.join(_src).replace('_aio', '_tornado')
src_aio_force_reload = src_aio.replace(
    'get_document()', 'get_document(autoreload=True)')
src_tornado_force_reload = src_tornado.replace(
    'get_document()', 'get_document(autoreload=True)')
_src.insert(12, 'exclude_patterns.append(r\'test.css\')')
src_exclude_css_aio = '\n'.join(_src)
src_exclude_css_tornado = src_exclude_css_aio.replace('_aio', '_tornado')
_src = src_aio.splitlines()
_src.insert(12, 'exclude_patterns.append(r\'testdi*\')')
src_exclude_dir_aio = '\n'.join(_src)
src_exclude_dir_tornado = src_exclude_dir_aio.replace('_aio', '_tornado')


class TestAutoReload(unittest.TestCase):
    wait_time = 5 if os.environ.get('TRAVIS') else 1
    def setUp(self):
        with open(css_path, 'w') as f:
            f.write(src_css)
        self.port = free_port()
        self.url = 'http://localhost:{}'.format(self.port)
        tmpfile = NamedTemporaryFile(mode='w+', dir=CURDIR, suffix='.py',
                                     delete=False)
        self.tmpfilename = tmpfile.name
        tmpfile.close()
        self.wd = get_webdriver()
        self.proc = None

    def tearDown(self):
        if self.proc is not None and self.proc.returncode is None:
            self.proc.terminate()
        if path.exists(self.tmpfilename):
            os.remove(self.tmpfilename)
        with open(css_path, 'w') as f:
            f.write(src_css)

    def _base_args(self):
        return [sys.executable, self.tmpfilename, '--port', str(self.port),
                '--logging', 'error']

    def wait(self, t:float=None):
        time.sleep(t or self.wait_time)

    def wait_short(self, t:float=None):
        time.sleep(t or (self.wait_time / 10))
<commit_msg>Add implicit wait on Travis<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import os
from os import path
import time
import subprocess
import unittest
from tempfile import NamedTemporaryFile

from wdom.testing import get_webdriver, free_port, browser_implict_wait


CURDIR = path.dirname(path.abspath(__file__))
ROOTDIR = path.dirname(path.dirname(path.dirname(CURDIR)))

src_aio = '''
import sys
import asyncio

sys.path.append('{rootdir}')

from wdom.misc import install_asyncio
from wdom.tag import H1
from wdom.document import get_document
from wdom.server_aio import get_app, start_server
from wdom.server import exclude_patterns

install_asyncio()
loop = asyncio.get_event_loop()
doc = get_document()
doc.body.appendChild(H1('FIRST', id='h1'))
doc.add_cssfile('testdir/test.css')
app = get_app(doc)
app.add_static_path('testdir', '{curdir}/testdir')
server = start_server(app, loop=loop, check_time=10)
loop.run_forever()
'''.format(rootdir=ROOTDIR, curdir=CURDIR)

css_path = path.join(CURDIR, 'testdir/test.css')
src_css = '''
h1 {color: #000000;}
'''
src_css_post = '''
h1 {color: #ff0000;}
'''

_src = src_aio.splitlines()
src_tornado = '\n'.join(_src).replace('_aio', '_tornado')
src_aio_force_reload = src_aio.replace(
    'get_document()', 'get_document(autoreload=True)')
src_tornado_force_reload = src_tornado.replace(
    'get_document()', 'get_document(autoreload=True)')
_src.insert(12, 'exclude_patterns.append(r\'test.css\')')
src_exclude_css_aio = '\n'.join(_src)
src_exclude_css_tornado = src_exclude_css_aio.replace('_aio', '_tornado')
_src = src_aio.splitlines()
_src.insert(12, 'exclude_patterns.append(r\'testdi*\')')
src_exclude_dir_aio = '\n'.join(_src)
src_exclude_dir_tornado = src_exclude_dir_aio.replace('_aio', '_tornado')


class TestAutoReload(unittest.TestCase):
    wait_time = 5 if os.environ.get('TRAVIS') else 1

    @classmethod
    def setUpClass(cls):
        cls.wd = get_webdriver()
        if os.environ.get('TRAVIS', True):
            cls.wd.implicitly_wait(2)

    @classmethod
    def tearDownClass(cls):
        if os.environ.get('TRAVIS', True):
            cls.wd.implicitly_wait(browser_implict_wait)

    def setUp(self):
        with open(css_path, 'w') as f:
            f.write(src_css)
        self.port = free_port()
        self.url = 'http://localhost:{}'.format(self.port)
        tmpfile = NamedTemporaryFile(mode='w+', dir=CURDIR, suffix='.py',
                                     delete=False)
        self.tmpfilename = tmpfile.name
        tmpfile.close()
        self.proc = None

    def tearDown(self):
        if self.proc is not None and self.proc.returncode is None:
            self.proc.terminate()
        if path.exists(self.tmpfilename):
            os.remove(self.tmpfilename)
        with open(css_path, 'w') as f:
            f.write(src_css)

    def _base_args(self):
        return [sys.executable, self.tmpfilename, '--port', str(self.port),
                '--logging', 'error']

    def wait(self, t:float=None):
        time.sleep(t or self.wait_time)

    def wait_short(self, t:float=None):
        time.sleep(t or (self.wait_time / 10))

{'fraction_non_alphanumeric': 0.1404063957361759, 'fraction_numerical': 0.00916055962691539, 'mean_word_length': 3.800159872102318, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348530', 'n_tokens_mistral': 2189, 'n_tokens_neox': 2120, 'n_words': 403}