<commit_before>import unittest
import os
import threading

from http.server import BaseHTTPRequestHandler, HTTPServer

from google.cloud import bigquery

HOSTNAME = "127.0.0.1"
PORT = 8000
URL = "http://%s:%s" % (HOSTNAME, PORT)

class TestBigQuery(unittest.TestCase):
    def _test_proxy(self, client):
        with HTTPServer((HOSTNAME, PORT), HTTPHandler) as httpd:
            threading.Thread(target=httpd.serve_forever).start()

            try:
                for ds in client.list_datasets(): pass
            except:
                pass

            httpd.shutdown()
            self.assertTrue(HTTPHandler.called, msg="Fake server did not recieve a request from the BQ client.")
            self.assertTrue(HTTPHandler.header_found, msg="X-KAGGLE-PROXY-DATA header was missing from the BQ request.")
    
    def test_proxy_kaggle_project(self):
        client = bigquery.Client(project='KAGGLE')
        self._test_proxy(client)

    def test_proxy_no_project(self):
        client = bigquery.Client()
        self._test_proxy(client)<commit_msg>Apply suggestions from code review<commit_after>import unittest
import os
import threading

from http.server import BaseHTTPRequestHandler, HTTPServer

from google.cloud import bigquery

HOSTNAME = "127.0.0.1"
PORT = 8000
URL = "http://%s:%s" % (HOSTNAME, PORT)

class TestBigQuery(unittest.TestCase):
    def _test_proxy(self, client):
        with HTTPServer((HOSTNAME, PORT), HTTPHandler) as httpd:
            threading.Thread(target=httpd.serve_forever).start()

            try:
                for ds in client.list_datasets(): pass
            except:
                pass

            httpd.shutdown()
            self.assertTrue(HTTPHandler.called, msg="Fake server did not receive a request from the BQ client.")
            self.assertTrue(HTTPHandler.header_found, msg="X-KAGGLE-PROXY-DATA header was missing from the BQ request.")
    
    def test_proxy_kaggle_project(self):
        client = bigquery.Client(project='KAGGLE')
        self._test_proxy(client)

    def test_proxy_no_project(self):
        client = bigquery.Client()
        self._test_proxy(client)
{'fraction_non_alphanumeric': 0.09537166900420757, 'fraction_numerical': 0.009350163627863487, 'mean_word_length': 2.8698010849909585, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1168041', 'n_tokens_mistral': 640, 'n_tokens_neox': 622, 'n_words': 153}