<commit_before>import unittest
import urllib2

import greenhouse
from base import FeatherTest


class WSGIServerTests(FeatherTest):
    def hello_world(self, environ, start_response):
        start_response("200 OK", [('Content-Length', '13')])
        return ["Hello, World!"]

    def hello_world_no_content_length(self, environ, start_response):
        start_response("200 OK", [])
        return ["Hello, World!"]

    def test_basic(self):
        greenhouse.emulation.patch()

        with self.wsgi_server(self.hello_world, port=8989):
            self.assertEqual(
                    urllib2.urlopen("http://localhost:8989/").read(),
                    "Hello, World!")

        self.assertRaises(
                urllib2.URLError,
                urllib2.urlopen,
                "http://localhost:8989/")

    def test_write(self):
        greenhouse.emulation.patch()

        def app(environ, start_response):
            write = start_response("200, OK", [])
            write("written\n")
            return ["returned"]

        with self.wsgi_server(app, port=8888):
            self.assertEqual(
                    urllib2.urlopen("http://localhost:8888/").read(),
                    "written\nreturned")

    def test_headers(self):
        greenhouse.emulation.patch()

        def app(environ, start_response):
            start_response("200 OK", [
                ("X-Foo", "bar"),<commit_msg>test fix, a wsgi app's first start_response argument shouldn't have a comma (!)<commit_after>import unittest
import urllib2

import greenhouse
from base import FeatherTest


class WSGIServerTests(FeatherTest):
    def hello_world(self, environ, start_response):
        start_response("200 OK", [('Content-Length', '13')])
        return ["Hello, World!"]

    def hello_world_no_content_length(self, environ, start_response):
        start_response("200 OK", [])
        return ["Hello, World!"]

    def test_basic(self):
        greenhouse.emulation.patch()

        with self.wsgi_server(self.hello_world, port=8989):
            self.assertEqual(
                    urllib2.urlopen("http://localhost:8989/").read(),
                    "Hello, World!")

        self.assertRaises(
                urllib2.URLError,
                urllib2.urlopen,
                "http://localhost:8989/")

    def test_write(self):
        greenhouse.emulation.patch()

        def app(environ, start_response):
            write = start_response("200 OK", [])
            write("written\n")
            return ["returned"]

        with self.wsgi_server(app, port=8888):
            self.assertEqual(
                    urllib2.urlopen("http://localhost:8888/").read(),
                    "written\nreturned")

    def test_headers(self):
        greenhouse.emulation.patch()

        def app(environ, start_response):
            start_response("200 OK", [
                ("X-Foo", "bar"),
{'fraction_non_alphanumeric': 0.12495697074010327, 'fraction_numerical': 0.02685025817555938, 'mean_word_length': 2.169029443838604, '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': '7347764', 'n_tokens_mistral': 913, 'n_tokens_neox': 823, 'n_words': 159}