From e40f45e5939b5c9174cf7a4b47ad8615d033c5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Franusic?= Date: Tue, 18 Jun 2013 14:55:07 -0700 Subject: [PATCH] changed per dnet's suggestions --- .gitignore | 2 -- tests/test_sstv.py | 15 +++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 61c89c6..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.py[cod] -venv diff --git a/tests/test_sstv.py b/tests/test_sstv.py index 0dc5044..a089ca8 100644 --- a/tests/test_sstv.py +++ b/tests/test_sstv.py @@ -6,6 +6,7 @@ from mock import MagicMock from StringIO import StringIO import hashlib +import sstv from sstv import SSTV @@ -49,8 +50,12 @@ class TestSSTV(unittest.TestCase): def test_gen_samples(self): gen_values = self.s.gen_samples() - # I expected to need this, but I don't? Not in this instance? - # sstv.random = Mock(return_value=0.4) # xkcd:221 + # 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) @@ -58,15 +63,13 @@ class TestSSTV(unittest.TestCase): def test_write_wav(self): self.maxDiff = None sio = StringIO() - sio.close = MagicMock() # ignore close() + sio.close = MagicMock() # ignore close() so we can .getvalue() mock_open = MagicMock(return_value=sio) with mock.patch('__builtin__.open', mock_open): self.s.write_wav('unittest.wav') expected = 'bf61c82e96aed1370d5c1753d87729db' data = sio.getvalue() - hash = hashlib.md5() - hash.update(data) - actual = hash.hexdigest() + actual = hashlib.md5(data).hexdigest() self.assertEqual(expected, actual) def test_init(self):