<commit_before>import json
import os
import sys

from ..taxbrain.compute import MockCompute
from django.core.files.uploadedfile import SimpleUploadedFile

NUM_BUDGET_YEARS = int(os.environ.get("NUM_BUDGET_YEARS", "10"))

def get_dropq_compute_from_module(module_import_path, num_times_to_wait=None):
    module_views = sys.modules[module_import_path]
    module_views.dropq_compute = MockCompute(
        num_times_to_wait=num_times_to_wait
    )
    return module_views.dropq_compute

def do_micro_sim(client, data, tb_dropq_compute=None, dyn_dropq_compute=None):
    '''do the proper sequence of HTTP calls to run a microsim'''
    #Monkey patch to mock out running of compute jobs
    if tb_dropq_compute is None:
        tb_dropq_compute = get_dropq_compute_from_module(
            'webapp.apps.taxbrain.views',
            num_times_to_wait=0
        )
    if dyn_dropq_compute is None:
        dyn_dropq_compute = get_dropq_compute_from_module(
            'webapp.apps.dynamic.views',
            num_times_to_wait=1
        )
    # dynamic_views.dropq_compute = MockCompute(num_times_to_wait=1)

    response = client.post('/taxbrain/', data)
    # Check that redirect happens
    assert response.status_code == 302
    idx = response.url[:-1].rfind('/')
    assert response.url[:idx].endswith("taxbrain")
    # return response<commit_msg>Add option to check compute count<commit_after>import json
import os
import sys

from ..taxbrain.compute import MockCompute
from django.core.files.uploadedfile import SimpleUploadedFile

NUM_BUDGET_YEARS = int(os.environ.get("NUM_BUDGET_YEARS", "10"))

def get_dropq_compute_from_module(module_import_path, num_times_to_wait=None):
    module_views = sys.modules[module_import_path]
    module_views.dropq_compute = MockCompute(
        num_times_to_wait=num_times_to_wait
    )
    return module_views.dropq_compute

def do_micro_sim(client, data, tb_dropq_compute=None, dyn_dropq_compute=None,
                 compute_count=None):
    '''do the proper sequence of HTTP calls to run a microsim'''
    #Monkey patch to mock out running of compute jobs
    if tb_dropq_compute is None:
        tb_dropq_compute = get_dropq_compute_from_module(
            'webapp.apps.taxbrain.views',
            num_times_to_wait=0
        )
    if dyn_dropq_compute is None:
        dyn_dropq_compute = get_dropq_compute_from_module(
            'webapp.apps.dynamic.views',
            num_times_to_wait=1
        )

    response = client.post('/taxbrain/', data)
    # Check that redirect happens
    assert response.status_code == 302
    idx = response.url[:-1].rfind('/')
    assert response.url[:idx].endswith("taxbrain")
    print('compute_count', tb_dropq_compute.count, compute_count)
    if compute_count is not None:
        assert tb_dropq_compute.count == compute_count
    # return response
{'fraction_non_alphanumeric': 0.08277562522014793, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 3.6787479406919275, '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': '6417184', 'n_tokens_mistral': 929, 'n_tokens_neox': 907, 'n_words': 186}