class TestUntypedCtis(unittest.TestCase): def setUp(self): self.invisibleRootItem = UntypedCti( nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild( UntypedCti(nodeName='kid', defaultData=-7)) def test__eq__(self): ctiIn = UntypedCti('parent', defaultData=7) self.assertEqual(ctiIn, ctiIn) self.assertEqual(ctiIn, UntypedCti('parent', defaultData=7)) self.assertNotEqual(ctiIn, UntypedCti('parent', defaultData=9)) ctiOut = UntypedCti('parent', defaultData=7) ctiIn.insertChild(UntypedCti('kid', defaultData=23)) self.assertNotEqual(ctiIn, ctiOut) ctiOut.insertChild(UntypedCti('kid', defaultData=23)) self.assertEqual(ctiIn, ctiOut) ctiIn.childItems[0].data = 99 self.assertNotEqual(ctiIn, ctiOut) def tearDown(self): pass
class TestSimpleCtis(unittest.TestCase): def setUp(self): self.invisibleRootItem = UntypedCti(nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild(UntypedCti(nodeName='kid', defaultData=-7)) def tearDown(self): pass def testColorCti(self): colorStr = '#FF33EE' cti = ColorCti('color', defaultData=colorStr) self.assertEqual(cti.data, QtGui.QColor(colorStr)) self.assertEqual(cti.data, QtGui.QColor(colorStr)) self.assertEqual(cti.displayValue, colorStr) def closedLoop(self, ctiIn): """ serialize cti default values to json and back """ nonDefaults = ctiIn.getNonDefaultsDict() json = dumps(nonDefaults) valuesDict = loads(json) ctiOut = copy.deepcopy(ctiIn) ctiOut._data = None ctiOut.setValuesFromDict(valuesDict) return ctiOut def testClosedLoop(self): # A data different than its default should be restored ctiIn = ColorCti('parent', defaultData='#ABCDEF') ctiIn.data='#DEADBE' # works only if data is set, otherwise ctiOut.data will be None ctiOut = self.closedLoop(ctiIn) print("ctiIn {}".format(ctiIn.__dict__)) print("ctiOut {}".format(ctiOut.__dict__)) self.assertEqual(ctiIn, ctiOut)
class TestSimpleCtis(unittest.TestCase): def setUp(self): self.invisibleRootItem = UntypedCti( nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild( UntypedCti(nodeName='kid', defaultData=-7)) def tearDown(self): pass def testColorCti(self): colorStr = '#FF33EE' cti = ColorCti('color', defaultData=colorStr) self.assertEqual(cti.data, QtGui.QColor(colorStr)) self.assertEqual(cti.data, QtGui.QColor(colorStr)) self.assertEqual(cti.displayValue, colorStr) def closedLoop(self, ctiIn): """ serialize cti default values to json and back """ nonDefaults = ctiIn.getNonDefaultsDict() json = dumps(nonDefaults) valuesDict = loads(json) ctiOut = copy.deepcopy(ctiIn) ctiOut._data = None ctiOut.setValuesFromDict(valuesDict) return ctiOut def testClosedLoop(self): # A data different than its default should be restored ctiIn = ColorCti('parent', defaultData='#ABCDEF') ctiIn.data = '#DEADBE' # works only if data is set, otherwise ctiOut.data will be None ctiOut = self.closedLoop(ctiIn) print("ctiIn {}".format(ctiIn.__dict__)) print("ctiOut {}".format(ctiOut.__dict__)) self.assertEqual(ctiIn, ctiOut)
def _createConfig(self): """ Creates a config tree item (CTI) hierarchy containing default children. """ rootItem = MainGroupCti('debug inspector') if DEBUGGING: # Some test config items. import numpy as np from argos.config.untypedcti import UntypedCti from argos.config.stringcti import StringCti from argos.config.intcti import IntCti from argos.config.floatcti import FloatCti, SnFloatCti from argos.config.boolcti import BoolCti, BoolGroupCti from argos.config.choicecti import ChoiceCti from argos.config.qtctis import PenCti grpItem = GroupCti("group") rootItem.insertChild(grpItem) lcItem = UntypedCti('line color', 123) grpItem.insertChild(lcItem) disabledItem = rootItem.insertChild(StringCti('disabled', "Can't touch me")) disabledItem.enabled=False grpItem.insertChild(IntCti('line-1 color', 7, minValue = -5, stepSize=2, prefix="@", suffix="%", specialValueText="I'm special")) rootItem.insertChild(StringCti('letter', 'aa', maxLength = 1)) grpItem.insertChild(FloatCti('width', 2, minValue =5, stepSize=0.45, decimals=3, prefix="@", suffix="%", specialValueText="so very special")) grpItem.insertChild(SnFloatCti('scientific', defaultData=-np.inf)) gridItem = rootItem.insertChild(BoolGroupCti('grid', True)) gridItem.insertChild(BoolCti('X-Axis', True)) gridItem.insertChild(BoolCti('Y-Axis', False)) rootItem.insertChild(ChoiceCti('hobbit', 2, editable=True, configValues=['Frodo', 'Sam', 'Pippin', 'Merry'])) myPen = QtGui.QPen(QtGui.QColor('#1C8857')) myPen.setWidth(2) myPen.setStyle(Qt.DashDotDotLine) rootItem.insertChild(PenCti('line', False, resetTo=myPen)) return rootItem
def test__eq__(self): ctiIn = UntypedCti('parent', defaultData=7) self.assertEqual(ctiIn, ctiIn) self.assertEqual(ctiIn, UntypedCti('parent', defaultData=7)) self.assertNotEqual(ctiIn, UntypedCti('parent', defaultData=9)) ctiOut = UntypedCti('parent', defaultData=7) ctiIn.insertChild(UntypedCti('kid', defaultData=23)) self.assertNotEqual(ctiIn, ctiOut) ctiOut.insertChild(UntypedCti('kid', defaultData=23)) self.assertEqual(ctiIn, ctiOut) ctiIn.childItems[0].data = 99 self.assertNotEqual(ctiIn, ctiOut)
def __init__(self, nodeName, viewBox, expanded=False): super(ViewBoxDebugCti, self).__init__(nodeName, expanded=expanded) self.viewBox = viewBox self.insertChild( UntypedCti( "targetRange", [[0, 1], [0, 1]], doc="Child coord. range visible [[xmin, xmax], [ymin, ymax]]")) self.insertChild( UntypedCti("viewRange", [[0, 1], [0, 1]], doc="Actual range viewed")) self.insertChild(UntypedCti("xInverted", None)) self.insertChild(UntypedCti("yInverted", None)) self.insertChild( UntypedCti( "aspectLocked", False, doc= "False if aspect is unlocked, otherwise float specifies the locked ratio." )) self.insertChild( UntypedCti( "autoRange", [True, True], doc= "False if auto range is disabled, otherwise float gives the fraction of data that is visible" )) self.insertChild( UntypedCti( "autoPan", [False, False], doc= "Whether to only pan (do not change scaling) when auto-range is enabled" )) self.insertChild( UntypedCti( "autoVisibleOnly", [False, False], doc= "Whether to auto-range only to the visible portion of a plot")) self.insertChild( UntypedCti( "linkedViews", [None, None], doc= "may be None, 'viewName', or weakref.ref(view) a name string indicates that the view *should* link to another, but no view with that name exists yet." )) self.insertChild(UntypedCti("mouseEnabled", [None, None])) self.insertChild(UntypedCti("mouseMode", None)) self.insertChild(UntypedCti("enableMenu", None)) self.insertChild(UntypedCti("wheelScaleFactor", None)) self.insertChild(UntypedCti("background", None)) self.limitsItem = self.insertChild(GroupCti("limits")) self.limitsItem.insertChild( UntypedCti("xLimits", [None, None], doc="Maximum and minimum visible X values ")) self.limitsItem.insertChild( UntypedCti("yLimits", [None, None], doc="Maximum and minimum visible Y values")) self.limitsItem.insertChild( UntypedCti("xRange", [None, None], doc="Maximum and minimum X range")) self.limitsItem.insertChild( UntypedCti("yRange", [None, None], doc="Maximum and minimum Y range"))
def setUp(self): self.invisibleRootItem = UntypedCti( nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild( UntypedCti(nodeName='kid', defaultData=-7))
def testNonDefaults(self): # A data different than its default should be restored ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=7) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) # A data is not written if it's the default and # is read correctly if the default stays the same ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=7) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) # A default data should have no effect it the default changes in the future. ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=9) ctiOut.setValuesFromDict(defDict) self.assertNotEqual(ctiIn, ctiOut) # Test children ctiIn = UntypedCti('parent', defaultData=6) ctiIn.insertChild(UntypedCti('child1', defaultData=1)) ctiIn.insertChild(UntypedCti('child2', defaultData=2)) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=6) ctiOut.insertChild(UntypedCti('child1', defaultData=1)) ctiOut.insertChild(UntypedCti('child2', defaultData=2)) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut)
class TestUntypedCtis(unittest.TestCase): def setUp(self): self.invisibleRootItem = UntypedCti( nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild( UntypedCti(nodeName='kid', defaultData=-7)) def test__eq__(self): ctiIn = UntypedCti('parent', defaultData=7) self.assertEqual(ctiIn, ctiIn) self.assertEqual(ctiIn, UntypedCti('parent', defaultData=7)) self.assertNotEqual(ctiIn, UntypedCti('parent', defaultData=9)) ctiOut = UntypedCti('parent', defaultData=7) ctiIn.insertChild(UntypedCti('kid', defaultData=23)) self.assertNotEqual(ctiIn, ctiOut) ctiOut.insertChild(UntypedCti('kid', defaultData=23)) self.assertEqual(ctiIn, ctiOut) ctiIn.childItems[0].data = 99 self.assertNotEqual(ctiIn, ctiOut) # This functionality is currently not used? Depricated? def __not_used__testJson(self): # encoding jstr = ctiDumps(self.invisibleRootItem) #print(jstr) # decoding #testItem = json.loads(jstr, object_hook=jsonAsCti) testItem = loads(jstr, cls=CtiDecoder) #print(mydumps(testItem)) self.assertEqual(testItem, self.invisibleRootItem) def testNonDefaults(self): # A data different than its default should be restored ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=7) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) # A data is not written if it's the default and # is read correctly if the default stays the same ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=7) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) # A default data should have no effect it the default changes in the future. ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=9) ctiOut.setValuesFromDict(defDict) self.assertNotEqual(ctiIn, ctiOut) # Test children ctiIn = UntypedCti('parent', defaultData=6) ctiIn.insertChild(UntypedCti('child1', defaultData=1)) ctiIn.insertChild(UntypedCti('child2', defaultData=2)) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=6) ctiOut.insertChild(UntypedCti('child1', defaultData=1)) ctiOut.insertChild(UntypedCti('child2', defaultData=2)) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) def tearDown(self): pass
def setUp(self): self.invisibleRootItem = UntypedCti(nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild(UntypedCti(nodeName='kid', defaultData=-7))
class TestUntypedCtis(unittest.TestCase): def setUp(self): self.invisibleRootItem = UntypedCti(nodeName='<invisible-root>', defaultData=0.123456789012345678901234567890) self.invisibleRootItem.insertChild(UntypedCti(nodeName='kid', defaultData=-7)) def test__eq__(self): ctiIn = UntypedCti('parent', defaultData=7) self.assertEqual(ctiIn, ctiIn) self.assertEqual(ctiIn, UntypedCti('parent', defaultData=7)) self.assertNotEqual(ctiIn, UntypedCti('parent', defaultData=9)) ctiOut = UntypedCti('parent', defaultData=7) ctiIn.insertChild(UntypedCti('kid', defaultData=23)) self.assertNotEqual(ctiIn, ctiOut) ctiOut.insertChild(UntypedCti('kid', defaultData=23)) self.assertEqual(ctiIn, ctiOut) ctiIn.childItems[0].data = 99 self.assertNotEqual(ctiIn, ctiOut) # This functionality is currently not used? Depricated? def __not_used__testJson(self): # encoding jstr = ctiDumps(self.invisibleRootItem) #print(jstr) # decoding #testItem = json.loads(jstr, object_hook=jsonAsCti) testItem = loads(jstr, cls=CtiDecoder) #print(mydumps(testItem)) self.assertEqual(testItem, self.invisibleRootItem) def testNonDefaults(self): # A data different than its default should be restored ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=7) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) # A data is not written if it's the default and # is read correctly if the default stays the same ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=7) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) # A default data should have no effect it the default changes in the future. ctiIn = UntypedCti('parent', defaultData=7) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=9) ctiOut.setValuesFromDict(defDict) self.assertNotEqual(ctiIn, ctiOut) # Test children ctiIn = UntypedCti('parent', defaultData=6) ctiIn.insertChild(UntypedCti('child1', defaultData=1)) ctiIn.insertChild(UntypedCti('child2', defaultData=2)) defDict = ctiIn.getNonDefaultsDict() #print(defDict) ctiOut = UntypedCti('parent', defaultData=6) ctiOut.insertChild(UntypedCti('child1', defaultData=1)) ctiOut.insertChild(UntypedCti('child2', defaultData=2)) ctiOut.setValuesFromDict(defDict) self.assertEqual(ctiIn, ctiOut) def tearDown(self): pass