test_excellon.py 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. import unittest
  2. from flatcamParsers.ParseExcellon import Excellon
  3. from flatcamParsers.ParseGerber import Gerber
  4. class ExcellonNumberParseTestInch(unittest.TestCase):
  5. # Inch base format: 00.0000
  6. # LEADING ZEROS
  7. # With leading zeros, when you type in a coordinate,
  8. # the leading zeros must always be included. Trailing zeros
  9. # are unneeded and may be left off. The CNC-7 will automatically add them.
  10. # TRAILING ZEROS
  11. # You must show all zeros to the right of the number and can omit
  12. # all zeros to the left of the number. The CNC-7 will count the number
  13. # of digits you typed and automatically fill in the missing zeros.
  14. def test_inch_leading_6digit(self):
  15. excellon = Excellon()
  16. self.assertEqual(excellon.zeros, "L")
  17. self.assertEqual(excellon.parse_number("123456"), 12.3456)
  18. def test_inch_leading_5digit(self):
  19. excellon = Excellon()
  20. self.assertEqual(excellon.parse_number("12345"), 12.345)
  21. def test_inch_leading_15digit(self):
  22. excellon = Excellon()
  23. self.assertEqual(excellon.parse_number("012345"), 1.2345)
  24. def test_inch_leading_51digit(self):
  25. excellon = Excellon()
  26. self.assertEqual(excellon.parse_number("123450"), 12.345)
  27. def test_inch_trailing_6digit(self):
  28. excellon = Excellon()
  29. excellon.zeros = "T"
  30. self.assertEqual(excellon.parse_number("123456"), 12.3456)
  31. def test_inch_trailing_5digit(self):
  32. excellon = Excellon()
  33. excellon.zeros = "T"
  34. self.assertEqual(excellon.parse_number("12345"), 1.2345)
  35. def test_inch_trailing_15digit(self):
  36. excellon = Excellon()
  37. excellon.zeros = "T"
  38. self.assertEqual(excellon.parse_number("012345"), 1.2345)
  39. def test_inch_trailing_51digit(self):
  40. excellon = Excellon()
  41. excellon.zeros = "T"
  42. self.assertEqual(excellon.parse_number("123450"), 12.345)
  43. class ExcellonNumberParseTestMetric(unittest.TestCase):
  44. # Metric base format: 000.000
  45. # LEADING ZEROS
  46. # With leading zeros, when you type in a coordinate,
  47. # the leading zeros must always be included. Trailing zeros
  48. # are unneeded and may be left off. The CNC-7 will automatically add them.
  49. # TRAILING ZEROS
  50. # You must show all zeros to the right of the number and can omit
  51. # all zeros to the left of the number. The CNC-7 will count the number
  52. # of digits you typed and automatically fill in the missing zeros.
  53. def test_inch_leading_6digit(self):
  54. excellon = Excellon()
  55. excellon.units = "mm"
  56. self.assertEqual(excellon.parse_number("123456"), 123.456)
  57. def test_inch_leading_5digit(self):
  58. excellon = Excellon()
  59. excellon.units = "mm"
  60. self.assertEqual(excellon.parse_number("12345"), 123.45)
  61. def test_inch_leading_15digit(self):
  62. excellon = Excellon()
  63. excellon.units = "mm"
  64. self.assertEqual(excellon.parse_number("012345"), 12.345)
  65. def test_inch_leading_51digit(self):
  66. excellon = Excellon()
  67. excellon.units = "mm"
  68. self.assertEqual(excellon.parse_number("123450"), 123.45)
  69. def test_inch_trailing_6digit(self):
  70. excellon = Excellon()
  71. excellon.units = "mm"
  72. excellon.zeros = "T"
  73. self.assertEqual(excellon.parse_number("123456"), 123.456)
  74. def test_inch_trailing_5digit(self):
  75. excellon = Excellon()
  76. excellon.units = "mm"
  77. excellon.zeros = "T"
  78. self.assertEqual(excellon.parse_number("12345"), 12.345)
  79. def test_inch_trailing_15digit(self):
  80. excellon = Excellon()
  81. excellon.units = "mm"
  82. excellon.zeros = "T"
  83. self.assertEqual(excellon.parse_number("012345"), 12.345)
  84. def test_inch_trailing_51digit(self):
  85. excellon = Excellon()
  86. excellon.units = "mm"
  87. excellon.zeros = "T"
  88. self.assertEqual(excellon.parse_number("123450"), 123.45)
  89. class ExcellonFormatM72Test(unittest.TestCase):
  90. def setUp(self):
  91. self.excellon = Excellon()
  92. code = """
  93. M48
  94. M72
  95. T1C.02362F197S550
  96. T2C.03543F197S550
  97. M95
  98. T1
  99. X9000Y11750
  100. X30250Y10500
  101. """
  102. code = code.split('\n')
  103. self.excellon.parse_lines(code)
  104. def test_format(self):
  105. self.assertEqual(self.excellon.units.lower(), "in")
  106. self.assertEqual(self.excellon.zeros, "L")
  107. def test_coords(self):
  108. # For X9000 add the missing 00 on the right. Then divide by 10000.
  109. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (90.0, 11.75))
  110. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (30.25, 10.5))
  111. class ExcellonFormatM71Test(unittest.TestCase):
  112. def setUp(self):
  113. self.excellon = Excellon()
  114. code = """
  115. M48
  116. M71
  117. T1C.02362F197S550
  118. T2C.03543F197S550
  119. M95
  120. T1
  121. X9000Y11750
  122. X30250Y10500
  123. """
  124. code = code.split('\n')
  125. self.excellon.parse_lines(code)
  126. def test_format(self):
  127. self.assertEqual(self.excellon.units.lower(), "mm")
  128. self.assertEqual(self.excellon.zeros, "L")
  129. def test_coords(self):
  130. # For X9000 add the missing 00 on the right. Then divide by 10000.
  131. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (900.0, 117.5))
  132. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (302.5, 105.0))
  133. class ExcellonFormatINCHLZTest(unittest.TestCase):
  134. def setUp(self):
  135. self.excellon = Excellon()
  136. code = """
  137. M48
  138. INCH,LZ
  139. T1C.02362F197S550
  140. T2C.03543F197S550
  141. M95
  142. T1
  143. X9000Y11750
  144. X30250Y10500
  145. """
  146. code = code.split('\n')
  147. self.excellon.parse_lines(code)
  148. def test_format(self):
  149. self.assertEqual(self.excellon.units.lower(), "in")
  150. self.assertEqual(self.excellon.zeros, "L")
  151. def test_coords(self):
  152. # For X9000 add the missing 00 on the right. Then divide by 10000.
  153. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (90.0, 11.75))
  154. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (30.25, 10.5))
  155. class ExcellonFormatINCHTest(unittest.TestCase):
  156. def setUp(self):
  157. self.excellon = Excellon()
  158. code = """
  159. M48
  160. INCH,LZ
  161. T1C.02362F197S550
  162. T2C.03543F197S550
  163. M95
  164. T1
  165. X9000Y11750
  166. X30250Y10500
  167. """
  168. code = code.split('\n')
  169. self.excellon.parse_lines(code)
  170. def test_format(self):
  171. self.assertEqual(self.excellon.units.lower(), "in")
  172. self.assertEqual(self.excellon.zeros, "L")
  173. def test_coords(self):
  174. # For X9000 add the missing 00 on the right. Then divide by 10000.
  175. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (90.0, 11.75))
  176. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (30.25, 10.5))
  177. class ExcellonFormatINCHTZTest(unittest.TestCase):
  178. def setUp(self):
  179. self.excellon = Excellon()
  180. code = """
  181. M48
  182. INCH,TZ
  183. T1C.02362F197S550
  184. T2C.03543F197S550
  185. M95
  186. T1
  187. X9000Y11750
  188. X30250Y10500
  189. """
  190. code = code.split('\n')
  191. self.excellon.parse_lines(code)
  192. def test_format(self):
  193. self.assertEqual(self.excellon.units.lower(), "in")
  194. self.assertEqual(self.excellon.zeros, "T")
  195. def test_coords(self):
  196. # For X9000 add the missing 00 on the right. Then divide by 10000.
  197. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (0.9, 1.175))
  198. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (3.025, 1.05))
  199. class ExcellonFormatMETRICLZTest(unittest.TestCase):
  200. def setUp(self):
  201. self.excellon = Excellon()
  202. code = """
  203. M48
  204. METRIC,LZ
  205. T1C.02362F197S550
  206. T2C.03543F197S550
  207. M95
  208. T1
  209. X9000Y11750
  210. X30250Y10500
  211. """
  212. code = code.split('\n')
  213. self.excellon.parse_lines(code)
  214. def test_format(self):
  215. self.assertEqual(self.excellon.units.lower(), "mm")
  216. self.assertEqual(self.excellon.zeros, "L")
  217. def test_coords(self):
  218. # For X9000 add the missing 00 on the right. Then divide by 10000.
  219. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (900.0, 117.5))
  220. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (302.5, 105.0))
  221. class ExcellonFormatMETRICTest(unittest.TestCase):
  222. def setUp(self):
  223. self.excellon = Excellon()
  224. code = """
  225. M48
  226. METRIC,LZ
  227. T1C.02362F197S550
  228. T2C.03543F197S550
  229. M95
  230. T1
  231. X9000Y11750
  232. X30250Y10500
  233. """
  234. code = code.split('\n')
  235. self.excellon.parse_lines(code)
  236. def test_format(self):
  237. self.assertEqual(self.excellon.units.lower(), "mm")
  238. self.assertEqual(self.excellon.zeros, "L")
  239. def test_coords(self):
  240. # For X9000 add the missing 00 on the right. Then divide by 10000.
  241. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (900.0, 117.5))
  242. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (302.5, 105.0))
  243. class ExcellonFormatMETRICTZTest(unittest.TestCase):
  244. def setUp(self):
  245. self.excellon = Excellon()
  246. code = """
  247. M48
  248. METRIC,TZ
  249. T1C.02362F197S550
  250. T2C.03543F197S550
  251. M95
  252. T1
  253. X9000Y11750
  254. X30250Y10500
  255. """
  256. code = code.split('\n')
  257. self.excellon.parse_lines(code)
  258. def test_format(self):
  259. self.assertEqual(self.excellon.units.lower(), "mm")
  260. self.assertEqual(self.excellon.zeros, "T")
  261. def test_coords(self):
  262. # For X9000 add the missing 00 on the right. Then divide by 10000.
  263. self.assertEqual(self.excellon.drills[0]["point"].coords[0], (9.0, 11.75))
  264. self.assertEqual(self.excellon.drills[1]["point"].coords[0], (30.25, 10.5))
  265. if __name__ == '__main__':
  266. unittest.main()