<commit_before>from django.test import TestCase

from graphite import readers


class ReadersTest(TestCase):

    maxDiff = None

    def test_merge_with_cache_with_different_step(self):
        # Data values from the Reader:
        start = 1465844460  # (Mon Jun 13 19:01:00 UTC 2016)
        window_size = 7200  # (2 hour)
        step = 60           # (1 minute)

        # Fill in half the data.  Nones for the rest.
        values = range(0, window_size/2, step)
        for i in range(0, window_size/2, step):
            values.append(None)

        # Generate data from Carbon.  Step will be different.
        cache_results = []
        for i in range(start+window_size/2, start+window_size, 1):
            cache_results.append((i, 1))

        values = readers.merge_with_cache(
            cached_datapoints=cache_results,
            start=start,
            step=step,
            values=values,
            func='sum'
        )

        #Compute what this is.
        expected_values = range(0, window_size/2, step)
        for i in range(0, window_size/2, step):
            expected_values.append(60)

        self.assertEqual(expected_values, values)

    def test_merge_with_cache_when_previous_window_in_cache(self):

        start = 1465844460  # (Mon Jun 13 19:01:00 UTC 2016)
        window_size = 3600  # (1 hour)
        step = 60           # (1 minute)

        # simulate db data, no datapoints for the given
        # time window
        values = self._create_none_window(step)

        # simulate cached data with datapoints only
        # from the previous window
        cache_results = []
        prev_window_start = start - window_size<commit_msg>Add space in comment for consistency<commit_after>from django.test import TestCase

from graphite import readers


class ReadersTest(TestCase):

    maxDiff = None

    def test_merge_with_cache_with_different_step(self):
        # Data values from the Reader:
        start = 1465844460  # (Mon Jun 13 19:01:00 UTC 2016)
        window_size = 7200  # (2 hour)
        step = 60           # (1 minute)

        # Fill in half the data.  Nones for the rest.
        values = range(0, window_size/2, step)
        for i in range(0, window_size/2, step):
            values.append(None)

        # Generate data from Carbon.  Step will be different.
        cache_results = []
        for i in range(start+window_size/2, start+window_size, 1):
            cache_results.append((i, 1))

        values = readers.merge_with_cache(
            cached_datapoints=cache_results,
            start=start,
            step=step,
            values=values,
            func='sum'
        )

        # Compute what this is.
        expected_values = range(0, window_size/2, step)
        for i in range(0, window_size/2, step):
            expected_values.append(60)

        self.assertEqual(expected_values, values)

    def test_merge_with_cache_when_previous_window_in_cache(self):

        start = 1465844460  # (Mon Jun 13 19:01:00 UTC 2016)
        window_size = 3600  # (1 hour)
        step = 60           # (1 minute)

        # simulate db data, no datapoints for the given
        # time window
        values = self._create_none_window(step)

        # simulate cached data with datapoints only
        # from the previous window
        cache_results = []
        prev_window_start = start - window_size
{'fraction_non_alphanumeric': 0.07796810395747195, 'fraction_numerical': 0.04311872415829888, 'mean_word_length': 2.0931506849315067, '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': '4485388', 'n_tokens_mistral': 1105, 'n_tokens_neox': 974, 'n_words': 284}