def test_getSpiceModelForPart(self): inputData = self.singleTransistorSchematic() circuit = eagleSchematic.EagleSchematic(inputData) transistor = circuit.parts['Q1'] spiceData = transistor.getSpiceModel() self.assertEqual(spiceData, ".model BC547 NPN ()")
def test_getDeviceForPart(self): inputData = self.singleTransistorSchematic() circuit = eagleSchematic.EagleSchematic(inputData) transistor = circuit.parts['Q1'] attributes = transistor.attributes self.assertEqual(len(attributes), 3)
def test_getSpiceNetlistForPart(self): inputData = self.singleTransistorSchematic() circuit = eagleSchematic.EagleSchematic(inputData) transistor = circuit.parts['Q1'] spiceData = transistor.getSpiceNetlist() self.assertEqual(spiceData, "QQ1 COLLECTOR BASE EMITTER BC547")
def test_extractSingleDeviceCorrectly(self): inputData = self.singleTransistorSchematic() circuit = eagleSchematic.EagleSchematic(inputData) devices = circuit.parts self.assertEqual(len(devices), 1) self.assertEqual(devices['Q1'].devicesetName, 'TRANSISTOR-NPN-GENERIC')
def test_extractSinglePartCorrectly(self): inputData = self.singleTransistorSchematic() circuit = eagleSchematic.EagleSchematic(inputData) parts = circuit.parts self.assertEqual(len(parts), 1) self.assertEqual(parts['Q1'].name, 'Q1')
def test_readingAndWritingToFileShouldStayTheSame(self): self.maxDiff = None inputData = resource_string( 'test', 'testRessources/replacementExamples/singleDiode.sch') baseSchematic = eagleSchematic.EagleSchematic(inputData) originalFile = self.prettifyXML(inputData) savedFile = baseSchematic.toString() self.assertEqual(originalFile, savedFile)
def test_getNetMapForPart(self): inputData = self.singleTransistorSchematic() circuit = eagleSchematic.EagleSchematic(inputData) transistor = circuit.parts['Q1'] netMap = transistor.netMap self.assertEqual(len(netMap.keys()), 3) self.assertEqual(netMap['COLLECTOR'], 'COLLECTOR') self.assertEqual(netMap['BASE'], 'BASE') self.assertEqual(netMap['EMITTER'], 'EMITTER')
def test_shouldReturnCorrectTranslationAndRotation(self): inputData = self.getSchematic('transistorAndResistor.sch') circuit = eagleSchematic.EagleSchematic(inputData) transistor = circuit.parts['Q1'] resistor = circuit.parts['R1'] self.assertEqual(transistor.getRotation(), 0) self.assertEqual(resistor.getRotation(), 90) self.assertEqual(transistor.getPosition(), (53.34, 43.18)) self.assertEqual(resistor.getPosition(), (53.34, 55.88))
def test_shouldNotCreateSupplyForGNDNode(self): inputData = self.getSchematic('transistorAndResistorWithSupply.sch') circuit = eagleSchematic.EagleSchematic(inputData) negativeSupply = circuit.parts['GND1'] spiceModel = negativeSupply.getSpiceModel() spiceNet = negativeSupply.getSpiceNetlist() spiceSupply = negativeSupply.getSpiceSupply() self.assertEqual(spiceModel, None) self.assertEqual(spiceNet, None) self.assertEqual(spiceSupply, None)
def test_getSpiceModelForSupplyPart(self): inputData = self.getSchematic('transistorAndResistorWithSupply.sch') circuit = eagleSchematic.EagleSchematic(inputData) positiveSupply = circuit.parts['P+1'] spiceModel = positiveSupply.getSpiceModel() spiceNet = positiveSupply.getSpiceNetlist() spiceSupply = positiveSupply.getSpiceSupply() self.assertEqual(spiceModel, None) self.assertEqual(spiceNet, None) self.assertEqual(spiceSupply, "VP5V +5V GND dc +5V ac 0V")
def test_shouldNotCreateModelForUnknowNode(self): inputData = self.getSchematic( 'transistorAndResistorWithSupplyAndTestPoint.sch') circuit = eagleSchematic.EagleSchematic(inputData) testPoint = circuit.parts['TP1'] spiceModel = testPoint.getSpiceModel() spiceNet = testPoint.getSpiceNetlist() spiceSupply = testPoint.getSpiceSupply() self.assertEqual(spiceModel, None) self.assertEqual(spiceNet, None) self.assertEqual(spiceSupply, None)
def test_shouldCreateSubCircuitForModelWithSubCircuit(self): inputData = self.getSchematic('relayWithSubCircuit.sch') circuit = eagleSchematic.EagleSchematic(inputData) relay = circuit.parts['RELAY1'] spiceModel = relay.getSpiceModel() spiceNet = relay.getSpiceNetlist() spiceSupply = relay.getSpiceSupply() spiceSubCircuit = relay.getSpiceSubCircuit() self.assertEqual(spiceModel, None) self.assertEqual(spiceNet, 'xRELAY1 NOP CENT NCL NPOS NNEG basicRelay') self.assertEqual(spiceSupply, None) self.assertEqual( spiceSubCircuit, ".subckt basicRelay 1 2 3 4 5\nSOpen 1 2 4 5 SW_OPEN on\nSClosed 2 3 4 5 SW_CLOSED on\n.model SW_OPEN SW(Ron=.1 Roff=1Meg Vt=6 )\n.model SW_CLOSED SW(Ron=1Meg Roff=.1 Vt=6 )\n.ends" )
def getSchematic(self, schematic): inputData = resource_string( 'test', 'testRessources/replacementExamples/' + schematic + '.sch') return eagleSchematic.EagleSchematic(inputData)
def openSchematic(filename): file = open(filename, "r") return eagleSchematic.EagleSchematic(file.read())