<commit_before>import pytest
import requests
from firefly.client import Client, RemoteFunction, FireflyError
from firefly.validator import ValidationError

class MockResponse:
    def __init__(self, status_code, data, headers=None):
        self.status_code = status_code
        self.data = data
        self.headers = headers

    def json(self):
        return self.data

def make_monkey_patch(status, data):
    def mock_post_response(url, json, headers=None):
        r = MockResponse(status_code=status, data=data, headers=headers)
        return r
    return mock_post_response

class TestClass:
    def test_call_for_success_event(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(200, 16))
        c = Client("http://127.0.0.1:8000")
        assert c.square(a=4) == 16

    def test_call_for_validation_error(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(404, {"status": "not found"}))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(FireflyError, message="Expected FireflyError"):
            c.sq(a=4)

    def test_call_for_validation_error(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(422, {"error": "missing a required argument: 'a'"}))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(ValidationError, message="Expected ValidationError"):
            c.square(b=4)

    def test_call_for_server_error(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(500, ""))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(FireflyError, message="Expected FireflyError"):
            c.square(a=4)

    def test_call_for_uncaught_exception(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(502, ""))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(FireflyError, message="Expected FireflyError"):
            c.square(a=4)
<commit_msg>Adds test case for Client file upload<commit_after>import io
import pytest
import requests
from firefly.client import Client, RemoteFunction, FireflyError
from firefly.validator import ValidationError

class MockResponse:
    def __init__(self, status_code, data, headers=None):
        self.status_code = status_code
        self.data = data
        self.headers = headers

    def json(self):
        return self.data

def make_monkey_patch(status, return_data, mode='json'):
    def mock_post_response(url, json=None, data=None, files=None, headers=None):
        r = MockResponse(status_code=status, data=return_data, headers=headers)
        return r
    return mock_post_response

class TestClass:
    def test_call_for_success_event(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(200, 16))
        c = Client("http://127.0.0.1:8000")
        assert c.square(a=4) == 16

    def test_call_for_validation_error(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(404, {"status": "not found"}))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(FireflyError, message="Expected FireflyError"):
            c.sq(a=4)

    def test_call_for_validation_error(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(422, {"error": "missing a required argument: 'a'"}))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(ValidationError, message="Expected ValidationError"):
            c.square(b=4)

    def test_call_for_server_error(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(500, ""))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(FireflyError, message="Expected FireflyError"):
            c.square(a=4)

    def test_call_for_uncaught_exception(self, monkeypatch):
        monkeypatch.setattr(requests, "post", make_monkey_patch(502, ""))
        c = Client("http://127.0.0.1:8000")
        with pytest.raises(FireflyError, message="Expected FireflyError"):
            c.square(a=4)

    def test_call_with_file_upload(self, monkeypatch):
        def filesize(data):
            return len(data.read())
        f = io.StringIO(u"test file contents")
        monkeypatch.setattr(requests, "post", make_monkey_patch(200, "18"))
        c = Client("http://127.0.0.1:8000")
        assert c.filesize(data=f) == "18"

{'fraction_non_alphanumeric': 0.12584726615454134, 'fraction_numerical': 0.03727971079981925, 'mean_word_length': 3.53121801432958, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 11, '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': '1265282', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1410, 'n_words': 273}