<commit_before># -*- coding: UTF8 -*-

import os
import time
import tempfile
from pprint import pprint

from lib import env
from lib.env import debug
from lib.erl import application as app, acl
from TestSuite import *
from mqttcli import MqttClient
from nyamuk.event import *
from nyamuk.mqtt_pkt import MqttPkt

import apache_log_parser
from twisted.internet import defer

APACHE_COMBINED="%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
parser = apache_log_parser.make_parser(APACHE_COMBINED)

def _match(f, conds):
    time.sleep(.5)
    try:
        rawline = f.readline()
        line = parser(rawline)
        #pprint(line)

        for k, v in conds.iteritems():
            if line[k] != v:
                debug("{0} not matching {1} (is {2})".format(k, v, line[k]), depth=1)
                return False

    except Exception, e:
        print e
        return False

    return True


class AccessLog(TestSuite):
    def __init__(self):
        TestSuite.__init__(self, "AccessLog")

    @defer.inlineCallbacks
    def setup_suite(self):
        ## configuring acls
        (fd, self.acl_file) = tempfile.mkstemp(prefix='wave-acl-'); os.close(fd)
        print "acl file:", self.acl_file

        with open(self.acl_file, 'w') as f:
            f.write("""
# testsuite acl file
anonymous\tallow\tr\tfoo/baz
anonymous\tallow\tw\tfoo/bat
""")

        yield acl.switch(self.acl_file)

    def setup_test(self, testname):
        super(AccessLog, self).setup_test(testname)
<commit_msg>[test] refactor testsuite 034: improve debug logging on error (print raw log line)<commit_after># -*- coding: UTF8 -*-

import os
import time
import tempfile
from pprint import pprint

from lib import env
from lib.env import debug
from lib.erl import application as app, acl
from TestSuite import *
from mqttcli import MqttClient
from nyamuk.event import *
from nyamuk.mqtt_pkt import MqttPkt

import apache_log_parser
from twisted.internet import defer

APACHE_COMBINED="%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
parser = apache_log_parser.make_parser(APACHE_COMBINED)

def _match(f, conds):
    time.sleep(.5)
    try:
        rawline = f.readline()
        line = parser(rawline)
        #pprint(line)

        for k, v in conds.iteritems():
            if line[k] != v:
                debug("{0} not matching {1} (is {2}, raw= {3})".format(k, v, line[k], rawline), depth=1)
                return False

    except Exception, e:
        print e
        return False

    return True


class AccessLog(TestSuite):
    def __init__(self):
        TestSuite.__init__(self, "AccessLog")

    @defer.inlineCallbacks
    def setup_suite(self):
        ## configuring acls
        (fd, self.acl_file) = tempfile.mkstemp(prefix='wave-acl-'); os.close(fd)
        print "acl file:", self.acl_file

        with open(self.acl_file, 'w') as f:
            f.write("""
# testsuite acl file
anonymous\tallow\tr\tfoo/baz
anonymous\tallow\tw\tfoo/bat
""")

        yield acl.switch(self.acl_file)

    def setup_test(self, testname):
        super(AccessLog, self).setup_test(testname)

{'fraction_non_alphanumeric': 0.12242268041237113, 'fraction_numerical': 0.005154639175257732, 'mean_word_length': 2.8523573200992556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4380249', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1052, 'n_words': 283}