def setUp(self): self.app = QtGui.QApplication(sys.argv) apply_patches() # Create App, keep app defaults (do not load # user-defined defaults). self.fc = App() self.fc.log.setLevel(logging.ERROR)
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_gerber('tests/gerber_files/' + self.filename)
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.filename = 'drawing.svg'
class VisPyPlotCase(unittest.TestCase): """ This is a top-level test covering the Gerber-to-GCode generation workflow. THIS IS A REQUIRED TEST FOR ANY UPDATES. """ filenames = ['test', 'test1', 'test2', 'test3', 'test4'] def setUp(self): self.app = QtGui.QApplication(sys.argv) apply_patches() # Create App, keep app defaults (do not load # user-defined defaults). self.fc = App() self.fc.log.setLevel(logging.ERROR) def tearDown(self): del self.fc del self.app def test_flow(self): for i in range(100): print "Test #", i + 1 # Open test project self.fc.open_project( 'tests/project_files/' + self.filenames[random.randint(0, len(self.filenames) - 1)]) print "Project", self.fc.project_filename # Wait for project loaded and plotted while True: self.sleep(500) if self.fc.proc_container.view.text.text( ) == 'Idle.' or self.fc.ui.isHidden(): break # Interrupt on window close if self.fc.ui.isHidden(): break # Create new project and wait for a random time self.fc.on_file_new() self.sleep(random.randint(100, 1000)) def sleep(self, time): timer = QtCore.QTimer() el = QtCore.QEventLoop() timer.singleShot(time, el, QtCore.SLOT("quit()")) el.exec_()
class VisPyPlotCase(unittest.TestCase): """ This is a top-level test covering the Gerber-to-GCode generation workflow. THIS IS A REQUIRED TEST FOR ANY UPDATES. """ filenames = ['test', 'test1', 'test2', 'test3', 'test4'] def setUp(self): self.app = QtGui.QApplication(sys.argv) apply_patches() # Create App, keep app defaults (do not load # user-defined defaults). self.fc = App() self.fc.log.setLevel(logging.ERROR) def tearDown(self): del self.fc del self.app def test_flow(self): for i in range(100): print "Test #", i + 1 # Open test project self.fc.open_project('tests/project_files/' + self.filenames[random.randint(0, len(self.filenames) - 1)]) print "Project", self.fc.project_filename # Wait for project loaded and plotted while True: self.sleep(500) if self.fc.proc_container.view.text.text() == 'Idle.' or self.fc.ui.isHidden(): break # Interrupt on window close if self.fc.ui.isHidden(): break # Create new project and wait for a random time self.fc.on_file_new() self.sleep(random.randint(100, 1000)) def sleep(self, time): timer = QtCore.QTimer() el = QtCore.QEventLoop() timer.singleShot(time, el, QtCore.SLOT("quit()")) el.exec_()
def setUpClass(cls): cls.setup = True cls.app = QtGui.QApplication(sys.argv) # Create App, keep app defaults (do not load # user-defined defaults). cls.fc = App(user_defaults=False) cls.fc.ui.shell_dock.show()
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 setUpClass(self): self.setup=True 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.ui.shell_dock.show()
class GerberFlowTestCase(unittest.TestCase): filename = 'simple1.gbr' 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_gerber('tests/gerber_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 FlatCAMGerber. #--------------------------------------- gerber_name = names[0] gerber_obj = self.fc.collection.get_by_name(gerber_name) self.assertTrue( isinstance(gerber_obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (gerber_name, type(gerber_obj))) #-------------------------------------------------- # Create isolation routing using default values # and by clicking on the button. #-------------------------------------------------- # Get the object's GUI and click on "Generate Geometry" under # "Isolation Routing" assert isinstance(gerber_obj, FlatCAMGerber) # Just for the IDE gerber_obj.build_ui() # Open the object's UI. ui = gerber_obj.ui assert isinstance(ui, GerberObjectUI) ui.generate_iso_button.click() # Click #--------------------------------------------- # 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 Geometry Object has the correct name #------------------------------------------------------- geo_name = gerber_name + "_iso" self.assertTrue(geo_name in names, "Object named %s not found." % geo_name) #------------------------------------------------------- # Get the object make sure it's a geometry object #------------------------------------------------------- geo_obj = self.fc.collection.get_by_name(geo_name) self.assertTrue(isinstance(geo_obj, FlatCAMGeometry), "Expected a FlatCAMGeometry, got %s" % type(geo_obj)) #------------------------------------ # Open the UI, make CNCObject #------------------------------------ geo_obj.build_ui() ui = geo_obj.ui assert isinstance(ui, GeometryObjectUI) # Just for the IDE 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 only 1 object has been created. #--------------------------------------------- names = self.fc.collection.get_names() self.assertEqual(len(names), 3, "Expected 3 objects, found %d" % len(names)) #------------------------------------------------------- # Make sure the CNC Job Object has the correct name #------------------------------------------------------- cnc_name = geo_name + "_cnc" self.assertTrue(cnc_name in names, "Object named %s not found." % geo_name) #------------------------------------------------------- # Get the object make sure it's a CNC Job object #------------------------------------------------------- cnc_obj = self.fc.collection.get_by_name(cnc_name) self.assertTrue(isinstance(cnc_obj, FlatCAMCNCjob), "Expected a FlatCAMCNCJob, got %s" % type(geo_obj)) #----------------------------------------- # Export G-Code, check output #----------------------------------------- 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: output_filename = tmp_file.name cnc_obj.export_gcode(output_filename) self.assertTrue(os.path.isfile(output_filename)) os.remove(output_filename) print names
class SVGFlowTestCase(unittest.TestCase): 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.filename = 'drawing.svg' def tearDown(self): del self.fc del self.app def test_flow(self): self.fc.import_svg('tests/svg/' + self.filename) 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 FlatCAMGerber. #--------------------------------------- geo_name = names[0] geo_obj = self.fc.collection.get_by_name(geo_name) self.assertTrue( isinstance(geo_obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (geo_name, type(geo_obj))) #---------------------------------------- # Object's GUI matches Object's options #---------------------------------------- # TODO: Open GUI with double-click on object. # Opens the Object's GUI, populates it. geo_obj.build_ui() for option, value in geo_obj.options.iteritems(): try: form_field = geo_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())) #------------------------------------ # Open the UI, make CNCObject #------------------------------------ geo_obj.build_ui() ui = geo_obj.ui assert isinstance(ui, GeometryObjectUI) # Just for the IDE 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 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 CNC Job Object has the correct name #------------------------------------------------------- cnc_name = geo_name + "_cnc" self.assertTrue(cnc_name in names, "Object named %s not found." % geo_name) #------------------------------------------------------- # Get the object make sure it's a CNC Job object #------------------------------------------------------- cnc_obj = self.fc.collection.get_by_name(cnc_name) self.assertTrue(isinstance(cnc_obj, FlatCAMCNCjob), "Expected a FlatCAMCNCJob, got %s" % type(geo_obj)) #----------------------------------------- # Export G-Code, check output #----------------------------------------- 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: output_filename = tmp_file.name cnc_obj.export_gcode(output_filename) self.assertTrue(os.path.isfile(output_filename)) os.remove(output_filename) print names
class GerberFlowTestCase(unittest.TestCase): filename = 'simple1.gbr' 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_gerber('tests/gerber_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 FlatCAMGerber. #--------------------------------------- gerber_name = names[0] gerber_obj = self.fc.collection.get_by_name(gerber_name) self.assertTrue(isinstance(gerber_obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (gerber_name, type(gerber_obj))) #-------------------------------------------------- # Create isolation routing using default values # and by clicking on the button. #-------------------------------------------------- # Get the object's GUI and click on "Generate Geometry" under # "Isolation Routing" assert isinstance(gerber_obj, FlatCAMGerber) # Just for the IDE gerber_obj.build_ui() # Open the object's UI. ui = gerber_obj.ui assert isinstance(ui, GerberObjectUI) ui.generate_iso_button.click() # Click #--------------------------------------------- # 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 Geometry Object has the correct name #------------------------------------------------------- geo_name = gerber_name + "_iso" self.assertTrue(geo_name in names, "Object named %s not found." % geo_name) #------------------------------------------------------- # Get the object make sure it's a geometry object #------------------------------------------------------- geo_obj = self.fc.collection.get_by_name(geo_name) self.assertTrue(isinstance(geo_obj, FlatCAMGeometry), "Expected a FlatCAMGeometry, got %s" % type(geo_obj)) #------------------------------------ # Open the UI, make CNCObject #------------------------------------ geo_obj.build_ui() ui = geo_obj.ui assert isinstance(ui, GeometryObjectUI) # Just for the IDE 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 only 1 object has been created. #--------------------------------------------- names = self.fc.collection.get_names() self.assertEqual(len(names), 3, "Expected 3 objects, found %d" % len(names)) #------------------------------------------------------- # Make sure the CNC Job Object has the correct name #------------------------------------------------------- cnc_name = geo_name + "_cnc" self.assertTrue(cnc_name in names, "Object named %s not found." % geo_name) #------------------------------------------------------- # Get the object make sure it's a CNC Job object #------------------------------------------------------- cnc_obj = self.fc.collection.get_by_name(cnc_name) self.assertTrue(isinstance(cnc_obj, FlatCAMCNCjob), "Expected a FlatCAMCNCJob, got %s" % type(geo_obj)) #----------------------------------------- # Export G-Code, check output #----------------------------------------- assert isinstance(cnc_obj, FlatCAMCNCjob) output_filename = "tests/tmp/" + cnc_name + ".gcode" cnc_obj.export_gcode(output_filename) self.assertTrue(os.path.isfile(output_filename)) os.remove(output_filename) print names
class TclShellTest(unittest.TestCase): svg_files = 'tests/svg' svg_filename = 'Arduino Nano3_pcb.svg' gerber_files = 'tests/gerber_files' copper_bottom_filename = 'detector_copper_bottom.gbr' copper_top_filename = 'detector_copper_top.gbr' cutout_filename = 'detector_contour.gbr' excellon_filename = 'detector_drill.txt' gerber_name = "gerber" geometry_name = "geometry" excellon_name = "excellon" gerber_top_name = "top" gerber_bottom_name = "bottom" gerber_cutout_name = "cutout" engraver_diameter = 0.3 cutout_diameter = 3 drill_diameter = 0.8 @classmethod def setUpClass(self): self.setup=True 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.ui.shell_dock.show() @classmethod def tearDownClass(self): self.fc.tcl=None self.app.closeAllWindows() del self.fc del self.app pass def test_set_get_units(self): self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') self.fc.exec_command_test('set_sys units IN') self.fc.exec_command_test('new') units=self.fc.exec_command_test('get_sys units') self.assertEquals(units, "IN") self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') units=self.fc.exec_command_test('get_sys units') self.assertEquals(units, "MM") def test_gerber_flow(self): # open gerber files top, bottom and cutout self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') self.fc.exec_command_test('open_gerber %s/%s -outname %s' % (self.gerber_files, self.copper_top_filename, self.gerber_top_name)) gerber_top_obj = self.fc.collection.get_by_name(self.gerber_top_name) self.assertTrue(isinstance(gerber_top_obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (self.gerber_top_name, type(gerber_top_obj))) self.fc.exec_command_test('open_gerber %s/%s -outname %s' % (self.gerber_files, self.copper_bottom_filename, self.gerber_bottom_name)) gerber_bottom_obj = self.fc.collection.get_by_name(self.gerber_bottom_name) self.assertTrue(isinstance(gerber_bottom_obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (self.gerber_bottom_name, type(gerber_bottom_obj))) self.fc.exec_command_test('open_gerber %s/%s -outname %s' % (self.gerber_files, self.cutout_filename, self.gerber_cutout_name)) gerber_cutout_obj = self.fc.collection.get_by_name(self.gerber_cutout_name) self.assertTrue(isinstance(gerber_cutout_obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (self.gerber_cutout_name, type(gerber_cutout_obj))) # exteriors delete and join geometries for top layer self.fc.exec_command_test('isolate %s -dia %f' % (self.gerber_cutout_name, self.engraver_diameter)) self.fc.exec_command_test('exteriors %s -outname %s' % (self.gerber_cutout_name + '_iso', self.gerber_cutout_name + '_iso_exterior')) self.fc.exec_command_test('delete %s' % (self.gerber_cutout_name + '_iso')) obj = self.fc.collection.get_by_name(self.gerber_cutout_name + '_iso_exterior') self.assertTrue(isinstance(obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (self.gerber_cutout_name + '_iso_exterior', type(obj))) # mirror bottom gerbers self.fc.exec_command_test('mirror %s -box %s -axis X' % (self.gerber_bottom_name, self.gerber_cutout_name)) self.fc.exec_command_test('mirror %s -box %s -axis X' % (self.gerber_cutout_name, self.gerber_cutout_name)) # exteriors delete and join geometries for bottom layer self.fc.exec_command_test('isolate %s -dia %f -outname %s' % (self.gerber_cutout_name, self.engraver_diameter, self.gerber_cutout_name + '_bottom_iso')) self.fc.exec_command_test('exteriors %s -outname %s' % (self.gerber_cutout_name + '_bottom_iso', self.gerber_cutout_name + '_bottom_iso_exterior')) self.fc.exec_command_test('delete %s' % (self.gerber_cutout_name + '_bottom_iso')) obj = self.fc.collection.get_by_name(self.gerber_cutout_name + '_bottom_iso_exterior') self.assertTrue(isinstance(obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (self.gerber_cutout_name + '_bottom_iso_exterior', type(obj))) # at this stage we should have 5 objects names = self.fc.collection.get_names() self.assertEqual(len(names), 5, "Expected 5 objects, found %d" % len(names)) # isolate traces self.fc.exec_command_test('isolate %s -dia %f' % (self.gerber_top_name, self.engraver_diameter)) self.fc.exec_command_test('isolate %s -dia %f' % (self.gerber_bottom_name, self.engraver_diameter)) # join isolated geometries for top and bottom self.fc.exec_command_test('join_geometries %s %s %s' % (self.gerber_top_name + '_join_iso', self.gerber_top_name + '_iso', self.gerber_cutout_name + '_iso_exterior')) self.fc.exec_command_test('join_geometries %s %s %s' % (self.gerber_bottom_name + '_join_iso', self.gerber_bottom_name + '_iso', self.gerber_cutout_name + '_bottom_iso_exterior')) # at this stage we should have 9 objects names = self.fc.collection.get_names() self.assertEqual(len(names), 9, "Expected 9 objects, found %d" % len(names)) # clean unused isolations self.fc.exec_command_test('delete %s' % (self.gerber_bottom_name + '_iso')) self.fc.exec_command_test('delete %s' % (self.gerber_top_name + '_iso')) self.fc.exec_command_test('delete %s' % (self.gerber_cutout_name + '_iso_exterior')) self.fc.exec_command_test('delete %s' % (self.gerber_cutout_name + '_bottom_iso_exterior')) # at this stage we should have 5 objects again names = self.fc.collection.get_names() self.assertEqual(len(names), 5, "Expected 5 objects, found %d" % len(names)) # geocutout bottom test (it cuts to same object) self.fc.exec_command_test('isolate %s -dia %f -outname %s' % (self.gerber_cutout_name, self.cutout_diameter, self.gerber_cutout_name + '_bottom_iso')) self.fc.exec_command_test('exteriors %s -outname %s' % (self.gerber_cutout_name + '_bottom_iso', self.gerber_cutout_name + '_bottom_iso_exterior')) self.fc.exec_command_test('delete %s' % (self.gerber_cutout_name + '_bottom_iso')) obj = self.fc.collection.get_by_name(self.gerber_cutout_name + '_bottom_iso_exterior') self.assertTrue(isinstance(obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (self.gerber_cutout_name + '_bottom_iso_exterior', type(obj))) self.fc.exec_command_test('geocutout %s -dia %f -gapsize 0.3 -gaps 4' % (self.gerber_cutout_name + '_bottom_iso_exterior', self.cutout_diameter)) # at this stage we should have 6 objects names = self.fc.collection.get_names() self.assertEqual(len(names), 6, "Expected 6 objects, found %d" % len(names)) # TODO: tests for tcl def test_open_gerber(self): self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') self.fc.exec_command_test('open_gerber %s/%s -outname %s' % (self.gerber_files, self.copper_top_filename, self.gerber_top_name)) gerber_top_obj = self.fc.collection.get_by_name(self.gerber_top_name) self.assertTrue(isinstance(gerber_top_obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (self.gerber_top_name, type(gerber_top_obj))) def test_excellon_flow(self): self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') self.fc.exec_command_test('open_excellon %s/%s -outname %s' % (self.gerber_files, self.excellon_filename, self.excellon_name)) excellon_obj = self.fc.collection.get_by_name(self.excellon_name) self.assertTrue(isinstance(excellon_obj, FlatCAMExcellon), "Expected FlatCAMExcellon, instead, %s is %s" % (self.excellon_name, type(excellon_obj))) # mirror bottom excellon self.fc.exec_command_test('mirror %s -box %s -axis X' % (self.excellon_name, self.gerber_cutout_name)) # TODO: tests for tcl def test_import_svg(self): """ Test all SVG files inside svg directory. Problematic SVG files shold be put there as test reference. :return: """ self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') file_list = listdir(self.svg_files) for svg_file in file_list: # import without outname self.fc.exec_command_test('import_svg "%s/%s"' % (self.svg_files, svg_file)) obj = self.fc.collection.get_by_name(svg_file) self.assertTrue(isinstance(obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (svg_file, type(obj))) # import with outname outname='%s-%s' % (self.geometry_name, svg_file) self.fc.exec_command_test('import_svg "%s/%s" -outname "%s"' % (self.svg_files, svg_file, outname)) obj = self.fc.collection.get_by_name(outname) self.assertTrue(isinstance(obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (outname, type(obj))) names = self.fc.collection.get_names() self.assertEqual(len(names), len(file_list)*2, "Expected %d objects, found %d" % (len(file_list)*2, len(file_list))) def test_import_svg_as_geometry(self): self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') self.fc.exec_command_test('import_svg "%s/%s" -type geometry -outname "%s"' % (self.svg_files, self.svg_filename, self.geometry_name)) obj = self.fc.collection.get_by_name(self.geometry_name) self.assertTrue(isinstance(obj, FlatCAMGeometry) and not isinstance(obj, FlatCAMGerber), "Expected FlatCAMGeometry, instead, %s is %s" % (self.geometry_name, type(obj))) def test_import_svg_as_gerber(self): self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') self.fc.exec_command_test('import_svg "%s/%s" -type gerber -outname "%s"' % (self.svg_files, self.svg_filename, self.gerber_name)) obj = self.fc.collection.get_by_name(self.gerber_name) self.assertTrue(isinstance(obj, FlatCAMGerber), "Expected FlatCAMGerber, instead, %s is %s" % (self.gerber_name, type(obj))) self.fc.exec_command_test('isolate "%s"' % self.gerber_name) obj = self.fc.collection.get_by_name(self.gerber_name+'_iso') self.assertTrue(isinstance(obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (self.gerber_name+'_iso', type(obj)))
class PolyPaintTestCase(unittest.TestCase): 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) def tearDown(self): for _ in range(2): self.app.processEvents() # NOTE: These are creating problems... # del self.fc # del self.app def test_poly_paint_svg_all(self): print("*********************************") print("* svg_all *") print("*********************************") # Clear workspace self.fc.on_file_new() for _ in range(2): self.app.processEvents() # Open SVG with polygons self.fc.import_svg('tests/svg/drawing.svg') name = self.fc.collection.get_names()[0] self.fc.collection.set_active(name) geo_obj = self.fc.collection.get_by_name(name) # Paint all polygons geo_obj.paint_poly_all(5, 0.2, 1) sleep(5) # Todo: Do not base it on fixed time. for _ in range(2): self.app.processEvents() # New object should be available names = self.fc.collection.get_names() self.assertEqual(len(names), 2) # Verify new geometry makes sense painted = self.fc.collection.get_by_name(names[-1]) for geo in painted.solid_geometry: # Correct Type self.assertTrue(isinstance(geo, LineString)) # Lots of points (Should be 1000s) self.assertGreater(len(geo.coords), 2) def test_poly_paint_svg_click(self): print("*********************************") print("* svg_click *") print("*********************************") # Clear workspace self.fc.on_file_new() for _ in range(2): self.app.processEvents() # Open SVG with polygons self.fc.import_svg('tests/svg/drawing.svg') name = self.fc.collection.get_names()[0] self.fc.collection.set_active(name) geo_obj = self.fc.collection.get_by_name(name) # Paint all polygons geo_obj.paint_poly_single_click([300, 700], 5, 0.2, 1) sleep(5) for _ in range(2): self.app.processEvents() # New object should be available names = self.fc.collection.get_names() sleep(1) self.assertEqual(len(names), 2) # Verify new geometry makes sense painted = self.fc.collection.get_by_name(names[-1]) for geo in painted.solid_geometry: # Correct Type self.assertTrue(isinstance(geo, LineString)) # Lots of points (Should be 1000s) self.assertGreater(len(geo.coords), 2) def test_poly_paint_noncopper_all(self): print("*********************************") print("* noncopper_all *") print("*********************************") # Clear workspace self.fc.on_file_new() for _ in range(2): self.app.processEvents() self.fc.open_gerber('tests/gerber_files/simple1.gbr') sleep(1) for _ in range(2): self.app.processEvents() name = self.fc.collection.get_names()[0] gerber_obj = self.fc.collection.get_by_name(name) self.fc.collection.set_active(name) gerber_obj.on_generatenoncopper_button_click() sleep(1) for _ in range(2): self.app.processEvents() # New object should be available names = self.fc.collection.get_names() sleep(1) self.assertEqual(len(names), 2) geoname = "simple1.gbr_noncopper" geo_obj = self.fc.collection.get_by_name(geoname) self.fc.collection.set_active(geoname) geo_obj.paint_poly_all(0.02, 0.2, 0) sleep(5) for _ in range(2): self.app.processEvents() # New object should be available names = self.fc.collection.get_names() sleep(1) self.assertEqual(len(names), 3) # Verify new geometry makes sense painted = self.fc.collection.get_by_name(names[-1]) for geo in painted.solid_geometry: # Correct Type self.assertTrue(isinstance(geo, LineString)) # Lots of points (Should be 1000s) self.assertGreater(len(geo.coords), 2) def test_poly_paint_noncopper_click(self): print("*********************************") print("* noncopper_click *") print("*********************************") # Clear workspace self.fc.on_file_new() for _ in range(2): self.app.processEvents() self.fc.open_gerber('tests/gerber_files/simple1.gbr') sleep(1) for _ in range(2): self.app.processEvents() name = self.fc.collection.get_names()[0] gerber_obj = self.fc.collection.get_by_name(name) self.fc.collection.set_active(name) gerber_obj.on_generatenoncopper_button_click() sleep(1) for _ in range(2): self.app.processEvents() # New object should be available names = self.fc.collection.get_names() sleep(1) self.assertEqual(len(names), 2) geoname = "simple1.gbr_noncopper" geo_obj = self.fc.collection.get_by_name(geoname) self.fc.collection.set_active(geoname) geo_obj.paint_poly_single_click([2.7, 1.0], 0.02, 0.2, 0) sleep(5) for _ in range(2): self.app.processEvents() # New object should be available names = self.fc.collection.get_names() sleep(1) self.assertEqual(len(names), 3) # Verify new geometry makes sense painted = self.fc.collection.get_by_name(names[-1]) for geo in painted.solid_geometry: # Correct Type self.assertTrue(isinstance(geo, LineString)) # Lots of points (Should be 1000s) self.assertGreater(len(geo.coords), 2)
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
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.assertEqual(len(names), 1, "Expected 1 object, found %d" % len(names)) #-------------------------------------- # Object's name matches the file name. #-------------------------------------- self.assertEqual( 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 list(excellon_obj.options.items()): 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)
# Author: Juan Pablo Caram (c) # # Date: 2/5/2014 # # MIT Licence # ############################################################ import sys from PyQt4 import QtGui from FlatCAMApp import App def debug_trace(): """ Set a tracepoint in the Python debugger that works with Qt :return: None """ from PyQt4.QtCore import pyqtRemoveInputHook #from pdb import set_trace pyqtRemoveInputHook() #set_trace() debug_trace() # All X11 calling should be thread safe otherwise we have strange issues # QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) # NOTE: Never talk to the GUI from threads! This is why I commented the above. app = QtGui.QApplication(sys.argv) fc = App() sys.exit(app.exec_())
class SVGFlowTestCase(unittest.TestCase): 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.filename = 'drawing.svg' def tearDown(self): del self.fc del self.app def test_flow(self): self.fc.import_svg('tests/svg/' + self.filename) 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 FlatCAMGerber. #--------------------------------------- geo_name = names[0] geo_obj = self.fc.collection.get_by_name(geo_name) self.assertTrue(isinstance(geo_obj, FlatCAMGeometry), "Expected FlatCAMGeometry, instead, %s is %s" % (geo_name, type(geo_obj))) #---------------------------------------- # Object's GUI matches Object's options #---------------------------------------- # TODO: Open GUI with double-click on object. # Opens the Object's GUI, populates it. geo_obj.build_ui() for option, value in geo_obj.options.iteritems(): try: form_field = geo_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() )) #------------------------------------ # Open the UI, make CNCObject #------------------------------------ geo_obj.build_ui() ui = geo_obj.ui assert isinstance(ui, GeometryObjectUI) # Just for the IDE 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 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 CNC Job Object has the correct name #------------------------------------------------------- cnc_name = geo_name + "_cnc" self.assertTrue(cnc_name in names, "Object named %s not found." % geo_name) #------------------------------------------------------- # Get the object make sure it's a CNC Job object #------------------------------------------------------- cnc_obj = self.fc.collection.get_by_name(cnc_name) self.assertTrue(isinstance(cnc_obj, FlatCAMCNCjob), "Expected a FlatCAMCNCJob, got %s" % type(geo_obj)) #----------------------------------------- # Export G-Code, check output #----------------------------------------- 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: output_filename = tmp_file.name cnc_obj.export_gcode(output_filename) self.assertTrue(os.path.isfile(output_filename)) os.remove(output_filename) print names