<commit_before>"""
When the test runner finds and executes tests within this directory,
this file will be loaded to setup the test environment. Tests
are run using python nose (usually invoked with ./acre test)

configuration comes in through os.environ, see config below

"""
import os
import sys
import urllib2
import httplib
import cookielib
import re
from unittest import TestCase
import simplejson
import urllib
from urllib2 import Request
import string
import types

from FirePHP import FirePHP_decode


__all__ = ['TestController', 'tag']

here_dir = os.path.dirname(os.path.abspath(__file__))
conf_file = here_dir + '/test.ini'

import simplejson
from nose.tools import *

def setup_context():
    """ 
    Test modules/packages can import this function and call it to
    ensure their tests have a valid context.
    
    """

def setup_package():
    setup_context()

def teardown_package():
    pass

class AcreRedirectHandler(urllib2.HTTPRedirectHandler):
    """
    A subclass of the default HTTPRedirectHandler which handles 301 and 302 status codes. 
    """
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        result = urllib2.HTTPRedirectHandler()
        print "Redirect handler caught error.\ncode: %s\nmsg: %s\nheaders: %s\nnewurl: %s\n" % (code, msg, headers, newurl);
        print "Now throwing catchable HTTPError";
        raise urllib2.HTTPError(newurl, code, msg, headers, fp)

class ExtraAsserts(object):
    
    def assertIn(self, array, value, msg=None):
        self.assert_(value in array, msg or "value %s not in %r" % (value, array))

    def assertNotIn(self, array, value, msg=None):
        self.assert_(not value in array, msg or "value %s is in %r" % (value, array))

    def assert_(self, cond, msg=None):
        return assert_true(cond, msg)

def tag(**kwds):
   """ decorator that sets attributes on a function

   usage:
       @tag(key1=v1, key2='something else')
       def fn(...):
           ....
   """
   def inner(f):
       for k,v in kwds.iteritems():
           setattr(f, k, v)
       return f
   return inner

class TestController(ExtraAsserts):

    def setUp(self, *args, **kwargs):
        self.cookiefile = "./cookies.lwp",
        self.cookiejar = cookielib.LWPCookieJar("./cookies.lwp")

        # Install cookie and redirect handlers.
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar))
        urllib2.install_opener(self.opener)

        # set test url
        self.data = None;
        self.method = "GET";
        self.headers = None

        config = os.environ
        self.server_host = "dev.acre.localhost"
        self.server_base= "acre.localhost"
        self.server_name = "api.qatests.apps.freebase.dev.acre.localhost"
        self.script_namespace = "/freebase/apps/qatests/api"

        self.port = int(config.get("ACRE_PORT"))
        self.server_url = 'http://' + self.server_name
        if self.port != 80:
            self.server_url += ':%d' % self.port

        self.host = self.server_url;
        self.username= config.get("TEST_USERNAME")
        self.password= config.get("TEST_PASSWORD")

        base_addr = config.get("ACRE_METAWEB_BASE_ADDR")
        port_str = config.get("ACRE_FREEBASE_SITE_ADDR_PORT")
        if port_str:
            port_str = ":" + port_str
        else:
            port_str = ":80"
        if base_addr:
            self.freebase_api_service = "http://api." + base_addr + port_str
            self.freebase_service = "http://api." + base_addr
            self.appeditor_host = "http://www." + base_addr + port_str
        else:
            print "tests are going nowhere with the env var: ACRE_METAWEB_BASE_ADDR"
            sys.exit(1)

        self.appeditor_service_url= None
        if self.appeditor_host:
            self.appeditor_service_url = self.appeditor_host + "/appeditor/services"

        self.auth_host = self.freebase_service
        self.data_path = "data"
        self.data_path = here_dir + '/' + self.data_path

    def set_acre_script(self, acre_script, data="", headers=None, domain=None):
        self.acre_script = acre_script
        if domain is not None:<commit_msg>make tests depend on the ACRE_HOST_BASE configuration<commit_after>"""
When the test runner finds and executes tests within this directory,
this file will be loaded to setup the test environment. Tests
are run using python nose (usually invoked with ./acre test)

configuration comes in through os.environ, see config below

"""
import os
import sys
import urllib2
import httplib
import cookielib
import re
from unittest import TestCase
import simplejson
import urllib
from urllib2 import Request
import string
import types

