| 1 | import os |
| 2 | import unittest |
| 3 | import warnings |
| 4 | |
| 5 | import numpy as np |
| 6 | import pytest |
| 7 | |
| 8 | import skrf as rf |
| 9 | from skrf.util import suppress_warning_decorator |
| 10 | |
| 11 | |
| 12 | class AgilentCSVTestCase(unittest.TestCase): |
| 13 | """ |
| 14 | AgilentCSVTestCase tests the IO of agilent style CSV files |
| 15 | """ |
| 16 | def setUp(self): |
| 17 | """ |
| 18 | Sets up the test directory and the initializes the members. |
| 19 | This method gets the current file path to this file, then gets the file |
| 20 | name for pna_csv_reim.csv file, then reads it in. |
| 21 | """ |
| 22 | self.test_dir = os.path.dirname(os.path.abspath(__file__))+'/' |
| 23 | self.filename = os.path.join(self.test_dir, 'pna_csv_reim.csv') |
| 24 | self.acsv = rf.AgilentCSV(self.filename) |
| 25 | |
| 26 | def test_columns(self): |
| 27 | """ |
| 28 | This tests reading of columns from the test file. |
| 29 | """ |
| 30 | self.assertEqual(self.acsv.columns, ['Freq(Hz)', '"A,1"(REAL)', |
| 31 | '"A,1"(IMAG)', '"R1,1"(REAL)', |
| 32 | '"R1,1"(IMAG)']) |
| 33 | |
| 34 | @pytest.mark.skip(reason='unicode error with carriage returns for p3 vs p2') |
| 35 | def test_comments(self): |
| 36 | """ |
| 37 | This tests reading of comment lines in the test file. |
| 38 | """ |
| 39 | self.assertEqual(self.acsv.comments.strip('\r'), 'this is a comment\nline\n') |
| 40 | |
| 41 | def test_data(self): |
| 42 | """ |
| 43 | This tests reading in of the data of the test file. |
| 44 | """ |
| 45 | self.assertTrue((self.acsv.data == |
| 46 | np.array([[750000000000, 1, 2, 3, 4], |
| 47 | [1100000000000, 5, 6, 7,8], |
| 48 | ])).all()) |
| 49 | |
| 50 | def test_frequency(self): |
| 51 | """ |
| 52 | This tests the reading of frequency from the test file |
| 53 | """ |
| 54 | self.assertEqual(self.acsv.frequency, rf.F(750e9, 1100e9, 2, 'hz')) |
| 55 | |
| 56 | @suppress_warning_decorator("CSV format unrecognized") |
| 57 | def test_networks(self): |
| 58 | """ |
| 59 | This only tests for execution, not accuracy |
| 60 | """ |
| 61 | a = self.acsv.networks |
| 62 | |
| 63 | def test_scalar_networks(self): |
| 64 | """ |
| 65 | This only tests for execution, not accuracy |
| 66 | """ |
| 67 | a = self.acsv.scalar_networks |
| 68 | |
| 69 | def test_read_pna_csv(self): |
| 70 | """ |
| 71 | This tests reading of a csv file written by an Agilient PNA. |
| 72 | """ |
| 73 | with warnings.catch_warnings(record=True) as w: |
| 74 | with self.assertWarns(DeprecationWarning): |
| 75 | header, comment, data = rf.read_pna_csv(self.filename) |
| 76 | |
| 77 | self.assertEqual(header, 'Freq(Hz),"A,1"(REAL),"A,1"(IMAG),"R1,1"(REAL),"R1,1"(IMAG)') |
| 78 | self.assertEqual(comment, 'this is a comment\nline\n') |
| 79 | self.assertTrue((data == np.array([[750000000000, 1, 2, 3, 4], |
| 80 | [1100000000000, 5, 6, 7,8], |
| 81 | ])).all()) |