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.

85 lines
2.4 KiB

  1. #!/usr/bin/python
  2. # Test the KiCad plugin regarding some expected features.
  3. # 1) Build target _pcbnew after enabling scripting in cmake.
  4. # $ make _pcbnew
  5. # 2) Changed dir to pcbnew
  6. # $ cd pcbnew
  7. # $ pwd
  8. # build/pcbnew
  9. # 3) Entered following command line, script takes no arguments
  10. # $ PYTHONPATH=. <path_to>/test_kicad_plugin.py
  11. from pcbnew import IO_MGR, BOARD, MODULE, FPID, UTF8
  12. from os import rename as mv
  13. tmp_path = '/tmp'
  14. lib_path1 = "%s/lib1.pretty" % tmp_path
  15. lib_path2 = "%s/lib2.pretty" % tmp_path
  16. plugin = IO_MGR.PluginFind( IO_MGR.KICAD )
  17. # Expecting "KiCad":
  18. print( "Plugin Type: %s" % plugin.PluginName() )
  19. try:
  20. plugin.FootprintLibDelete( lib_path1 )
  21. except:
  22. pass # ignore, new may not exist if first run
  23. try:
  24. plugin.FootprintLibDelete( lib_path2 )
  25. except:
  26. pass # ignore, new may not exist if first run
  27. plugin.FootprintLibCreate( lib_path1 )
  28. # Verify that the same plugin instance can edge trigger on a lib_path change
  29. # for a FootprintLibCreate()
  30. plugin.FootprintLibCreate( lib_path2 )
  31. board = BOARD()
  32. # The only way to construct a MODULE is to pass it a BOARD? Yep.
  33. module = MODULE( board )
  34. fpid = FPID( 'mine' )
  35. module.SetFPID( fpid )
  36. plugin.FootprintSave( lib_path2, module )
  37. # Verify that the same plugin instance can edge trigger on a lib_path change
  38. # for a FootprintSave()
  39. plugin.FootprintSave( lib_path1, module )
  40. # create a disparity between the library's name ("footprint"),
  41. # and the module's internal useless name ("mine"). Module is officially named "footprint" now
  42. # but has (module mine ...) internally:
  43. mv( "%s/mine.kicad_mod" % lib_path2, "%s/footprint.kicad_mod" % lib_path2 )
  44. footprint = plugin.FootprintLoad( lib_path2, 'footprint' )
  45. fpid = footprint.GetFPID()
  46. fpid.SetLibNickname( UTF8( 'mylib' ) )
  47. name = fpid.Format().GetChars() # example to get the UTF8 char buffer
  48. # Always after a FootprintLoad() the internal name should match the one used to load it.
  49. print( "Internal name should be 'footprint': '%s'" % name )
  50. # Verify that the same plugin instance can edge trigger on a lib_path change
  51. # for FootprintLoad()
  52. footprint = plugin.FootprintLoad( lib_path1, 'mine' )
  53. fpid = footprint.GetFPID()
  54. fpid.SetLibNickname( UTF8( 'other_mylib' ) )
  55. # Always after a FootprintLoad() the internal name should match the one used to load it.
  56. # Example to print an UTF8 string
  57. print( "Internal name should be 'mine': '%s'" % fpid.Format() )
  58. # As of 3-Dec-2013 this test is passed by KICAD_PLUGIN and Wayne is owed an atta boy!