Skip to content

Commit

Permalink
Improving coverage on asc_editor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nunobrum committed Aug 10, 2023
1 parent 646f829 commit 7bedf53
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
32 changes: 32 additions & 0 deletions unittests/golden/test_components_output_1.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Version 4
SHEET 1 880 680
WIRE 208 80 128 80
WIRE 288 80 208 80
WIRE 288 128 288 80
WIRE 128 192 128 80
WIRE 288 224 288 208
WIRE 368 224 288 224
WIRE 448 224 368 224
WIRE 288 240 288 224
WIRE 128 352 128 272
WIRE 288 352 288 320
WIRE 288 352 128 352
WIRE 448 352 448 288
WIRE 448 352 288 352
WIRE 128 368 128 352
FLAG 128 368 0
FLAG 368 224 out
FLAG 208 80 in
SYMBOL voltage 128 176 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
WINDOW 0 -82 53 Left 2
WINDOW 3 -85 83 Left 2
SYMATTR InstName Vin
SYMATTR Value 1
TEXT 56 488 Left 2 !.dc Vin 1 10 9
TEXT 56 440 Left 2 !.param res=10k
TEXT 120 400 Left 2 !.step temp 0 100 50
TEXT 408 400 Left 2 ;.step param res 1k 16k 5k
TEXT 56 512 Left 2 !.op
TEXT 296 488 Left 2 !.param temp = 0
20 changes: 20 additions & 0 deletions unittests/test_asc_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,47 @@ def setUp(self):
self.edt = PyLTSpice.editor.asc_editor.AscEditor(test_dir + "DC sweep.asc")

def test_component_editing(self):
golden = './golden/'
self.assertEqual(self.edt.get_component_value('R1'), '10k', "Tested R1 Value") # add assertion here
self.assertListEqual(self.edt.get_components(), ['Vin', 'R1', 'R2', 'D1'], "Tested get_components") # add assertion here
self.edt.set_component_value('R1', '33k')
self.edt.write_netlist(test_dir + 'test_components_output.asc')
self.equalFiles(test_dir + 'test_components_output.asc', golden + 'test_components_output.asc')
self.assertEqual(self.edt.get_component_value('R1'), '33k', "Tested R1 Value") # add assertion here
self.edt.remove_component('R1')
self.edt.write_netlist(test_dir + 'test_components_output_1.asc')
self.equalFiles(test_dir + 'test_components_output_1.asc', golden + 'test_components_output_1.asc')

def test_parameter_edit(self):
golden = './golden/'
self.assertEqual(self.edt.get_parameter('TEMP'), '0', "Tested TEMP Parameter") # add assertion here
self.edt.set_parameter('TEMP', 25)
self.assertEqual(self.edt.get_parameter('TEMP'), '25', "Tested TEMP Parameter") # add assertion here
self.edt.write_netlist(test_dir + 'test_parameter_output.asc')
self.equalFiles(test_dir + 'test_parameter_output.asc', golden + 'test_parameter_output.asc')
self.edt.set_parameter('TEMP', 0) # reset to 0
self.assertEqual(self.edt.get_parameter('TEMP'), '0.0', "Tested TEMP Parameter") # add assertion here

def test_instructions(self):
golden = './golden/'
self.edt.add_instruction('.ac dec 10 1 100k')
self.edt.add_instruction('.save V(vout)')
self.edt.add_instruction('.save I(R1)')
self.edt.add_instruction('.save I(R2)')
self.edt.add_instruction('.save I(D1)')
self.edt.write_netlist(test_dir + 'test_instructions_output.asc')
self.equalFiles(test_dir + 'test_instructions_output.asc', golden + 'test_instructions_output.asc')
self.edt.remove_instruction('.save I(R1)')
self.edt.write_netlist(test_dir + 'test_instructions_output_1.asc')
self.equalFiles(test_dir + 'test_instructions_output_1.asc', golden + 'test_instructions_output_1.asc')

def equalFiles(self, file1, file2):
with open(file1, 'r') as f1:
lines1 = f1.readlines()
with open(file2, 'r') as f2:
lines2 = f2.readlines()
for i, lines in enumerate(zip(lines1, lines2)):
self.assertEqual(lines[0], lines[1], "Line %d" % i)


if __name__ == '__main__':
Expand Down

0 comments on commit 7bedf53

Please sign in to comment.