<commit_before>import time
import requests
import re
import json

import unittest


class BaseRestTest(unittest.TestCase):
    def _base_url(self):
        raise NotImplementedError("The method base url must be implemented")

    def _get_full_url(self, url):
        """Replaces a starting . with base url"""
        return re.sub(r'^\.', self._base_url(), url)

    def _validate_response(self, resp, expect):
        if expect is not None:
            self.assertEqual(resp.status_code, expect)

    def put(self, url, obj=None, expect=200):
        """
        Sends a PUT to the url, with the obj as the body

        A starting '.' is replaced with the base url
        :param obj: A Python object
        :param expect: The expected status code
        """
        json_body = json.dumps(obj)
        full_url = self._get_full_url(url)
        resp = requests.put(full_url, json_body)
        self._validate_response(resp, expect)
        return resp

    def get(self, url, expect=200):
        """
        Gets the item at url and returns a Python object based on the json body (if any).

        A starting '.' is replaced with the base url

        :param expect: The expected status code
        """
        full_url = self._get_full_url(url)
        resp = requests.get(full_url)
        self._validate_response(resp, expect)
        try:
            resp.body_obj = jsonpickle.decode(resp.text)
        except ValueError:
            resp.body_obj = None
        return resp


class TestFunctionDelta:
    """
    Checks the results of the same function call made consecutively<commit_msg>Use json instead of jsonpickle<commit_after>import time
import requests
import re
import json

import unittest


class BaseRestTest(unittest.TestCase):
    def _base_url(self):
        raise NotImplementedError("The method base url must be implemented")

    def _get_full_url(self, url):
        """Replaces a starting . with base url"""
        return re.sub(r'^\.', self._base_url(), url)

    def _validate_response(self, resp, expect):
        if expect is not None:
            self.assertEqual(resp.status_code, expect)

    def put(self, url, obj=None, expect=200):
        """
        Sends a PUT to the url, with the obj as the body

        A starting '.' is replaced with the base url
        :param obj: A Python object
        :param expect: The expected status code
        """
        json_body = json.dumps(obj)
        full_url = self._get_full_url(url)
        resp = requests.put(full_url, json_body)
        self._validate_response(resp, expect)
        return resp

    def get(self, url, expect=200):
        """
        Gets the item at url and returns a Python object based on the json body (if any).

        A starting '.' is replaced with the base url

        :param expect: The expected status code
        """
        full_url = self._get_full_url(url)
        resp = requests.get(full_url)
        self._validate_response(resp, expect)
        try:
            resp.body_obj = json.loads(resp.text)
        except ValueError:
            resp.body_obj = None
        return resp


class TestFunctionDelta:
    """
    Checks the results of the same function call made consecutively
{'fraction_non_alphanumeric': 0.08333333333333333, 'fraction_numerical': 0.0037313432835820895, 'mean_word_length': 2.368586387434555, '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': '2320888', 'n_tokens_mistral': 915, 'n_tokens_neox': 891, 'n_words': 313}