<commit_before>## This file is part of Invenio.
## Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

# pylint: disable=E1102

"""
Helper functions for building and running test suites.
"""

__revision__ = "$Id$"

CFG_TESTUTILS_VERBOSE = 1

import os
import sys
import time

import cgi
import subprocess

from warnings import warn
from urlparse import urlsplit, urlunsplit
from urllib import urlencode
from itertools import chain, repeat

try:
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
except ImportError:
    # web tests will not be available, but unit and regression tests will:
    pass

import unittest

from invenio.config import CFG_SITE_URL, \
     CFG_SITE_SECURE_URL, CFG_LOGDIR, CFG_SITE_NAME_INTL, CFG_PYLIBDIR, \
     CFG_JSTESTDRIVER_PORT, CFG_WEBDIR, CFG_PREFIX
from invenio.w3c_validator import w3c_validate, w3c_errors_to_str, \
     CFG_TESTS_REQUIRE_HTML_VALIDATION
from invenio.pluginutils import PluginContainer

try:
    from nose.tools import nottest
except ImportError:
    def nottest(f):
        """Helper decorator to mark a function as not to be tested by nose."""
        f.__test__ = False
        return f

@nottest
def warn_user_about_tests(test_suite_type='regression'):
    """
    Display a standard warning about running tests that might modify
    user data, and wait for user confirmation, unless --yes-i-know
    was specified in the comman line.
    """

    # Provide a command line option to avoid having to type the
    # confirmation every time during development.
    if '--yes-i-know' in sys.argv:
        return

    if test_suite_type == 'web':
        sys.stderr.write("""\
**********************************************************************
**                                                                  **
**     A B O U T   T H E   W E B   T E S T   S U I T E              **
**                                                                  **
** The web test suite will be launched in Firefox.  You must have   **
** the Selenium IDE extension installed to be able to run the web   **
** test suite.  If you do, please check out the results of the web  **
** test suite in the Selenium IDE window.                           **
**                                                                  **
**********************************************************************

""")

    sys.stderr.write("""\
**********************************************************************
**                                                                  **
**     I M P O R T A N T   W A R N I N G                            **
**                                                                  **
** The %s test suite needs to be run on a clean demo site   **
** that you can obtain by doing:                                    **
**                                                                  **
**    $ inveniocfg --drop-demo-site                                 **
**    $ inveniocfg --create-demo-site                               **
**    $ inveniocfg --load-demo-records                              **
**                                                                  **
** Note that DOING THE ABOVE WILL ERASE YOUR ENTIRE DATABASE.       **
**                                                                  **
** In addition, due to the write nature of some of the tests,       **
** the demo DATABASE will be ALTERED WITH JUNK DATA, so that        **
** it is recommended to rebuild the demo site anew afterwards.      **
**                                                                  **
**********************************************************************

Please confirm by typing 'Yes, I know!': """ % test_suite_type)

    answer = raw_input('')
    if answer != 'Yes, I know!':
        sys.stderr.write("Aborted.\n")
        raise SystemExit(0)

    return

@nottest
def make_test_suite(*test_cases):
    """ Build up a test suite given separate test cases"""
    return unittest.TestSuite([unittest.makeSuite(case, 'test')
                               for case in test_cases])

#from invenio.config import *
from invenio.dbquery import CFG_DATABASE_HOST, \
    CFG_DATABASE_PORT, \
    CFG_DATABASE_NAME, \
    CFG_DATABASE_USER, \
    CFG_DATABASE_PASS, \
    CFG_DATABASE_TYPE, \
    CFG_DATABASE_SLAVE
from invenio.webinterface_handler_flask import create_invenio_flask_app, \
    with_app_context
from invenio.urlutils import rewrite_to_secure_url
from flask.ext.testing import TestCase
from sqlalchemy.engine.url import URL
from functools import wraps


class InvenioFixture(object):

    def __init__(self, fixture_builder=None):<commit_msg>testutils: fix pyparsing import troubles<commit_after>## This file is part of Invenio.
## Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

# pylint: disable=E1102

"""
Helper functions for building and running test suites.
"""

__revision__ = "$Id$"