from FirePHP import FirePHP_decode


__all__ = ['TestController', 'tag']

here_dir = os.path.dirname(os.path.abspath(__file__))
conf_file = here_dir + '/test.ini'

import simplejson
from nose.tools import *

def setup_context():
    """ 
    Test modules/packages can import this function and call it to
    ensure their tests have a valid context.
    
    """

def setup_package():
    setup_context()

def teardown_package():
    pass

class AcreRedirectHandler(urllib2.HTTPRedirectHandler):
    """
    A subclass of the default HTTPRedirectHandler which handles 301 and 302 status codes. 
    """
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        result = urllib2.HTTPRedirectHandler()
        print "Redirect handler caught error.\ncode: %s\nmsg: %s\nheaders: %s\nnewurl: %s\n" % (code, msg, headers, newurl);
        print "Now throwing catchable HTTPError";
        raise urllib2.HTTPError(newurl, code, msg, headers, fp)

class ExtraAsserts(object):
    
    def assertIn(self, array, value, msg=None):
        self.assert_(value in array, msg or "value %s not in %r" % (value, array))

    def assertNotIn(self, array, value, msg=None):
        self.assert_(not value in array, msg or "value %s is in %r" % (value, array))

    def assert_(self, cond, msg=None):
        return assert_true(cond, msg)

def tag(**kwds):
   """ decorator that sets attributes on a function

   usage:
       @tag(key1=v1, key2='something else')
       def fn(...):
           ....
   """
   def inner(f):
       for k,v in kwds.iteritems():
           setattr(f, k, v)
       return f
   return inner

class TestController(ExtraAsserts):

    def setUp(self, *args, **kwargs):
        self.cookiefile = "./cookies.lwp",
        self.cookiejar = cookielib.LWPCookieJar("./cookies.lwp")

        # Install cookie and redirect handlers.
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar))
        urllib2.install_opener(self.opener)

        # set test url
        self.data = None;
        self.method = "GET";
        self.headers = None

        config = os.environ
        self.server_base = config.get("ACRE_HOST_BASE")
        self.server_host = "dev." + self.server_base
        self.server_name = "api.qatests.apps.freebase." + self.server_host
        self.script_namespace = "/freebase/apps/qatests/api"

        self.port = int(config.get("ACRE_PORT"))
        self.server_url = 'http://' + self.server_name
        if self.port != 80:
            self.server_url += ':%d' % self.port

        self.host = self.server_url;
        self.username = config.get("TEST_USERNAME")
        self.password = config.get("TEST_PASSWORD")

        base_addr = config.get("ACRE_METAWEB_BASE_ADDR")
        port_str = config.get("ACRE_FREEBASE_SITE_ADDR_PORT")
        if port_str:
            port_str = ":" + port_str
        else:
            port_str = ":80"
        if base_addr:
            self.freebase_api_service = "http://api." + base_addr + port_str
            self.freebase_service = "http://api." + base_addr
            self.appeditor_host = "http://www." + base_addr + port_str
        else:
            print "tests are going nowhere with the env var: ACRE_METAWEB_BASE_ADDR"
            sys.exit(1)

        self.appeditor_service_url = None
        if self.appeditor_host:
            self.appeditor_service_url = self.appeditor_host + "/appeditor/services"

        self.auth_host = self.freebase_service
        self.data_path = "data"
        self.data_path = here_dir + '/' + self.data_path

    def set_acre_script(self, acre_script, data="", headers=None, domain=None):
        self.acre_script = acre_script
        if domain is not None:
{'fraction_non_alphanumeric': 0.1066080342286665, 'fraction_numerical': 0.005229379605419538, 'mean_word_length': 2.760053619302949, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3605695', 'n_tokens_mistral': 2672, 'n_tokens_neox': 2615, 'n_words': 705}