Cleaned up tests for shell. Added test steps for gerber flow.

This commit is contained in:
Juan Pablo Caram 2016-06-03 17:15:35 -04:00
parent a3dbaff258
commit 36d0a2e029
20 changed files with 65 additions and 19 deletions

View File

@ -29,6 +29,7 @@ from MeasurementTool import Measurement
from DblSidedTool import DblSidedTool
import tclCommands
########################################
## App ##
########################################

View File

@ -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,

View File

@ -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)

View File

@ -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.
#---------------------------------------------

View File

@ -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