PySSTV 0.5.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PySSTV-0.5.5.dist-info/LICENSE.txt +22 -0
- PySSTV-0.5.5.dist-info/METADATA +95 -0
- PySSTV-0.5.5.dist-info/RECORD +23 -0
- PySSTV-0.5.5.dist-info/WHEEL +5 -0
- PySSTV-0.5.5.dist-info/entry_points.txt +2 -0
- PySSTV-0.5.5.dist-info/top_level.txt +1 -0
- pysstv/__init__.py +3 -0
- pysstv/__main__.py +92 -0
- pysstv/color.py +205 -0
- pysstv/examples/__init__.py +3 -0
- pysstv/examples/codegen.py +167 -0
- pysstv/examples/get_floats.py +22 -0
- pysstv/examples/get_freq_bits.py +23 -0
- pysstv/examples/gimp-plugin.py +253 -0
- pysstv/examples/overlay.py +17 -0
- pysstv/examples/pyaudio_sstv.py +51 -0
- pysstv/examples/repeater.py +73 -0
- pysstv/grayscale.py +40 -0
- pysstv/sstv.py +136 -0
- pysstv/tests/__init__.py +3 -0
- pysstv/tests/common.py +9 -0
- pysstv/tests/test_color.py +44 -0
- pysstv/tests/test_sstv.py +79 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from io import BytesIO
|
|
3
|
+
from itertools import islice
|
|
4
|
+
import mock
|
|
5
|
+
from mock import MagicMock
|
|
6
|
+
import hashlib
|
|
7
|
+
|
|
8
|
+
from pysstv import sstv
|
|
9
|
+
from pysstv.sstv import SSTV
|
|
10
|
+
from pysstv.tests.common import load_pickled_asset
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestSSTV(unittest.TestCase):
|
|
14
|
+
|
|
15
|
+
def setUp(self):
|
|
16
|
+
self.s = SSTV(False, 48000, 16)
|
|
17
|
+
self.s.VIS_CODE = 0x00
|
|
18
|
+
self.s.SYNC = 7
|
|
19
|
+
|
|
20
|
+
def test_horizontal_sync(self):
|
|
21
|
+
horizontal_sync = self.s.horizontal_sync()
|
|
22
|
+
expected = (1200, self.s.SYNC)
|
|
23
|
+
actual = next(iter(horizontal_sync))
|
|
24
|
+
self.assertEqual(expected, actual)
|
|
25
|
+
|
|
26
|
+
def test_gen_freq_bits(self):
|
|
27
|
+
gen_freq_bits = self.s.gen_freq_bits()
|
|
28
|
+
expected = [(1900, 300),
|
|
29
|
+
(1200, 10),
|
|
30
|
+
(1900, 300),
|
|
31
|
+
(1200, 30),
|
|
32
|
+
(1300, 30),
|
|
33
|
+
(1300, 30),
|
|
34
|
+
(1300, 30),
|
|
35
|
+
(1300, 30),
|
|
36
|
+
(1300, 30),
|
|
37
|
+
(1300, 30),
|
|
38
|
+
(1300, 30),
|
|
39
|
+
(1300, 30),
|
|
40
|
+
(1200, 30)]
|
|
41
|
+
actual = list(islice(gen_freq_bits, 0, 1000))
|
|
42
|
+
self.assertEqual(expected, actual)
|
|
43
|
+
|
|
44
|
+
# FIXME: Instead of using a test fixture, 'expected' should be synthesized?
|
|
45
|
+
def test_gen_values(self):
|
|
46
|
+
gen_values = self.s.gen_values()
|
|
47
|
+
expected = load_pickled_asset("SSTV_gen_values")
|
|
48
|
+
for e, g in zip(expected, gen_values):
|
|
49
|
+
self.assertAlmostEqual(e, g, delta=0.000000001)
|
|
50
|
+
|
|
51
|
+
def test_gen_samples(self):
|
|
52
|
+
gen_values = self.s.gen_samples()
|
|
53
|
+
# gen_samples uses random to avoid quantization noise
|
|
54
|
+
# by using additive noise, so there's always a chance
|
|
55
|
+
# of running the code two consecutive times on the same machine
|
|
56
|
+
# and having different results.
|
|
57
|
+
# https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29
|
|
58
|
+
sstv.random = MagicMock(return_value=0.4) # xkcd:221
|
|
59
|
+
expected = load_pickled_asset("SSTV_gen_samples")
|
|
60
|
+
actual = list(islice(gen_values, 0, 1000))
|
|
61
|
+
for e, a in zip(expected, actual):
|
|
62
|
+
self.assertAlmostEqual(e, a, delta=1)
|
|
63
|
+
|
|
64
|
+
def test_write_wav(self):
|
|
65
|
+
self.maxDiff = None
|
|
66
|
+
bio = BytesIO()
|
|
67
|
+
bio.close = MagicMock() # ignore close() so we can .getvalue()
|
|
68
|
+
mock_open = MagicMock(return_value=bio)
|
|
69
|
+
with mock.patch('builtins.open', mock_open):
|
|
70
|
+
self.s.write_wav('unittest.wav')
|
|
71
|
+
expected = 'dd7eed880ab3360fb79ce09c469deee2'
|
|
72
|
+
data = bio.getvalue()
|
|
73
|
+
actual = hashlib.md5(data).hexdigest()
|
|
74
|
+
self.assertEqual(expected, actual)
|
|
75
|
+
|
|
76
|
+
def test_init(self):
|
|
77
|
+
self.assertEqual(self.s.image, False)
|
|
78
|
+
self.assertEqual(self.s.samples_per_sec, 48000)
|
|
79
|
+
self.assertEqual(self.s.bits, 16)
|