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

###############################################################################
#  Copyright 2013 Kitware Inc.
#
#  Licensed under the Apache License, Version 2.0 ( the "License" );
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
###############################################################################

import base64
import codecs
import cherrypy
import io
import json
import mimetypes
import os
import signal
import subprocess
import sys
import unittest
import urllib
import uuid

from StringIO import StringIO
from girder.utility import model_importer
from girder.utility.server import setup as setupServer
from girder.constants import AccessType, ROOT_DIR, SettingKey
from . import mock_smtp

# local = cherrypy.lib.httputil.Host('127.0.0.1', 50000, '')
# remote = cherrypy.lib.httputil.Host('127.0.0.1', 50001, '')
enabledPlugins = []
process = None


def startServer():
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    # Start tangelo on the testing port, and bail out with error if it fails.
    global process
    appPath = os.path.join(os.environ['ROOT_DIR'], "app")
    process = subprocess.Popen([os.environ['TANGELO'], "start",
                                "--host", "127.0.0.1",
                                "--port", os.environ['PORT'],
                                "--root", appPath,
                                "-nd",
                                "--logdir", ".",
                                "--girder-path", "/girder",
                                "--no-config"])


def stopServer():
    """
    Test cases that communicate with the server should call this
    function in their tearDownModule() function.
    """
    global process
    code = process.poll()
    if code is not None:
        print("Tangelo exited prematurely with code{}.".format(code))
    else:
        process.kill()


def dropTestDatabase():
    """
    Call this to clear all contents from the test database. Also forces models
    to reload.
    """
    from girder.models import getDbConnection
    db_connection = getDbConnection()
    model_importer.clearModels()  # Must clear the models so indices are rebuit
    dbName = cherrypy.config['database']['database']

    if 'girder_test_' not in dbName:
        raise Exception('Expected a testing database name, but got {}'
                        .format(dbName))<commit_msg>Wait for tangelo to spin up for testing<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

###############################################################################
#  Copyright 2013 Kitware Inc.
#
#  Licensed under the Apache License, Version 2.0 ( the "License" );
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
###############################################################################

import base64
import codecs
import cherrypy
import io
import json
import mimetypes
import os
import signal
import subprocess
import sys
import time
import unittest
import urllib
import uuid

from StringIO import StringIO
from girder.utility import model_importer
from girder.utility.server import setup as setupServer
from girder.constants import AccessType, ROOT_DIR, SettingKey
from . import mock_smtp

# local = cherrypy.lib.httputil.Host('127.0.0.1', 50000, '')
# remote = cherrypy.lib.httputil.Host('127.0.0.1', 50001, '')
enabledPlugins = []
process = None


def startServer():
    """
    Test cases that communicate with the server should call this
    function in their setUpModule() function.
    """
    # Start tangelo on the testing port, and bail out with error if it fails.
    global process
    appPath = os.path.join(os.environ['ROOT_DIR'], "app")
    process = subprocess.Popen([os.environ['TANGELO'], "start",
                                "--host", "127.0.0.1",
                                "--port", os.environ['PORT'],
                                "--root", appPath,
                                "-nd",
                                "--logdir", ".",
                                "--girder-path", "/girder",
                                "--no-config"])

    # Give it time to spin up
    time.sleep(5)


def stopServer():
    """
    Test cases that communicate with the server should call this
    function in their tearDownModule() function.
    """
    global process
    code = process.poll()
    if code is not None:
        print("Tangelo exited prematurely with code{}.".format(code))
    else:
        process.kill()


def dropTestDatabase():
    """
    Call this to clear all contents from the test database. Also forces models
    to reload.
    """
    from girder.models import getDbConnection
    db_connection = getDbConnection()
    model_importer.clearModels()  # Must clear the models so indices are rebuit
    dbName = cherrypy.config['database']['database']

    if 'girder_test_' not in dbName:
        raise Exception('Expected a testing database name, but got {}'
                        .format(dbName))
{'fraction_non_alphanumeric': 0.1447080599024062, 'fraction_numerical': 0.013292949688709406, 'mean_word_length': 2.6873449131513647, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 6, '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': '2584892', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1544, 'n_words': 565}