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.

72 lines
2.8 KiB

  1. import code
  2. import unittest
  3. import pcbnew
  4. import pdb
  5. class TestPCBLoad(unittest.TestCase):
  6. def setUp(self):
  7. self.pcb = pcbnew.LoadBoard("data/pcbnew/complex_hierarchy.kicad_pcb")
  8. def test_pcb_load(self):
  9. self.assertNotEqual(self.pcb,None)
  10. def test_pcb_track_count(self):
  11. tracks = list(self.pcb.GetTracks())
  12. self.assertEqual(len(tracks),361)
  13. def test_pcb_modules(self):
  14. modules = list(self.pcb.GetFootprints())
  15. self.assertEqual(len(modules), 72)
  16. def test_pcb_module_references(self):
  17. board_refs = list(module.GetReference() for
  18. module in self.pcb.GetFootprints())
  19. known_refs = [u'P1', u'P3', u'C2', u'C1', u'D1', u'Q3', u'Q5', u'Q7',
  20. u'Q6', u'Q1', u'Q2', u'Q4', u'Q8', u'P2', u'U1', u'U4',
  21. u'P4', u'P5', u'P6', u'U3', u'R9', u'R15', u'RV1', u'RV2',
  22. u'C3', u'C4', u'C5', u'C6', u'C7', u'C8', u'C9', u'D2',
  23. u'D3', u'D4', u'D5', u'D6', u'D7', u'R3', u'R4', u'R5',
  24. u'R6', u'R7', u'R8', u'R10', u'R11', u'R12', u'R13',
  25. u'R14', u'R16', u'R17', u'R18', u'R19', u'R20', u'R21',
  26. u'R22', u'MIRE', u'C10', u'C11',
  27. u'U2', u'C14', u'C12', u'R23', u'R24', u'D9', u'D8', u'R25',
  28. u'R26', u'R27', u'R28']
  29. for ref in known_refs:
  30. self.assertTrue(ref in board_refs)
  31. def test_pcb_netcount(self):
  32. self.assertEqual(self.pcb.GetNetCount(),51)
  33. def test_pcb_shapes(self):
  34. drawings = list(self.pcb.GetDrawings())
  35. edge_cuts = [d for d in drawings if d.GetLayer() == pcbnew.Edge_Cuts]
  36. coordinates = [[list(edge.GetStart()), list(edge.GetEnd())] for edge in edge_cuts]
  37. expected_coordinates = [
  38. [[88265000, 51816000], [188595000, 51816000]],
  39. [[88265000, 131826000], [88265000, 51816000]],
  40. [[188595000, 51816000], [188595000, 131826000]],
  41. [[188595000, 131826000], [88265000, 131826000]]
  42. ]
  43. self.assertEqual(sorted(coordinates), sorted(expected_coordinates))
  44. def test_pcb_text(self):
  45. drawings = list(self.pcb.GetDrawings())
  46. text = [d for d in drawings if d.GetClass() == "PCB_TEXT"]
  47. self.verify_text(text[0], 173355000, 68453000, pcbnew.F_Cu,
  48. u'Actionneur\nPiezo New Amp\nV02')
  49. self.verify_text(text[1], 176149000, 64643000, pcbnew.B_Cu,
  50. u'Actionneur\nPiezo New Amp\nV02')
  51. def verify_text(self, text, x, y, layer, s):
  52. self.assertEquals(list(text.GetPosition()), [x, y])
  53. self.assertEquals(text.GetLayer(), layer)
  54. self.assertEquals(text.GetText(), s)
  55. #def test_interactive(self):
  56. # code.interact(local=locals())
  57. if __name__ == '__main__':
  58. unittest.main()