<commit_before>import django.test
from django_rq import get_connection
from rq import get_current_job
from rq.job import Job

from manager.rq_helper import rq_enqueue_with_settings
from tests.redis_test_helpers import perform_all_jobs_sync


def store_in_job(key, value):
    job = get_current_job(connection=get_connection())
    job.meta[key] = value
    job.save()


def return_result(result):
    return result


class RQMetaDataTests(django.test.TestCase):
    def test_stored_metadata_is_not_available_on_original_job_proxy_object(self, *args, **kwargs):
        job = rq_enqueue_with_settings(store_in_job, 'world', 'hello')
        perform_all_jobs_sync()
        self.assertDictEqual(job.meta, {})

    def test_stored_metadata_can_be_retrieved_from_freshly_fetched_job(self, *args, **kwargs):
        job = rq_enqueue_with_settings(store_in_job, 'world', 'hello')
        perform_all_jobs_sync()
        job_fetched = Job.fetch(job.id, connection=get_connection())
        self.assertDictEqual(job_fetched.meta, {'world': 'hello'})


class RQResultTest(django.test.TestCase):
    def test_result_is_not_available_before_job_has_run(self):<commit_msg>test non-tivial pickleable object as metadata value<commit_after>import django.test
from django_rq import get_connection
from rq import get_current_job
from rq.job import Job

from manager.rq_helper import rq_enqueue_with_settings
from tests.redis_test_helpers import perform_all_jobs_sync


def store_in_job(key, value):
    job = get_current_job(connection=get_connection())
    job.meta[key] = value
    job.save()


def return_result(result):
    return result


class RQMetaDataTests(django.test.TestCase):
    def test_stored_metadata_is_not_available_on_original_job_proxy_object(self, *args, **kwargs):
        job = rq_enqueue_with_settings(store_in_job, 'world', 'hello')
        perform_all_jobs_sync()
        self.assertDictEqual(job.meta, {})

    def test_stored_metadata_can_be_retrieved_from_freshly_fetched_job(self, *args, **kwargs):
        job = rq_enqueue_with_settings(store_in_job, 'world', 'hello')
        perform_all_jobs_sync()
        job_fetched = Job.fetch(job.id, connection=get_connection())
        self.assertDictEqual(job_fetched.meta, {'world': 'hello'})

    def test_stored_metadata_value_can_be_an_arbitrary_pickleable_object(self):
        nontrivial_pickleable_object = {'the value': ['can', b'e', ('an arbitrary', 'pickleable'), object]}
        job = rq_enqueue_with_settings(store_in_job, 'world', nontrivial_pickleable_object)
        perform_all_jobs_sync()
        job_fetched = Job.fetch(job.id, connection=get_connection())
        self.assertDictEqual(job_fetched.meta, {'world': nontrivial_pickleable_object})


class RQResultTest(django.test.TestCase):
    def test_result_is_not_available_before_job_has_run(self):
{'fraction_non_alphanumeric': 0.09405940594059406, 'fraction_numerical': 0.0, 'mean_word_length': 5.400452488687783, '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': '1521108', 'n_tokens_mistral': 961, 'n_tokens_neox': 931, 'n_words': 157}