CFG_TESTUTILS_VERBOSE = 1

import os
import sys
import time

import cgi
import subprocess

from warnings import warn
from urlparse import urlsplit, urlunsplit
from urllib import urlencode
from itertools import chain, repeat

try:
    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
except ImportError:
    # web tests will not be available, but unit and regression tests will:
    pass

import unittest

from invenio.config import CFG_SITE_URL, \
     CFG_SITE_SECURE_URL, CFG_LOGDIR, CFG_SITE_NAME_INTL, CFG_PYLIBDIR, \
     CFG_JSTESTDRIVER_PORT, CFG_WEBDIR, CFG_PREFIX
from invenio.w3c_validator import w3c_validate, w3c_errors_to_str, \
     CFG_TESTS_REQUIRE_HTML_VALIDATION
from invenio.pluginutils import PluginContainer

try:
    from nose.tools import nottest
except ImportError:
    def nottest(f):
        """Helper decorator to mark a function as not to be tested by nose."""
        f.__test__ = False
        return f

@nottest
def warn_user_about_tests(test_suite_type='regression'):
    """
    Display a standard warning about running tests that might modify
    user data, and wait for user confirmation, unless --yes-i-know
    was specified in the comman line.
    """

    # Provide a command line option to avoid having to type the
    # confirmation every time during development.
    if '--yes-i-know' in sys.argv:
        return

    if test_suite_type == 'web':
        sys.stderr.write("""\
**********************************************************************
**                                                                  **
**     A B O U T   T H E   W E B   T E S T   S U I T E              **
**                                                                  **
** The web test suite will be launched in Firefox.  You must have   **
** the Selenium IDE extension installed to be able to run the web   **
** test suite.  If you do, please check out the results of the web  **
** test suite in the Selenium IDE window.                           **
**                                                                  **
**********************************************************************

""")

    sys.stderr.write("""\
**********************************************************************
**                                                                  **
**     I M P O R T A N T   W A R N I N G                            **
**                                                                  **
** The %s test suite needs to be run on a clean demo site   **
** that you can obtain by doing:                                    **
**                                                                  **
**    $ inveniocfg --drop-demo-site                                 **
**    $ inveniocfg --create-demo-site                               **
**    $ inveniocfg --load-demo-records                              **
**                                                                  **
** Note that DOING THE ABOVE WILL ERASE YOUR ENTIRE DATABASE.       **
**                                                                  **
** In addition, due to the write nature of some of the tests,       **
** the demo DATABASE will be ALTERED WITH JUNK DATA, so that        **
** it is recommended to rebuild the demo site anew afterwards.      **
**                                                                  **
**********************************************************************

Please confirm by typing 'Yes, I know!': """ % test_suite_type)

    answer = raw_input('')
    if answer != 'Yes, I know!':
        sys.stderr.write("Aborted.\n")
        raise SystemExit(0)

    return

@nottest
def make_test_suite(*test_cases):
    """ Build up a test suite given separate test cases"""
    return unittest.TestSuite([unittest.makeSuite(case, 'test')
                               for case in test_cases])

#from invenio.config import *
from invenio.dbquery import CFG_DATABASE_HOST, \
    CFG_DATABASE_PORT, \
    CFG_DATABASE_NAME, \
    CFG_DATABASE_USER, \
    CFG_DATABASE_PASS, \
    CFG_DATABASE_TYPE, \
    CFG_DATABASE_SLAVE
from invenio.webinterface_handler_flask import create_invenio_flask_app, \
    with_app_context
from invenio.urlutils import rewrite_to_secure_url
import pyparsing  # needed to import here before flask.ext.testing in
                  # order to avoid pyparsing troubles due to twill
from flask.ext.testing import TestCase
from sqlalchemy.engine.url import URL
from functools import wraps


class InvenioFixture(object):

    def __init__(self, fixture_builder=None):
{'fraction_non_alphanumeric': 0.12185563251913963, 'fraction_numerical': 0.01020780167699599, 'mean_word_length': 2.0489024729091416, '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': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5981052', 'n_tokens_mistral': 2944, 'n_tokens_neox': 2753, 'n_words': 1064}