<commit_before># -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

import treq

import glob
import os

import pytest

dirname = os.path.dirname(__file__)
reqdir = os.path.join(dirname, "requests", "invalid")


def test_http_parser():
    for fname in glob.glob(os.path.join(reqdir, "*.http")):
        env = treq.load_py(os.path.splitext(fname)[0] + ".py")

        expect = env['request']
        cfg = env['cfg']
        req = treq.badrequest(fname)

        with pytest.raises(expect):
            def f(fname):
                return req.check(cfg)
            f(fname)<commit_msg>Parametrize invalid request tests.<commit_after># -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.

import treq

import glob
import os

import pytest

dirname = os.path.dirname(__file__)
reqdir = os.path.join(dirname, "requests", "invalid")
httpfiles = glob.glob(os.path.join(reqdir, "*.http"))

@pytest.mark.parametrize("fname", httpfiles)
def test_http_parser(fname):
    env = treq.load_py(os.path.splitext(fname)[0] + ".py")

    expect = env["request"]
    cfg = env["cfg"]
    req = treq.badrequest(fname)

    with pytest.raises(expect):
        req.check(cfg)
{'fraction_non_alphanumeric': 0.13650306748466257, 'fraction_numerical': 0.003067484662576687, 'mean_word_length': 3.2233009708737863, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6182574', 'n_tokens_mistral': 445, 'n_tokens_neox': 440, 'n_words': 112}