test_excellon.py 10.0 KB

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