You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.5 KiB
69 lines
1.5 KiB
"""Shared test fixtures for pyngspice tests."""
|
|
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
# Ensure repo root is on path for editable installs
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_workdir():
|
|
"""Provide a temporary working directory, cleaned up after the test."""
|
|
with tempfile.TemporaryDirectory() as d:
|
|
yield d
|
|
|
|
|
|
@pytest.fixture
|
|
def rc_netlist(tmp_workdir):
|
|
"""Write a simple RC circuit netlist and return its path."""
|
|
path = os.path.join(tmp_workdir, "rc.cir")
|
|
with open(path, "w") as f:
|
|
f.write("""RC Test Circuit
|
|
V1 in 0 DC 1
|
|
R1 in out 1k
|
|
C1 out 0 1u
|
|
.tran 0.1m 10m
|
|
.end
|
|
""")
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def inductor_rser_netlist(tmp_workdir):
|
|
"""Write a netlist with LTspice-style Rser= on inductors."""
|
|
path = os.path.join(tmp_workdir, "inductor_rser.cir")
|
|
with open(path, "w") as f:
|
|
f.write("""Tesla Coil Primary
|
|
V1 drive 0 SIN(0 100 250000)
|
|
L1 drive tank 8.5u Rser=0.012
|
|
C1 tank 0 100n
|
|
L2 tank sec 500u Rser=2.5
|
|
R_load sec 0 50
|
|
.tran 0.1u 100u
|
|
.backanno
|
|
.end
|
|
""")
|
|
return path
|
|
|
|
|
|
@pytest.fixture
|
|
def tesla_coil_netlist(tmp_workdir):
|
|
"""Write a Tesla coil netlist with .options savecurrents and Rser=."""
|
|
path = os.path.join(tmp_workdir, "tesla_coil.cir")
|
|
with open(path, "w") as f:
|
|
f.write("""Tesla Coil AC Analysis
|
|
V1 vin 0 AC 1
|
|
C_mmc vin p1 0.03u
|
|
L1 p1 0 10.927u Rser=0.001
|
|
L2 0 top 15.987m Rser=0.001
|
|
C_topload top 0 13.822p
|
|
K1 L1 L2 0.3204
|
|
.options savecurrents
|
|
.ac dec 100 1k 3meg
|
|
.end
|
|
""")
|
|
return path
|