<commit_before>#!/usr/bin/python
################################################################################

import os
import sys
import unittest

from StringIO import StringIO
from contextlib import nested

from mock import *

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src', 'collectors')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'contrib')))

from diamond import *

def get_collector_config(key, value):
    config = configobj.ConfigObj()
    config['server'] = {}
    config['server']['collectors_config_path'] = ''
    config['collectors'] = {}
    config['collectors']['default'] = {}
    config['collectors'][key] = value
    return config

def get_fixture(fixture_name):
    with open(get_fixture_path(fixture_name), 'r') as file:
        return StringIO(file.read())

def get_fixture_path(fixture_name):
    return os.path.abspath(os.path.join(os.path.dirname(__file__), 'fixtures', fixture_name))

class CollectorTestCase(unittest.TestCase):
    def assertPublished(self, mock, key, value):
        calls = filter(lambda x: x[0][0] == key, mock.call_args_list)

        actual_value = len(calls)
        expected_value = 1
        message = '%s: actual number of calls %d, expected %d' % (key, actual_value, expected_value)

        self.assertEqual(actual_value, expected_value, message)

        actual_value = calls[0][0][1]
        expected_value = value
        precision = None

        if isinstance(value, tuple):
            expected_value, precision = expected_value

        message = '%s: actual %r, expected %r' % (key, actual_value, expected_value)

        if precision:
            self.assertAlmostEqual(actual_value, expected_value, places = precision, msg = message)
        else:
            self.assertEqual(actual_value, expected_value, message)

    def assertPublishedMany(self, mock, dict):
        for key, value in dict.iteritems():
            self.assertPublished(mock, key, value)

        mock.reset_mock()<commit_msg>Default percision is 0, so update tests to reflect this<commit_after>#!/usr/bin/python
################################################################################

import os
import sys
import unittest

from StringIO import StringIO
from contextlib import nested

from mock import *

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src', 'collectors')))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'contrib')))

from diamond import *

def get_collector_config(key, value):
    config = configobj.ConfigObj()
    config['server'] = {}
    config['server']['collectors_config_path'] = ''
    config['collectors'] = {}
    config['collectors']['default'] = {}
    config['collectors'][key] = value
    return config

def get_fixture(fixture_name):
    with open(get_fixture_path(fixture_name), 'r') as file:
        return StringIO(file.read())

def get_fixture_path(fixture_name):
    return os.path.abspath(os.path.join(os.path.dirname(__file__), 'fixtures', fixture_name))

class CollectorTestCase(unittest.TestCase):
    def assertPublished(self, mock, key, value):
        calls = filter(lambda x: x[0][0] == key, mock.call_args_list)

        actual_value = len(calls)
        expected_value = 1
        message = '%s: actual number of calls %d, expected %d' % (key, actual_value, expected_value)

        self.assertEqual(actual_value, expected_value, message)

        actual_value = calls[0][0][1]
        expected_value = value
        precision = 0

        if isinstance(value, tuple):
            expected_value, precision = expected_value

        message = '%s: actual %r, expected %r' % (key, actual_value, expected_value)

        if precision is not None:
            self.assertAlmostEqual(actual_value, expected_value, places = precision, msg = message)
        else:
            self.assertEqual(actual_value, expected_value, message)

    def assertPublishedMany(self, mock, dict):
        for key, value in dict.iteritems():
            self.assertPublished(mock, key, value)

        mock.reset_mock()
{'fraction_non_alphanumeric': 0.16562137049941927, 'fraction_numerical': 0.0032520325203252032, 'mean_word_length': 3.811173184357542, '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': '1723534', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1284, 'n_words': 279}