diff --git a/FlatCAMApp.py b/FlatCAMApp.py index f9ca0a4..c239118 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -29,6 +29,7 @@ from MeasurementTool import Measurement from DblSidedTool import DblSidedTool import tclCommands + ######################################## ## App ## ######################################## diff --git a/FlatCAMObj.py b/FlatCAMObj.py index b475692..722e9c4 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -327,7 +327,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber): "isotooldia": self.ui.iso_tool_dia_entry, "isopasses": self.ui.iso_width_entry, "isooverlap": self.ui.iso_overlap_entry, - "combine_passes":self.ui.combine_passes_cb, + "combine_passes": self.ui.combine_passes_cb, "cutouttooldia": self.ui.cutout_tooldia_entry, "cutoutmargin": self.ui.cutout_margin_entry, "cutoutgapsize": self.ui.cutout_gap_entry, diff --git a/tclCommands/__init__.py b/tclCommands/__init__.py index 0885d14..f02b02d 100644 --- a/tclCommands/__init__.py +++ b/tclCommands/__init__.py @@ -21,15 +21,16 @@ for loader, name, is_pkg in pkgutil.walk_packages(__path__): module = loader.find_module(name).load_module(name) __all__.append(name) + def register_all_commands(app, commands): """ Static method which register all known commands. - Command should be for now in directory tclCommands and module should start with TCLCommand + Command should be for now in directory test_tclCommands and module should start with TCLCommand Class have to follow same name as module. we need import all modules in top section: - import tclCommands.TclCommandExteriors + import test_tclCommands.TclCommandExteriors at this stage we can include only wanted commands with this, auto loading may be implemented in future I have no enough knowledge about python's anatomy. Would be nice to include all classes which are descendant etc. @@ -38,10 +39,10 @@ def register_all_commands(app, commands): :return: None """ - tcl_modules = {k: v for k, v in sys.modules.items() if k.startswith('tclCommands.TclCommand')} + tcl_modules = {k: v for k, v in sys.modules.items() if k.startswith('test_tclCommands.TclCommand')} for key, mod in tcl_modules.items(): - if key != 'tclCommands.TclCommand': + if key != 'test_tclCommands.TclCommand': class_name = key.split('.')[1] class_type = getattr(mod, class_name) command_instance = class_type(app) diff --git a/tests/test_gerber_flow.py b/tests/test_gerber_flow.py index 9eac0ef..23ef1c1 100644 --- a/tests/test_gerber_flow.py +++ b/tests/test_gerber_flow.py @@ -1,13 +1,14 @@ import sys import unittest from PyQt4 import QtGui -from FlatCAMApp import App +from FlatCAMApp import App, tclCommands from FlatCAMObj import FlatCAMGerber, FlatCAMGeometry, FlatCAMCNCjob from ObjectUI import GerberObjectUI, GeometryObjectUI from time import sleep import os import tempfile + class GerberFlowTestCase(unittest.TestCase): filename = 'simple1.gbr' @@ -51,6 +52,36 @@ class GerberFlowTestCase(unittest.TestCase): "Expected FlatCAMGerber, instead, %s is %s" % (gerber_name, type(gerber_obj))) + #---------------------------------------- + # Object's GUI matches Object's options + #---------------------------------------- + # TODO: Open GUI with double-click on object. + # Opens the Object's GUI, populates it. + gerber_obj.build_ui() + for option, value in gerber_obj.options.iteritems(): + try: + form_field = gerber_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 = gerber_obj.form_fields['isotooldia'] + value = form_field.get_value() + form_field.set_value(value * 1.1) # Increase by 10% + print "'isotooldia' == {}".format(value) + #-------------------------------------------------- # Create isolation routing using default values # and by clicking on the button. @@ -58,11 +89,22 @@ class GerberFlowTestCase(unittest.TestCase): # 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. + # Changed: UI has been build already + #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 GUI has been read in. + #--------------------------------------------- + value = gerber_obj.options['isotooldia'] + form_value = form_field.get_value() + self.assertEqual(value, form_value, + "Form value for '{}' == {} was not read into options" + "which has {}".format('isotooldia', form_value, value)) + print "'isotooldia' == {}".format(value) + #--------------------------------------------- # Check that only 1 object has been created. #--------------------------------------------- diff --git a/tests/tclCommands/__init__.py b/tests/test_tclCommands/__init__.py similarity index 100% rename from tests/tclCommands/__init__.py rename to tests/test_tclCommands/__init__.py diff --git a/tests/tclCommands/test_TclCommandAddPolygon.py b/tests/test_tclCommands/test_TclCommandAddPolygon.py similarity index 100% rename from tests/tclCommands/test_TclCommandAddPolygon.py rename to tests/test_tclCommands/test_TclCommandAddPolygon.py diff --git a/tests/tclCommands/test_TclCommandAddPolyline.py b/tests/test_tclCommands/test_TclCommandAddPolyline.py similarity index 100% rename from tests/tclCommands/test_TclCommandAddPolyline.py rename to tests/test_tclCommands/test_TclCommandAddPolyline.py diff --git a/tests/tclCommands/test_TclCommandCncjob.py b/tests/test_tclCommands/test_TclCommandCncjob.py similarity index 100% rename from tests/tclCommands/test_TclCommandCncjob.py rename to tests/test_tclCommands/test_TclCommandCncjob.py diff --git a/tests/tclCommands/test_TclCommandDrillcncjob.py b/tests/test_tclCommands/test_TclCommandDrillcncjob.py similarity index 100% rename from tests/tclCommands/test_TclCommandDrillcncjob.py rename to tests/test_tclCommands/test_TclCommandDrillcncjob.py diff --git a/tests/tclCommands/test_TclCommandExportGcode.py b/tests/test_tclCommands/test_TclCommandExportGcode.py similarity index 100% rename from tests/tclCommands/test_TclCommandExportGcode.py rename to tests/test_tclCommands/test_TclCommandExportGcode.py diff --git a/tests/tclCommands/test_TclCommandExteriors.py b/tests/test_tclCommands/test_TclCommandExteriors.py similarity index 100% rename from tests/tclCommands/test_TclCommandExteriors.py rename to tests/test_tclCommands/test_TclCommandExteriors.py diff --git a/tests/tclCommands/test_TclCommandImportSvg.py b/tests/test_tclCommands/test_TclCommandImportSvg.py similarity index 100% rename from tests/tclCommands/test_TclCommandImportSvg.py rename to tests/test_tclCommands/test_TclCommandImportSvg.py diff --git a/tests/tclCommands/test_TclCommandInteriors.py b/tests/test_tclCommands/test_TclCommandInteriors.py similarity index 100% rename from tests/tclCommands/test_TclCommandInteriors.py rename to tests/test_tclCommands/test_TclCommandInteriors.py diff --git a/tests/tclCommands/test_TclCommandIsolate.py b/tests/test_tclCommands/test_TclCommandIsolate.py similarity index 100% rename from tests/tclCommands/test_TclCommandIsolate.py rename to tests/test_tclCommands/test_TclCommandIsolate.py diff --git a/tests/tclCommands/test_TclCommandNew.py b/tests/test_tclCommands/test_TclCommandNew.py similarity index 100% rename from tests/tclCommands/test_TclCommandNew.py rename to tests/test_tclCommands/test_TclCommandNew.py diff --git a/tests/tclCommands/test_TclCommandNewGeometry.py b/tests/test_tclCommands/test_TclCommandNewGeometry.py similarity index 100% rename from tests/tclCommands/test_TclCommandNewGeometry.py rename to tests/test_tclCommands/test_TclCommandNewGeometry.py diff --git a/tests/tclCommands/test_TclCommandOpenExcellon.py b/tests/test_tclCommands/test_TclCommandOpenExcellon.py similarity index 100% rename from tests/tclCommands/test_TclCommandOpenExcellon.py rename to tests/test_tclCommands/test_TclCommandOpenExcellon.py diff --git a/tests/tclCommands/test_TclCommandOpenGerber.py b/tests/test_tclCommands/test_TclCommandOpenGerber.py similarity index 100% rename from tests/tclCommands/test_TclCommandOpenGerber.py rename to tests/test_tclCommands/test_TclCommandOpenGerber.py diff --git a/tests/tclCommands/test_TclCommandPaintPolygon.py b/tests/test_tclCommands/test_TclCommandPaintPolygon.py similarity index 100% rename from tests/tclCommands/test_TclCommandPaintPolygon.py rename to tests/test_tclCommands/test_TclCommandPaintPolygon.py diff --git a/tests/test_tcl_shell.py b/tests/test_tcl_shell.py index be1f81d..510a491 100644 --- a/tests/test_tcl_shell.py +++ b/tests/test_tcl_shell.py @@ -12,6 +12,7 @@ from time import sleep import os import tempfile + class TclShellTest(unittest.TestCase): svg_files = 'tests/svg' @@ -33,28 +34,30 @@ class TclShellTest(unittest.TestCase): # load test methods to split huge test file into smaller pieces # reason for this is reuse one test window only, - from tests.tclCommands import * + + # CANNOT DO THIS HERE!!! + #from tests.test_tclCommands import * @classmethod - def setUpClass(self): + def setUpClass(cls): - self.setup=True - self.app = QtGui.QApplication(sys.argv) + cls.setup = True + cls.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() + cls.fc = App(user_defaults=False) + cls.fc.ui.shell_dock.show() def setUp(self): self.fc.exec_command_test('set_sys units MM') self.fc.exec_command_test('new') @classmethod - def tearDownClass(self): - self.fc.tcl=None - self.app.closeAllWindows() - del self.fc - del self.app + def tearDownClass(cls): + cls.fc.tcl = None + cls.app.closeAllWindows() + del cls.fc + del cls.app pass def test_set_get_units(self): @@ -72,7 +75,6 @@ class TclShellTest(unittest.TestCase): 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