def test_setter(self): ts = Touchstone("") dp_list = [Datapoint(1, 0.0, 0.0), Datapoint(3, 1.0, 1.0)] ts.s11data = dp_list[:] ts.s21data = dp_list[:] ts.s12data = dp_list[:] ts.s22data = dp_list[:] self.assertEqual(ts.s11data, dp_list) self.assertEqual(ts.s21data, dp_list) self.assertEqual(ts.s12data, dp_list) self.assertEqual(ts.s22data, dp_list) self.assertEqual(ts.min_freq(), 1) self.assertEqual(ts.max_freq(), 3) ts.gen_interpolation() self.assertEqual(ts.s_freq("11", 2), Datapoint(2, 0.5, 0.5))
def test_load(self): ts = Touchstone("./test/data/valid.s1p") ts.load() self.assertEqual(str(ts.opts), "# HZ S RI R 50") self.assertEqual(len(ts.s11data), 1010) self.assertEqual(len(ts.s21data), 0) self.assertEqual(ts.r, 50) ts = Touchstone("./test/data/valid.s2p") ts.load() ts.gen_interpolation() self.assertEqual(str(ts.opts), "# HZ S RI R 50") self.assertEqual(len(ts.s11data), 1020) self.assertEqual(len(ts.s21data), 1020) self.assertEqual(len(ts.s12data), 1020) self.assertEqual(len(ts.s22data), 1020) self.assertIn("! Vector Network Analyzer VNA R2", ts.comments) self.assertEqual(ts.min_freq(), 500000) self.assertEqual(ts.max_freq(), 900000000) self.assertEqual(ts.s_freq("11", 1), Datapoint(1, -3.33238E-001, 1.80018E-004)) self.assertEqual( ts.s_freq("11", 750000), Datapoint(750000, -0.3331754099382822, 0.00032433255669243524)) ts = Touchstone("./test/data/ma.s2p") ts.load() self.assertEqual(str(ts.opts), "# MHZ S MA R 50") ts = Touchstone("./test/data/db.s2p") ts.load() self.assertEqual(str(ts.opts), "# HZ S DB R 50") ts = Touchstone("./test/data/broken_pair.s2p") with self.assertLogs(level=logging.ERROR) as cm: ts.load() self.assertRegex(cm.output[0], "Data values aren't pairs") ts = Touchstone("./test/data/missing_pair.s2p") with self.assertLogs(level=logging.ERROR) as cm: ts.load() self.assertRegex(cm.output[0], "Inconsistent number") ts = Touchstone("./test/data/nonexistent.s2p") with self.assertLogs(level=logging.ERROR) as cm: ts.load() self.assertRegex(cm.output[0], "No such file or directory")