<commit_before># -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2015 by Ecpy Authors, see AUTHORS for more details.
#
# Distributed under the terms of the BSD license.
#
# The full license is in the file LICENCE, distributed with this software.
# -----------------------------------------------------------------------------
"""Pytest fixtures.

"""
from __future__ import (division, unicode_literals, print_function,
                        absolute_import)

import os
from os import remove  # Avoid issue when monkeypatching it
import logging
from inspect import getabsfile
from time import sleep

import pytest
from configobj import ConfigObj
from future.builtins import str as text
from enaml.qt.qt_application import QtApplication
from enaml.workbench.api import Workbench


from .util import (APP_DIR_CONFIG, APP_PREFERENCES, close_all_windows,
                   ecpy_path, process_app_events)

#: Global variable storing the application folder path
ECPY = ''


#: Global variable linked to the --ecpy-sleep cmd line option.
DIALOG_SLEEP = 0


pytest_plugins = str('pytest_capturelog')


def pytest_addoption(parser):
    """Add command line options.

    """
    parser.addoption("--ecpy-sleep", action='store', type=float,
                     help="Time to sleep after showing a dialog")


def pytest_configure(config):
    """Turn the --ecpy-sleep command line into a global variable.

    """
    s = config.getoption('--ecpy-sleep')
    if s is not None:
        global DIALOG_SLEEP
        DIALOG_SLEEP = s


@pytest.fixture
def dialog_sleep():
    """Return the time to sleep as set by the --ecpy-sleep option.

    """
    return DIALOG_SLEEP


@pytest.yield_fixture(scope='session', autouse=True)
def sys_path():
    """Detect installation path of ecpy.

    Automtically called, DOES NOT use directly. Use ecpy_path to get the path
    to the ecpy directory.

    """
    import ecpy

    # Hiding current app_directory.ini to avoid losing user choice.
    path = os.path.dirname(getabsfile(ecpy))
    pref_path = os.path.join(path, APP_PREFERENCES)
    app_dir = os.path.join(pref_path, APP_DIR_CONFIG)
    new = os.path.join(pref_path, '_' + APP_DIR_CONFIG)

    # If a hidden file exists already assume it is because previous test
    # failed and do nothing.
    if os.path.isfile(app_dir) and not os.path.isfile(new):
        os.rename(app_dir, new)

    global ECPY
    ECPY = path

    yield

    # Remove created app_directory.ini and put hold one back in place.
    app_dir = os.path.join(pref_path, APP_DIR_CONFIG)
    if os.path.isfile(app_dir):
        os.remove(app_dir)

    # Put user file back in place.
    protected = os.path.join(pref_path, '_' + APP_DIR_CONFIG)
    if os.path.isfile(protected):
        os.rename(protected, app_dir)


@pytest.yield_fixture(scope='session')
def app():
    """Make sure a QtApplication is active.

    """

    app = QtApplication.instance()
    if app is None:
        app = QtApplication()
        yield app
        app.stop()
    else:
        yield app


@pytest.yield_fixture
def windows(app):
    """Fixture making sure the app is running and closing all windows.

    """
    yield
    close_all_windows()


@pytest.yield_fixture<commit_msg>testing: use polling observer on Travis to avoid inotify issues<commit_after># -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright 2015 by Ecpy Authors, see AUTHORS for more details.
#
# Distributed under the terms of the BSD license.
#
# The full license is in the file LICENCE, distributed with this software.
# -----------------------------------------------------------------------------
"""Pytest fixtures.

"""
from __future__ import (division, unicode_literals, print_function,
                        absolute_import)

import os
from os import remove  # Avoid issue when monkeypatching it
import logging
from inspect import getabsfile
from time import sleep

import pytest
from configobj import ConfigObj
from future.builtins import str as text
from enaml.qt.qt_application import QtApplication
from enaml.workbench.api import Workbench


from .util import (APP_DIR_CONFIG, APP_PREFERENCES, close_all_windows,
                   ecpy_path, process_app_events)

#: Global variable storing the application folder path
ECPY = ''


#: Global variable linked to the --ecpy-sleep cmd line option.
DIALOG_SLEEP = 0


pytest_plugins = str('pytest_capturelog')


def pytest_addoption(parser):
    """Add command line options.

    """
    parser.addoption("--ecpy-sleep", action='store', type=float,
                     help="Time to sleep after showing a dialog")


def pytest_configure(config):
    """Turn the --ecpy-sleep command line into a global variable.

    """
    s = config.getoption('--ecpy-sleep')
    if s is not None:
        global DIALOG_SLEEP
        DIALOG_SLEEP = s


@pytest.fixture
def dialog_sleep():
    """Return the time to sleep as set by the --ecpy-sleep option.

    """
    return DIALOG_SLEEP


@pytest.yield_fixture(scope='session', autouse=True)
def sys_path():
    """Detect installation path of ecpy.

    Automtically called, DOES NOT use directly. Use ecpy_path to get the path
    to the ecpy directory.

    """
    import ecpy

    # Hiding current app_directory.ini to avoid losing user choice.
    path = os.path.dirname(getabsfile(ecpy))
    pref_path = os.path.join(path, APP_PREFERENCES)
    app_dir = os.path.join(pref_path, APP_DIR_CONFIG)
    new = os.path.join(pref_path, '_' + APP_DIR_CONFIG)

    # If a hidden file exists already assume it is because previous test
    # failed and do nothing.
    if os.path.isfile(app_dir) and not os.path.isfile(new):
        os.rename(app_dir, new)

    global ECPY
    ECPY = path

    yield

    # Remove created app_directory.ini and put hold one back in place.
    app_dir = os.path.join(pref_path, APP_DIR_CONFIG)
    if os.path.isfile(app_dir):
        os.remove(app_dir)

    # Put user file back in place.
    protected = os.path.join(pref_path, '_' + APP_DIR_CONFIG)
    if os.path.isfile(protected):
        os.rename(protected, app_dir)


@pytest.fixture(scope='session', autouse=True)
def watchdog_on_travis():
    """Do not use inotify on travis as it tends to break builds.

    """
    if 'TRAVIS' in os.environ:
        print('Using polling observer on Travis')
        from watchdog.observers.polling import PollingObserver
        import watchdog.observers
        watchdog.observers.Observer = PollingObserver


@pytest.yield_fixture(scope='session')
def app():
    """Make sure a QtApplication is active.

    """

    app = QtApplication.instance()
    if app is None:
        app = QtApplication()
        yield app
        app.stop()
    else:
        yield app


@pytest.yield_fixture
def windows(app):
    """Fixture making sure the app is running and closing all windows.

    """
    yield
    close_all_windows()


@pytest.yield_fixture
{'fraction_non_alphanumeric': 0.13022990147079824, 'fraction_numerical': 0.001713551335142082, 'mean_word_length': 2.5991778006166495, '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': '888198', 'n_tokens_mistral': 2146, 'n_tokens_neox': 2063, 'n_words': 659}