From 3e556eee8ad4c4425799cb652bac26ee58f8e113 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 4 Nov 2019 14:28:44 +0000 Subject: [PATCH] Add docstrings to decoder test cases --- test/test_command.py | 3 ++- test/test_decoder.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_command.py b/test/test_command.py index 1a46bcf..3d3bd0b 100644 --- a/test/test_command.py +++ b/test/test_command.py @@ -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") diff --git a/test/test_decoder.py b/test/test_decoder.py index 94075ec..44e613b 100644 --- a/test/test_decoder.py +++ b/test/test_decoder.py @@ -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