1
0
Fork 0

Add docstrings to decoder test cases

master
James Taylor 2019-11-04 14:28:44 +00:00
parent 3bbec517d1
commit 3e556eee8a
2 changed files with 6 additions and 2 deletions

View File

@ -32,7 +32,7 @@ class SSTVCommandTestCase(unittest.TestCase):
with self.assertRaises(SystemExit):
SSTVCommand(["-d"])
self.assertIn("expected one argument", sys.stderr.getvalue().strip(),
"Wrong argument error message not present in output")
"'Wrong argument' error message not present in output")
with self.assertRaises(SystemExit):
SSTVCommand(["--decode"])
@ -57,6 +57,7 @@ class SSTVCommandTestCase(unittest.TestCase):
"skip value not set to default value")
def test_arg_parser_decode_set_skip(self):
"""Test setting the skip flag to a custom value"""
args = SSTVCommand(["-d", "./test/data/m1.ogg", "-s", "15.50"]).args
self.assertTrue(hasattr(args, "skip"),
"skip attribute not set")

View File

@ -1,6 +1,5 @@
"""Test cases for the decoder code"""
import sys
import unittest
from sstv.decode import barycentric_peak_interp, calc_lum, SSTVDecoder
@ -10,11 +9,13 @@ class SSTVDecoderTestCase(unittest.TestCase):
"""Test SSTVDecoder class"""
def test_calc_lum(self):
"""Test function that calculates pixel byte from frequency"""
self.assertEqual(calc_lum(1450), 0)
self.assertEqual(calc_lum(2350), 255)
self.assertEqual(calc_lum(1758.1531), 82)
def test_barycentric_peak_interp(self):
"""Test function to interpolate the x value from frequency bins"""
bins = [100, 50, 0, 25, 50, 75, 100, 200, 150, 100]
# Left neighbour is higher, so result must be smaller/equal
self.assertLess(barycentric_peak_interp(bins, 9), 9)
@ -28,12 +29,14 @@ class SSTVDecoderTestCase(unittest.TestCase):
self.assertEqual(barycentric_peak_interp(bins, 2), 2)
def test_decoder_init(self):
"""Test SSTVDecoder init"""
with open("./test/data/m1.ogg", 'rb') as fp:
with SSTVDecoder(fp) as decoder:
self.assertEqual(decoder._audio_file, fp)
self.assertEqual(decoder._sample_rate, 44100)
def test_decoder_freq_detect(self):
"""Test the peak frequency detection function"""
with open("./test/data/220hz_sine.ogg", 'rb') as fp:
with SSTVDecoder(fp) as decoder:
# Test using all samples in sound file