Procházet zdrojové kódy

Added (passing) test for Excellon flow.

Juan Pablo Caram před 9 roky
rodič
revize
01c2feca98

+ 125 - 0
tests/excellon_files/case1.drl

@@ -0,0 +1,125 @@
+M48
+INCH
+T01C0.0200
+T02C0.0800
+T03C0.0600
+T04C0.0300
+T05C0.0650
+T06C0.0450
+T07C0.0400
+T08C0.1181
+T09C0.0500
+%
+T01
+X-018204Y+015551
+X-025842Y+015551
+T02
+X-000118Y+020629
+X-000118Y+016889
+X+012401Y+020629
+X+012401Y+016889
+X-010170Y+002440
+X-010110Y+011470
+X+018503Y+026574
+T03
+X+013060Y+010438
+X+013110Y+000000
+X-049015Y+002165
+X+018378Y+010433
+X+018317Y+000000
+X-049015Y+010039
+X-041141Y-000629
+X-041181Y+012992
+X-056496Y+012992
+X-056496Y-000590
+T04
+X-037560Y+030490
+X-036560Y+030490
+X-035560Y+030490
+X-034560Y+030490
+X-033560Y+030490
+X-032560Y+030490
+X-031560Y+030490
+X-030560Y+030490
+X-029560Y+030490
+X-028560Y+030490
+X-027560Y+030490
+X-026560Y+030490
+X-025560Y+030490
+X-024560Y+030490
+X-024560Y+036490
+X-025560Y+036490
+X-026560Y+036490
+X-027560Y+036490
+X-028560Y+036490
+X-029560Y+036490
+X-030560Y+036490
+X-031560Y+036490
+X-032560Y+036490
+X-033560Y+036490
+X-034560Y+036490
+X-035560Y+036490
+X-036560Y+036490
+X-037560Y+036490
+X-014590Y+030810
+X-013590Y+030810
+X-012590Y+030810
+X-011590Y+030810
+X-011590Y+033810
+X-012590Y+033810
+X-013590Y+033810
+X-014590Y+033810
+X-021260Y+034680
+X-020010Y+034680
+X-008390Y+035840
+X-008390Y+034590
+X-008440Y+031870
+X-008440Y+030620
+T05
+X-022504Y+019291
+X-020354Y+019291
+X-018204Y+019291
+X-030142Y+019291
+X-027992Y+019291
+X-025842Y+019291
+X-012779Y+019291
+X-010629Y+019291
+X-008479Y+019291
+T06
+X-028080Y+028230
+X-030080Y+028230
+X-034616Y+024409
+X-039616Y+024409
+X-045364Y+023346
+X-045364Y+018346
+X-045364Y+030157
+X-045364Y+025157
+X-008604Y+026983
+X-013604Y+026983
+X-016844Y+034107
+X-016844Y+029107
+T07
+X-041655Y+026456
+X-040655Y+026456
+X-039655Y+026456
+X-041640Y+022047
+X-040640Y+022047
+X-039640Y+022047
+X-049760Y+029430
+X-048760Y+029430
+X-047760Y+029430
+X-019220Y+037380
+X-020220Y+037380
+X-021220Y+037380
+T08
+X-024212Y+007751
+X-024212Y+004011
+X-035629Y+007874
+X-035629Y+004133
+T09
+X+007086Y+030708
+X+007086Y+032874
+X-000787Y+031889
+X-000787Y+035826
+X-000787Y+027952
+M30

+ 163 - 0
tests/test_excellon_flow.py

