<commit_before>import unittest
from itertools import islice
import pickle
import mock
from mock import MagicMock
from StringIO import StringIO
import hashlib

import sstv
from sstv import SSTV


class TestSSTV(unittest.TestCase):

    def setUp(self):
        self.s = SSTV(False, 48000, 16)
        self.s.VIS_CODE = 0x00
        self.s.SYNC = 7

    def test_horizontal_sync(self):
        horizontal_sync = self.s.horizontal_sync()
        expected = (1200, self.s.SYNC)
        actual = horizontal_sync.next()
        self.assertEqual(expected, actual)

    def test_gen_freq_bits(self):
        gen_freq_bits = self.s.gen_freq_bits()
        expected = [(1900, 300),
                    (1200, 10),
                    (1900, 300),
                    (1200, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1200, 30)]
        actual = list(islice(gen_freq_bits, 0, 1000))
        self.assertEqual(expected, actual)

    # FIXME: Instead of using a test fixture, 'expected' should be synthesized?
    def test_gen_values(self):
        gen_values = self.s.gen_values()
        expected = pickle.load(open("tests/assets/SSTV_gen_values.p"))
        actual = list(islice(gen_values, 0, 1000))
        self.assertEqual(expected, actual)

    def test_gen_samples(self):
        gen_values = self.s.gen_samples()
        # gen_samples uses random to avoid quantization noise
        # by using additive noise, so there's always a chance
        # of running the code two consecutive times on the same machine
        # and having different results.
        # https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29
        sstv.random = MagicMock(return_value=0.4)  # xkcd:221
        expected = pickle.load(open("tests/assets/SSTV_gen_samples.p"))
        actual = list(islice(gen_values, 0, 1000))
        self.assertEqual(expected, actual)

    def test_write_wav(self):
        self.maxDiff = None<commit_msg>allow slight differences when comparing float values<commit_after>import unittest
from itertools import islice, izip
import pickle
import mock
from mock import MagicMock
from StringIO import StringIO
import hashlib

import sstv
from sstv import SSTV


class TestSSTV(unittest.TestCase):

    def setUp(self):
        self.s = SSTV(False, 48000, 16)
        self.s.VIS_CODE = 0x00
        self.s.SYNC = 7

    def test_horizontal_sync(self):
        horizontal_sync = self.s.horizontal_sync()
        expected = (1200, self.s.SYNC)
        actual = horizontal_sync.next()
        self.assertEqual(expected, actual)

    def test_gen_freq_bits(self):
        gen_freq_bits = self.s.gen_freq_bits()
        expected = [(1900, 300),
                    (1200, 10),
                    (1900, 300),
                    (1200, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1200, 30)]
        actual = list(islice(gen_freq_bits, 0, 1000))
        self.assertEqual(expected, actual)

    # FIXME: Instead of using a test fixture, 'expected' should be synthesized?
    def test_gen_values(self):
        gen_values = self.s.gen_values()
        expected = pickle.load(open("tests/assets/SSTV_gen_values.p"))
        for e, g in izip(expected, gen_values):
            self.assertAlmostEqual(e, g, delta=0.000000001)

    def test_gen_samples(self):
        gen_values = self.s.gen_samples()
        # gen_samples uses random to avoid quantization noise
        # by using additive noise, so there's always a chance
        # of running the code two consecutive times on the same machine
        # and having different results.
        # https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29
        sstv.random = MagicMock(return_value=0.4)  # xkcd:221
        expected = pickle.load(open("tests/assets/SSTV_gen_samples.p"))
        actual = list(islice(gen_values, 0, 1000))
        self.assertEqual(expected, actual)

    def test_write_wav(self):
        self.maxDiff = None
{'fraction_non_alphanumeric': 0.09782857142857143, 'fraction_numerical': 0.055542857142857144, 'mean_word_length': 2.058001397624039, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '3261931', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1279, 'n_words': 329}