test.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #import unittest
  2. import kicommand
  3. #.run as kc
  4. import platform
  5. import sys
  6. import pcbnew
  7. if platform.python_version() < '2.7':
  8. unittest = __import__('unittest2')
  9. else:
  10. import unittest
  11. if True:#__name__ == '__main__':
  12. testsuite = unittest.TestLoader().discover('kicommand.test',pattern="test_*.py")
  13. results = unittest.TextTestRunner(verbosity=100).run(testsuite)
  14. # Return an error code if any of the testsuite tests fail
  15. # if not results.wasSuccessful():
  16. # sys.exit(1)
  17. class TestKiCommand(unittest.TestCase):
  18. def test_load(self):
  19. pcommands = ['moduletextobj', 'wxpoint', 'outlinetoptext', 'setselect', 'referencetextobj', 'outlinepads', 'valuetextobj', 'drawparams', 'textfromobj', 'referencetext', 'toptextobj', 'outlinetext', 'clearallselected', 'not', 'orthogonal', 'copy', 'clearselect', 'texttosegments', 'valuetext']
  20. self.assertTrue(set(pcommands) <= set(kicommand.kicommand._dictionary['persist'].keys()))
  21. self.assertFalse(set(['thiscommand doesnt exist']) < set(kicommand.kicommand._dictionary['persist'].keys()))
  22. def test_mils_mil_mm(self):
  23. result = kicommand.run('10 mm')
  24. self.assertEqual(result,10*pcbnew.IU_PER_MM)
  25. result = kicommand.run('10 mils')
  26. self.assertEqual(result,10*pcbnew.IU_PER_MILS)
  27. result = kicommand.run('10 mil')
  28. self.assertEqual(result,10*pcbnew.IU_PER_MILS)
  29. def test_drawsegments(self):
  30. result = kicommand.run('clear 0,0,1,1 mm drawpoly',returnval=-1)
  31. self.assertEqual(len(result),1)
  32. self.assertEqual(len(result[0]),1)
  33. # Test single list of list of numbers:
  34. result = kicommand.run('delist remove',returnval=-1)
  35. self.assertEqual(result,[])
  36. result = kicommand.run('clear 0,0,1,1 mm list drawpoly',returnval=-1)
  37. self.assertEqual(len(result),1)
  38. self.assertEqual(len(result[0][0]),1)
  39. result = kicommand.run('delist remove',returnval=-1)
  40. self.assertEqual(result,[])
  41. # Test single list of numbers:
  42. result = kicommand.run('clear 0,0,1,1,2,2,3,3 mm list drawpoly',returnval=-1)
  43. self.assertEqual(len(result),1)
  44. self.assertEqual(len(result[0][0]),3)
  45. result = kicommand.run('delist remove',returnval=-1)
  46. self.assertEqual(result,[])
  47. # Test two lists of numbers:
  48. result = kicommand.run('clear 0,0,1,1 mm list 2,2,3,3 mm list append drawpoly',returnval=-1)
  49. self.assertEqual(len(result),1)
  50. self.assertEqual(len(result[0][0]),1)
  51. self.assertEqual(len(result[0][1]),1)
  52. result = kicommand.run('copy 1 index remove 0 index remove',returnval=-1)
  53. self.assertEqual(result,[])
  54. result = kicommand.run('clear 0,0,1000000,1000000 ,2000000,2000000,3000000,3000000 append drawpoly',returnval=-1)
  55. self.assertEqual(len(result),1)
  56. self.assertEqual(len(result[0][0]),3)
  57. result = kicommand.run('delist remove',returnval=-1)
  58. self.assertEqual(result,[])
  59. result = kicommand.run('clear 0,0,1000000,1000000,2000000,2000000,3000000,3000000 drawpoly',returnval=-1)
  60. self.assertEqual(len(result),1)
  61. self.assertEqual(len(result[0][0]),3)
  62. result = kicommand.run('delist remove',returnval=-1)
  63. self.assertEqual(result,[])
  64. result = kicommand.run('clear 0,0,1000000,1000000 list 2000000,2000000,3000000,3000000 list append drawpoly',returnval=-1)
  65. self.assertEqual(len(result),1)
  66. self.assertEqual(len(result[0][0]),1)
  67. self.assertEqual(len(result[0][1]),1)
  68. result = kicommand.run('copy 1 index remove 0 index remove',returnval=-1)
  69. self.assertEqual(result,[])
  70. result = kicommand.run('clear 0,0 mm wxpoint 1,1 mm wxpoint append 2,2 mm wxpoint append 3,3 mm wxpoint append drawpoly',returnval=-1)
  71. self.assertEqual(len(result),1)
  72. self.assertEqual(len(result[0][0]),3)
  73. result = kicommand.run('delist remove',returnval=-1)
  74. self.assertEqual(result,[])
  75. result = kicommand.run('clear 0,0 mm wxpoint 1,1 mm wxpoint append list 2,2 mm wxpoint 3,3 mm wxpoint append list append drawpoly',returnval=-1)
  76. self.assertEqual(len(result),1)
  77. self.assertEqual(len(result[0][0]),1)
  78. self.assertEqual(len(result[0][1]),1)
  79. result = kicommand.run('copy 1 index remove 0 index remove',returnval=-1)
  80. self.assertEqual(result,[])
  81. def test_help_helpcat_explain_see_seeall(self):
  82. result = kicommand.run("help All helpcat 'help explain seeall 'bool see",returnval=-1)
  83. self.assertEqual(result,[])
  84. def test_coverage(self):
  85. prefix = 'test_'
  86. fulltestnames = filter(lambda x: x.startswith(prefix),dir(self))
  87. testnames = set()
  88. #testnames = set(map(lambda x: x[len(prefix):],fulltestnames))
  89. set(map(lambda x: testnames.update(x.split('_')),fulltestnames))
  90. untested = set(kicommand.kicommand._dictionary['command'].keys()) - testnames
  91. print 'untested',untested
  92. self.assertEqual(True,True)
  93. #unittest.main()
  94. # The following lines enable testing from pcbnew Script Console
  95. # just "import kicommand_test" and you can view the output in the
  96. # Script Console window.
  97. suite = unittest.TestLoader().loadTestsFromTestCase(TestKiCommand)
  98. unittest.TextTestRunner(verbosity=2).run(suite)
  99. # from kicommand_test import test_001_pcb_kicad