diff options
author | mormj <mormjb@gmail.com> | 2020-10-30 10:59:50 -0400 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-10-30 17:52:53 +0100 |
commit | 7a0948ba85758fba1cc3858ef99bfa600dcc7416 (patch) | |
tree | 610d7f9d773a193562def6df2d4b50f1bb3b3f86 /gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py | |
parent | 12192ee7d58de95ddca35a3e93bfc172bdb5c820 (diff) |
qa: run autopep8 formatting on qa python files
find ./ -iname qa*.py | xargs autopep8 --in-place -a -a
mostly formats whitespace and gets rid of trailing semicolons
Diffstat (limited to 'gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py')
-rw-r--r-- | gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py | 251 |
1 files changed, 168 insertions, 83 deletions
diff --git a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py index ae06f8eaf2..0b1cddbaa6 100644 --- a/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py +++ b/gr-digital/python/digital/qa_ofdm_carrier_allocator_cvc.py @@ -10,16 +10,17 @@ from gnuradio import gr, gr_unittest, digital, blocks import pmt + class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): - def setUp (self): - self.tb = gr.top_block () + def setUp(self): + self.tb = gr.top_block() self.tsb_key = "ts_last" - def tearDown (self): + def tearDown(self): self.tb = None - def test_001_t (self): + def test_001_t(self): """ pretty simple (the carrier allocation here is not a practical OFDM configuration!) """ @@ -34,21 +35,24 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): # ^ DC carrier src = blocks.vector_source_c(tx_symbols, False, 1) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, sync_word, - self.tsb_key) + occupied_carriers, + pilot_carriers, + pilot_symbols, sync_word, + self.tsb_key) sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), - alloc, - sink - ) + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_001_t2 (self): + def test_001_t2(self): """ pretty simple (same as before, but odd fft len) """ @@ -62,18 +66,26 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): # ^ DC carrier src = blocks.vector_source_c(tx_symbols, False, 1) alloc = digital.ofdm_carrier_allocator_cvc( - fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key + fft_len, + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key ) sink = blocks.tsb_vector_sink_c(vlen=fft_len, tsb_key=self.tsb_key) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_002_t (self): + def test_002_t(self): """ same, but using negative carrier indices """ @@ -85,21 +97,24 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): expected_result = [1j, 0, 1, 0, 2, 3] src = blocks.vector_source_c(tx_symbols, False, 1) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key) + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key) sink = blocks.tsb_vector_sink_c(fft_len) self.tb.connect( - src, - blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), - alloc, - sink - ) - self.tb.run () + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - def test_002_tb (self): + def test_002_tb(self): """ once again, but this time add a sync word """ @@ -109,7 +124,8 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): pilot_symbols = ((1j,),) occupied_carriers = ((-1, 1, 2),) pilot_carriers = ((3,),) - expected_result = list(sync_word + (1j, 0, 1, 0, 2, 3) + (1j, 0, 4, 0, 5, 6)) + expected_result = list( + sync_word + (1j, 0, 1, 0, 2, 3) + (1j, 0, 4, 0, 5, 6)) special_tag1 = gr.tag_t() special_tag1.offset = 0 special_tag1.key = pmt.string_to_symbol("spam") @@ -131,18 +147,26 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): len_tag_key=self.tsb_key ) sink = blocks.tsb_vector_sink_c(fft_len) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) tags = [gr.tag_to_python(x) for x in sink.tags()] tags = sorted([(x.offset, x.key, x.value) for x in tags]) tags_expected = [ - (0, 'spam', 23), - (2, 'eggs', 42), + (0, 'spam', 23), + (2, 'eggs', 42), ] self.assertEqual(tags, tags_expected) - def test_003_t (self): + def test_003_t(self): """ more advanced: - 6 symbols per carrier @@ -152,42 +176,102 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): - add some random tags - don't shift """ - tx_symbols = list(range(1, 16)); # 15 symbols + tx_symbols = list(range(1, 16)) # 15 symbols pilot_symbols = ((1j, 2j), (3j, 4j)) occupied_carriers = ((1, 3, 4, 11, 12, 14), (1, 2, 4, 11, 13, 14),) pilot_carriers = ((2, 13), (3, 12)) - expected_result = list((0, 1, 1j, 2, 3, 0, 0, 0, 0, 0, 0, 4, 5, 2j, 6, 0, - 0, 7, 8, 3j, 9, 0, 0, 0, 0, 0, 0, 10, 4j, 11, 12, 0, - 0, 13, 1j, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 2j, 0, 0)) + expected_result = list( + (0, + 1, + 1j, + 2, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 4, + 5, + 2j, + 6, + 0, + 0, + 7, + 8, + 3j, + 9, + 0, + 0, + 0, + 0, + 0, + 0, + 10, + 4j, + 11, + 12, + 0, + 0, + 13, + 1j, + 14, + 15, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2j, + 0, + 0)) fft_len = 16 testtag1 = gr.tag_t() testtag1.offset = 0 testtag1.key = pmt.string_to_symbol('tag1') testtag1.value = pmt.from_long(0) testtag2 = gr.tag_t() - testtag2.offset = 7 # On the 2nd OFDM symbol + testtag2.offset = 7 # On the 2nd OFDM symbol testtag2.key = pmt.string_to_symbol('tag2') testtag2.value = pmt.from_long(0) testtag3 = gr.tag_t() - testtag3.offset = len(tx_symbols)+1 # First OFDM symbol of packet 2 + testtag3.offset = len(tx_symbols) + 1 # First OFDM symbol of packet 2 testtag3.key = pmt.string_to_symbol('tag3') testtag3.value = pmt.from_long(0) testtag4 = gr.tag_t() - testtag4.offset = 2*len(tx_symbols)-1 # Last OFDM symbol of packet 2 + # Last OFDM symbol of packet 2 + testtag4.offset = 2 * len(tx_symbols) - 1 testtag4.key = pmt.string_to_symbol('tag4') testtag4.value = pmt.from_long(0) - src = blocks.vector_source_c(tx_symbols * 2, False, 1, (testtag1, testtag2, testtag3, testtag4)) + src = blocks.vector_source_c( + tx_symbols * 2, False, 1, (testtag1, testtag2, testtag3, testtag4)) alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - occupied_carriers, - pilot_carriers, - pilot_symbols, (), - self.tsb_key, - False) + occupied_carriers, + pilot_carriers, + pilot_symbols, (), + self.tsb_key, + False) sink = blocks.tsb_vector_sink_c(fft_len) - self.tb.connect(src, blocks.stream_to_tagged_stream(gr.sizeof_gr_complex, 1, len(tx_symbols), self.tsb_key), alloc, sink) - self.tb.run () + self.tb.connect( + src, + blocks.stream_to_tagged_stream( + gr.sizeof_gr_complex, + 1, + len(tx_symbols), + self.tsb_key), + alloc, + sink) + self.tb.run() self.assertEqual(sink.data()[0], expected_result) - tags_found = {'tag1': False, 'tag2': False, 'tag3': False, 'tag4': False} + tags_found = { + 'tag1': False, + 'tag2': False, + 'tag3': False, + 'tag4': False} correct_offsets = {'tag1': 0, 'tag2': 1, 'tag3': 3, 'tag4': 5} for tag in sink.tags(): key = pmt.symbol_to_string(tag.key) @@ -196,49 +280,50 @@ class qa_digital_carrier_allocator_cvc (gr_unittest.TestCase): self.assertEqual(correct_offsets[key], tag.offset) self.assertTrue(all(tags_found.values())) - def test_004_t (self): + def test_004_t(self): """ Provoking TypeError exceptions providing wrong user input (earlier invisible SIGFPE). """ fft_len = 6 # Occupied carriers - #with self.assertRaises(TypeError) as oc: - #Pybind11 raises this as a ValueError + # with self.assertRaises(TypeError) as oc: + # Pybind11 raises this as a ValueError with self.assertRaises(ValueError) as oc: - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - [], - [[],], - [[],], - [], - self.tsb_key) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + [], + [[], ], + [[], ], + [], + self.tsb_key) # Pilot carriers - #Pybind11 raises this as a ValueError + # Pybind11 raises this as a ValueError with self.assertRaises(ValueError) as pc: - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - [[],], - [], - [[],], - [], - self.tsb_key) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + [[], ], + [], + [[], ], + [], + self.tsb_key) # Pilot carrier symbols - #Pybind11 raises this as a ValueError + # Pybind11 raises this as a ValueError with self.assertRaises(ValueError) as ps: - alloc = digital.ofdm_carrier_allocator_cvc(fft_len, - [[],], - [[],], - [], - [], - self.tsb_key) + alloc = digital.ofdm_carrier_allocator_cvc(fft_len, + [[], ], + [[], ], + [], + [], + self.tsb_key) - - self.assertEqual(str(oc.exception), "Occupied carriers must be of type vector of vector i.e. ((),).") - self.assertEqual(str(pc.exception), "Pilot carriers must be of type vector of vector i.e. ((),).") - self.assertEqual(str(ps.exception), "Pilot symbols must be of type vector of vector i.e. ((),).") + self.assertEqual(str( + oc.exception), "Occupied carriers must be of type vector of vector i.e. ((),).") + self.assertEqual(str(pc.exception), + "Pilot carriers must be of type vector of vector i.e. ((),).") + self.assertEqual(str(ps.exception), + "Pilot symbols must be of type vector of vector i.e. ((),).") if __name__ == '__main__': gr_unittest.run(qa_digital_carrier_allocator_cvc) - |