@@ -0,0 +1,163 @@
+import unittest
+from PyQt4 import QtGui
+import sys
+from FlatCAMApp import App
+from FlatCAMObj import FlatCAMExcellon, FlatCAMCNCjob
+from ObjectUI import ExcellonObjectUI
+import tempfile
+import os
+from time import sleep
+
+
+class ExcellonFlowTestCase(unittest.TestCase):
+    """
+    This is a top-level test covering the Excellon-to-GCode
+    generation workflow.
+
+    THIS IS A REQUIRED TEST FOR ANY UPDATES.
+
+    """
+
+    filename = 'case1.drl'
+
+    def setUp(self):
+        self.app = QtGui.QApplication(sys.argv)
+
+        # Create App, keep app defaults (do not load
+        # user-defined defaults).
+        self.fc = App(user_defaults=False)
+
+        self.fc.open_excellon('tests/excellon_files/' + self.filename)
+
+    def tearDown(self):
+        del self.fc
+        del self.app
+
+    def test_flow(self):
+        # Names of available objects.
+        names = self.fc.collection.get_names()
+        print names
+
+        #--------------------------------------
+        # Total of 1 objects.
+        #--------------------------------------
+        self.assertEquals(len(names), 1,
+                          "Expected 1 object, found %d" % len(names))
+
+        #--------------------------------------
+        # Object's name matches the file name.
+        #--------------------------------------
+        self.assertEquals(names[0], self.filename,
+                          "Expected name == %s, got %s" % (self.filename, names[0]))
+
+        #---------------------------------------
+        # Get object by that name, make sure it's a FlatCAMExcellon.
+        #---------------------------------------
+        excellon_name = names[0]
+        excellon_obj = self.fc.collection.get_by_name(excellon_name)
+        self.assertTrue(isinstance(excellon_obj, FlatCAMExcellon),
+                        "Expected FlatCAMExcellon, instead, %s is %s" %
+                        (excellon_name, type(excellon_obj)))
+
+        #----------------------------------------
+        # Object's GUI matches Object's options
+        #----------------------------------------
+        # TODO: Open GUI with double-click on object.
+        # Opens the Object's GUI, populates it.
+        excellon_obj.build_ui()
+        for option, value in excellon_obj.options.iteritems():
+            try:
+                form_field = excellon_obj.form_fields[option]
+            except KeyError:
+                print ("**********************************************************\n"
+                       "* WARNING: Option '{}' has no form field\n"
+                       "**********************************************************"
+                       "".format(option))
+                continue
+            self.assertEqual(value, form_field.get_value(),
+                             "Option '{}' == {} but form has {}".format(
+                                 option, value, form_field.get_value()
+                             ))
+
+        #--------------------------------------------------
+        # Changes in the GUI should be read in when
+        # running any process. Changing something here.
+        #--------------------------------------------------
+
+        form_field = excellon_obj.form_fields['feedrate']
+        value = form_field.get_value()
+        form_field.set_value(value * 1.1)  # Increase by 10%
+        print "'feedrate' == {}".format(value)
+
+        #--------------------------------------------------
+        # Create GCode using all tools.
+        #--------------------------------------------------
+
+        assert isinstance(excellon_obj, FlatCAMExcellon)  # Just for the IDE
+        ui = excellon_obj.ui
+        assert isinstance(ui, ExcellonObjectUI)
+        ui.tools_table.selectAll()  # Select All
+        ui.generate_cnc_button.click()  # Click
+
+        # Work is done in a separate thread and results are
+        # passed via events to the main event loop which is
+        # not running. Run only for pending events.
+        #
+        # I'm not sure why, but running it only once does
+        # not catch the new object. Might be a timing issue.
+        # http://pyqt.sourceforge.net/Docs/PyQt4/qeventloop.html#details
+        for _ in range(2):
+            sleep(0.1)
+            self.app.processEvents()
+
+        #---------------------------------------------
+        # Check that GUI has been read in.
+        #---------------------------------------------
+
+        value = excellon_obj.options['feedrate']
+        form_value = form_field.get_value()
+        self.assertEqual(value, form_value,
+                         "Form value for '{}' == {} was not read into options"
+                         "which has {}".format('feedrate', form_value, value))
+        print "'feedrate' == {}".format(value)
+
+        #---------------------------------------------
+        # Check that only 1 object has been created.
+        #---------------------------------------------
+
+        names = self.fc.collection.get_names()
+        self.assertEqual(len(names), 2,
+                         "Expected 2 objects, found %d" % len(names))
+
+        #-------------------------------------------------------
+        # Make sure the CNCJob Object has the correct name
+        #-------------------------------------------------------
+
+        cncjob_name = excellon_name + "_cnc"
+        self.assertTrue(cncjob_name in names,
+                        "Object named %s not found." % cncjob_name)
+
+        #-------------------------------------------------------
+        # Get the object make sure it's a cncjob object
+        #-------------------------------------------------------
+
+        cncjob_obj = self.fc.collection.get_by_name(cncjob_name)
+        self.assertTrue(isinstance(cncjob_obj, FlatCAMCNCjob),
+                        "Expected a FlatCAMCNCjob, got %s" % type(cncjob_obj))
+
+        #-----------------------------------------
+        # Export G-Code, check output
+        #-----------------------------------------
+        assert isinstance(cncjob_obj, FlatCAMCNCjob)  # For IDE
+
+        # get system temporary file(try create it and delete)
+        with tempfile.NamedTemporaryFile(prefix='unittest.',
+                                         suffix="." + cncjob_name + '.gcode',
+                                         delete=True) as tmp_file:
+            output_filename = tmp_file.name
+
+        cncjob_obj.export_gcode(output_filename)
+        self.assertTrue(os.path.isfile(output_filename))
+        os.remove(output_filename)
+
+        print names

+ 11 - 2
tests/test_gerber_flow.py

@@ -10,6 +10,13 @@ import tempfile
 
 
 class GerberFlowTestCase(unittest.TestCase):
+    """
+    This is a top-level test covering the Gerber-to-GCode
+    generation workflow.
+
+    THIS IS A REQUIRED TEST FOR ANY UPDATES.
+
+    """
 
     filename = 'simple1.gbr'
 
@@ -172,10 +179,12 @@ class GerberFlowTestCase(unittest.TestCase):
         assert isinstance(cnc_obj, FlatCAMCNCjob)
         output_filename = ""
         # get system temporary file(try create it and  delete also)
-        with tempfile.NamedTemporaryFile(prefix='unittest.', suffix="." + cnc_name + '.gcode', delete=True) as tmp_file:
+        with tempfile.NamedTemporaryFile(prefix='unittest.',
+                                         suffix="." + cnc_name + '.gcode',
+                                         delete=True) as tmp_file:
             output_filename = tmp_file.name
         cnc_obj.export_gcode(output_filename)
         self.assertTrue(os.path.isfile(output_filename))
         os.remove(output_filename)
 
-        print names
+        print names