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.6 KiB
69 lines
1.6 KiB
"""Basic simulation test for pyngspice (moved from root test_sim.py)."""
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
from pyngspice import _cpp_available
|
|
|
|
|
|
@pytest.mark.skipif(not _cpp_available, reason="C++ extension not built")
|
|
def test_simulator_basic():
|
|
"""Test the low-level Simulator class with a simple RC circuit."""
|
|
from pyngspice import Simulator
|
|
|
|
sim = Simulator()
|
|
sim.initialize()
|
|
assert sim.is_initialized()
|
|
|
|
netlist = """RC Test Circuit
|
|
V1 in 0 DC 1
|
|
R1 in out 1k
|
|
C1 out 0 1u
|
|
.tran 0.1m 10m
|
|
.end
|
|
"""
|
|
|
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.cir', delete=False) as f:
|
|
f.write(netlist)
|
|
netlist_path = f.name
|
|
|
|
try:
|
|
sim.load_netlist(netlist_path)
|
|
sim.run()
|
|
|
|
plots = sim.all_plots()
|
|
assert len(plots) > 0
|
|
|
|
vectors = sim.all_vectors(plots[0])
|
|
assert len(vectors) > 0
|
|
finally:
|
|
os.unlink(netlist_path)
|
|
|
|
|
|
@pytest.mark.skipif(not _cpp_available, reason="C++ extension not built")
|
|
def test_simrunner_basic():
|
|
"""Test the SimRunner class with a simple RC circuit."""
|
|
from pyngspice import SimRunner, RawRead
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
netlist_path = os.path.join(tmpdir, "rc.cir")
|
|
with open(netlist_path, "w") as f:
|
|
f.write("""RC Test
|
|
V1 in 0 DC 1
|
|
R1 in out 1k
|
|
C1 out 0 1u
|
|
.tran 0.1m 10m
|
|
.end
|
|
""")
|
|
|
|
runner = SimRunner(output_folder=tmpdir)
|
|
raw_file, log_file = runner.run_now(netlist_path)
|
|
|
|
assert os.path.isfile(raw_file)
|
|
|
|
raw = RawRead(raw_file)
|
|
traces = raw.get_trace_names()
|
|
assert len(traces) > 0
|
|
assert raw.num_points > 0
|