<commit_before># -*- coding: utf-8 -*-

"""
Copyright (C) 2014 <NAME> <dsuch at zato.io>

Licensed under LGPLv3, see LICENSE.txt for terms and conditions.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

# stdlib
import os

# Zato
from zato.apitest.util import new_context

# Behave formatting/pretty printing
import behave.formatter.pretty

import logging

def before_all(context):
    if not context.config.log_capture:
        logging.basicConfig(level=logging.DEBUG)

def before_feature(context, feature):
    environment_dir = os.path.dirname(os.path.realpath(__file__))
    context.zato = new_context(None, environment_dir)

from distutils.util import strtobool as _bool

BEHAVE_DEBUG_ON_ERROR = _bool(os.environ.get("BEHAVE_DEBUG_ON_ERROR", "no"))
PRINT_VERBOSE_OUTPUT = _bool(os.environ.get("PRINT_VERBOSE_OUTPUT", "no"))
PRINT_DOC_ON_PASSED = os.environ.get("PRINT_DOC_ON_PASSED", None)
PRINT_DOC_TO_FILENAME = os.environ.get("PRINT_DOC_TO_FILENAME", None)

# I don't feel like hacking myself into the loggin features. Aka, we just add
# everything to a document string.
# I cannot use the context to store stuff, since that can be cleared..
global documentation
documentation = ''

def after_all(context):
    if PRINT_DOC_ON_PASSED:
        if PRINT_DOC_TO_FILENAME:
            print("Printing docs to file " + PRINT_DOC_TO_FILENAME)
            with open(PRINT_DOC_TO_FILENAME, "w") as docfile:
                docfile.write(documentation)
        else:
            print(documentation)

def add_to_doc(text, type):
    global documentation
    if PRINT_DOC_ON_PASSED == 'trac':
        if type == "h1":
            documentation += '= ' + text + ' =' + '\n'
        if type == "h2":
            documentation += '== ' + text + ' ==' + '\n'
        if type == "h3":
            documentation += '=== ' + text + ' ===' + '\n'
        if type == "code" or type == "jacascript":
            documentation += '{{{\n' + text + '\n}}}\n' + '\n'
    elif PRINT_DOC_ON_PASSED == 'html':
        if type == "h1":
            documentation += '<h1>' + text + '</h1>' + '\n'
        if type == "h2":
            documentation += '<h2>' + text + '</h2>' + '\n'
        if type == "h3":
            documentation += '<h3>' + text + '</h3>' + '\n'
        if type == "code" or type == "javascript":
            documentation += '<pre>\n' + text + '</pre>\n'
    # Default, Markdown
    else:
        pass

def after_step(context, step):
    if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
        print(u"Request:")
        import pprint
        pp = pprint.PrettyPrinter(indent=4, depth=3)
        pp.pprint(context.zato.request)
        print("response:\n")
        try:
            pp.pprint(context.zato.response)
        except:
            print("No response object")
        print("/ context")
        print("steps:" + str(step.status))
        pp.pprint(step)<commit_msg>When the request fails, there is a very hich chance that the response text is not in the same format as the request format set. Which results in very little response information. If I use the raw data.text, I will get whatever the server sent. Which is alot more useful. Hopefully.<commit_after># -*- coding: utf-8 -*-

"""
Copyright (C) 2014 <NAME> <dsuch at zato.io>

Licensed under LGPLv3, see LICENSE.txt for terms and conditions.
"""

from __future__ import absolute_import, division, print_function, unicode_literals

# stdlib
import os

# Zato
from zato.apitest.util import new_context

# Behave formatting/pretty printing
import behave.formatter.pretty

import logging

def before_all(context):
    if not context.config.log_capture:
        logging.basicConfig(level=logging.DEBUG)

def before_feature(context, feature):
    environment_dir = os.path.dirname(os.path.realpath(__file__))
    context.zato = new_context(None, environment_dir)

from distutils.util import strtobool as _bool

BEHAVE_DEBUG_ON_ERROR = _bool(os.environ.get("BEHAVE_DEBUG_ON_ERROR", "no"))
PRINT_VERBOSE_OUTPUT = _bool(os.environ.get("PRINT_VERBOSE_OUTPUT", "no"))
PRINT_DOC_ON_PASSED = os.environ.get("PRINT_DOC_ON_PASSED", None)
PRINT_DOC_TO_FILENAME = os.environ.get("PRINT_DOC_TO_FILENAME", None)

# I don't feel like hacking myself into the loggin features. Aka, we just add
# everything to a document string.
# I cannot use the context to store stuff, since that can be cleared..
global documentation
documentation = ''

def after_all(context):
    if PRINT_DOC_ON_PASSED:
        if PRINT_DOC_TO_FILENAME:
            print("Printing docs to file " + PRINT_DOC_TO_FILENAME)
            with open(PRINT_DOC_TO_FILENAME, "w") as docfile:
                docfile.write(documentation)
        else:
            print(documentation)

def add_to_doc(text, type):
    global documentation
    if PRINT_DOC_ON_PASSED == 'trac':
        if type == "h1":
            documentation += '= ' + text + ' =' + '\n'
        if type == "h2":
            documentation += '== ' + text + ' ==' + '\n'
        if type == "h3":
            documentation += '=== ' + text + ' ===' + '\n'
        if type == "code" or type == "jacascript":
            documentation += '{{{\n' + text + '\n}}}\n' + '\n'
    elif PRINT_DOC_ON_PASSED == 'html':
        if type == "h1":
            documentation += '<h1>' + text + '</h1>' + '\n'
        if type == "h2":
            documentation += '<h2>' + text + '</h2>' + '\n'
        if type == "h3":
            documentation += '<h3>' + text + '</h3>' + '\n'
        if type == "code" or type == "javascript":
            documentation += '<pre>\n' + text + '</pre>\n'
    # Default, Markdown
    else:
        pass

def after_step(context, step):
    if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
        print(u"Request:")
        import pprint
        pp = pprint.PrettyPrinter(indent=4, depth=3)
        pp.pprint(context.zato.request)
        print("response:\n")
        try:
            pp.pprint(context.zato.response.data.text)
        except:
            print("No response object")
        print("/ context")
        print("steps:" + str(step.status))
        pp.pprint(step)
{'fraction_non_alphanumeric': 0.13385569702905648, 'fraction_numerical': 0.00652954619653934, 'mean_word_length': 2.7985120892746433, 'pattern_counts': {'":': 18, '<': 23, '<?xml version=': 0, '>': 23, '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': '4590094', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1926, 'n_words': 515}