| 1 |
""" |
| 2 |
this test on tests ability for all media class to pass construction |
| 3 |
of all general circuit components |
| 4 |
|
| 5 |
""" |
| 6 |
import unittest |
| 7 |
|
| 8 |
import numpy as np |
| 9 |
from scipy.constants import mil |
| 10 |
|
| 11 |
import skrf as rf |
| 12 |
from skrf.media import CPW, CircularWaveguide, Coaxial, DistributedCircuit, Freespace, MLine, RectangularWaveguide |
| 13 |
|
| 14 |
|
| 15 |
class MediaTestCase: |
| 16 |
"""Base class, contains tests for all media.""" |
| 17 |
def test_gamma(self): |
| 18 |
self.media.gamma |
| 19 |
|
| 20 |
def test_z0_value(self): |
| 21 |
self.media.z0 |
| 22 |
|
| 23 |
def test_mode_original_not_modified(self): |
| 24 |
|
| 25 |
network1 = self.media.delay_short(30, unit='deg') |
| 26 |
newmedia = self.media.mode(z0_port=1) |
| 27 |
network2 = self.media.delay_short(30, unit='deg') |
| 28 |
self.assertEqual(network1, network2) |
| 29 |
|
| 30 |
def test_match(self): |
| 31 |
self.media.match() |
| 32 |
|
| 33 |
def test_load(self): |
| 34 |
self.media.load(1) |
| 35 |
|
| 36 |
def test_short(self): |
| 37 |
self.media.short() |
| 38 |
|
| 39 |
def test_open(self): |
| 40 |
self.media.open() |
| 41 |
|
| 42 |
def test_capacitor(self): |
| 43 |
self.media.capacitor(1) |
| 44 |
|
| 45 |
def test_capacitor_q(self): |
| 46 |
self.media.capacitor_q(1, 2, 3) |
| 47 |
|
| 48 |
def test_inductor(self): |
| 49 |
self.media.inductor(1) |
| 50 |
|
| 51 |
def test_inductor_q(self): |
| 52 |
self.media.capacitor_q(1, 2, 3) |
| 53 |
|
| 54 |
def test_impedance_mismatch(self): |
| 55 |
self.media.impedance_mismatch(1, 2) |
| 56 |
|
| 57 |
def test_tee(self): |
| 58 |
self.media.tee() |
| 59 |
|
| 60 |
def test_splitter(self): |
| 61 |
self.media.splitter(4) |
| 62 |
|
| 63 |
def test_thru(self): |
| 64 |
self.media.thru() |
| 65 |
|
| 66 |
def test_line(self): |
| 67 |
self.media.line(1) |
| 68 |
|
| 69 |
def test_line_floating(self): |
| 70 |
self.media.line_floating(1) |
| 71 |
|
| 72 |
def test_delay_load(self): |
| 73 |
self.media.delay_load(1,2) |
| 74 |
|
| 75 |
def test_delay_short(self): |
| 76 |
self.media.delay_short(1) |
| 77 |
|
| 78 |
def test_delay_open(self): |
| 79 |
self.media.delay_open(1) |
| 80 |
|
| 81 |
def test_shunt_delay_load(self): |
| 82 |
self.media.shunt_delay_load(1,1) |
| 83 |
|
| 84 |
def test_shunt_delay_short(self): |
| 85 |
self.media.shunt_delay_short(1) |
| 86 |
|
| 87 |
def test_shunt_delay_open(self): |
| 88 |
self.media.shunt_delay_open(1) |
| 89 |
|
| 90 |
def test_shunt_capacitor(self): |
| 91 |
self.media.shunt_capacitor(1) |
| 92 |
|
| 93 |
def test_shunt_inductor(self): |
| 94 |
self.media.shunt_inductor(1) |
| 95 |
|
| 96 |
def test_Z0_deprecation_warning(self): |
| 97 |
with self.assertWarns(DeprecationWarning) as context: |
| 98 |
self.media.Z0 |
| 99 |
|
| 100 |
def test_embed_deprecation_warning(self): |
| 101 |
with self.assertWarns(DeprecationWarning) as context: |
| 102 |
self.media.line(1, unit = 'deg', embed = True) |
| 103 |
|
| 104 |
class Z0InitDeprecationTestCase(unittest.TestCase): |
| 105 |
def setUp(self): |
| 106 |
self.frequency = rf.Frequency(1,2,2,'GHz') |
| 107 |
|
| 108 |
def testZ0InitDeprecation(self): |
| 109 |
|
| 110 |
with self.assertWarns(DeprecationWarning) as context: |
| 111 |
cw = CircularWaveguide(self.frequency, z0 = 50) |
| 112 |
self.assertTrue(np.all(cw.z0 == 50)) |
| 113 |
with self.assertWarns(DeprecationWarning) as context: |
| 114 |
rw = RectangularWaveguide(self.frequency, z0 = 50) |
| 115 |
self.assertTrue(np.all(rw.z0 == 50)) |
| 116 |
|
| 117 |
with self.assertWarns(DeprecationWarning) as context: |
| 118 |
coax = Coaxial(self.frequency, z0 = 50) |
| 119 |
self.assertTrue(np.all(coax.z0 == 50)) |
| 120 |
with self.assertWarns(DeprecationWarning) as context: |
| 121 |
cpw = CPW(self.frequency, z0 = 50) |
| 122 |
self.assertTrue(np.all(cpw.z0 == 50)) |
| 123 |
with self.assertWarns(DeprecationWarning) as context: |
| 124 |
air = Freespace(self.frequency, z0 = 50) |
| 125 |
self.assertTrue(np.all(air.z0 == 50)) |
| 126 |
with self.assertWarns(DeprecationWarning) as context: |
| 127 |
mlin = MLine(self.frequency, z0 = 50) |
| 128 |
self.assertTrue(np.all(mlin.z0 == 50)) |
| 129 |
|
| 130 |
|
| 131 |
class FreespaceTestCase(MediaTestCase, unittest.TestCase): |
| 132 |
def setUp(self): |
| 133 |
self.frequency = rf.Frequency(75,110,101,'GHz') |
| 134 |
self.media = Freespace(self.frequency) |
| 135 |
|
| 136 |
def test_z0_value(self): |
| 137 |
self.assertEqual(round(\ |
| 138 |
self.media.z0[0].real), 377) |
| 139 |
|
| 140 |
|
| 141 |
class CPWTestCase(MediaTestCase, unittest.TestCase): |
| 142 |
def setUp(self): |
| 143 |
self.frequency = rf.Frequency(75,110,101,'GHz') |
| 144 |
self.media = CPW(\ |
| 145 |
frequency=self.frequency, |
| 146 |
w=10e-6, |
| 147 |
s=5e-6, |
| 148 |
ep_r=11.7, |
| 149 |
t=1e-6, |
| 150 |
rho=22e-9) |
| 151 |
|
| 152 |
|
| 153 |
class RectangularWaveguideTestCase(MediaTestCase, unittest.TestCase): |
| 154 |
def setUp(self): |
| 155 |
self.frequency = rf.Frequency(75,110,101,'GHz') |
| 156 |
self.media = RectangularWaveguide(\ |
| 157 |
frequency=self.frequency, |
| 158 |
a=100*mil, |
| 159 |
) |
| 160 |
|
| 161 |
|
| 162 |
class DistributedCircuitTestCase(MediaTestCase, unittest.TestCase): |
| 163 |
def setUp(self): |
| 164 |
self.frequency = rf.Frequency(75,110,101,'GHz') |
| 165 |
self.media = DistributedCircuit(\ |
| 166 |
frequency=self.frequency, |
| 167 |
L=1,C=1,R=0,G=0 |
| 168 |
) |
| 169 |
|
| 170 |
|
| 171 |
suite = unittest.TestSuite() |
| 172 |
loader = unittest.TestLoader() |
| 173 |
|
| 174 |
|
| 175 |
suite.addTests([\ |
| 176 |
loader.loadTestsFromTestCase(FreespaceTestCase), |
| 177 |
loader.loadTestsFromTestCase(CPWTestCase), |
| 178 |
loader.loadTestsFromTestCase(RectangularWaveguideTestCase), |
| 179 |
loader.loadTestsFromTestCase(DistributedCircuitTestCase), |
| 180 |
loader.loadTestsFromTestCase(Z0InitDeprecationTestCase), |
| 181 |
]) |
| 182 |
|
| 183 |
|
| 184 |
unittest.TextTestRunner(verbosity=2).run(suite) |