def test_removeProp(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.setProp(stage.foo_one) dm.addProp(stage.foo_two) self.assertListEqual(dm.getProps(), [stage.foo_one, stage.foo_two]) self.assertEqual(dm.getFocusProp(), stage.foo_two) # Remove a property. dm.removeProp(stage.foo_one) self.assertListEqual(dm.getProps(), [stage.foo_two]) self.assertEqual(dm.getFocusProp(), stage.foo_two) # Try to remove a property not in the selection. Nothing should happen. dm.removeProp(stage.foo_one) self.assertListEqual(dm.getProps(), [stage.foo_two]) self.assertEqual(dm.getFocusProp(), stage.foo_two) # Remove the last property. dm.removeProp(stage.foo_two) self.assertListEqual(dm.getProps(), []) self.assertEqual(dm.getFocusProp(), None) # Test validation. with self.assertRaises(ValueError): dm.removeProp(stage.foo)
def test_propBatchedChanges(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) counter = PropSignalCounter(dm.signalPropSelectionChanged) # Add some props in a batch. with dm.batchPropChanges: dm.addProp(stage.foo_one) dm.addProp(stage.foo_two) # Signal shouldn't be emitted yet! self.assertEqual(counter.getAndClearNumSignals(), 0) self.assertEqual(counter.getAndClearNumSignals(), 1) # Add a prop, then remove it immediately. A signal will still be # emitted. with dm.batchPropChanges: dm.addProp(stage.foo_three) dm.removeProp(stage.foo_three) self.assertEqual(counter.getAndClearNumSignals(), 1) # Clear the props then add some back. with dm.batchPropChanges: dm.clearProps() dm.addProp(stage.foo_two) dm.addProp(stage.foo_three) self.assertEqual(counter.getAndClearNumSignals(), 1)
def test_switchToPrim(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel, _computedPropFactory=FakeComputedPropFactory()) dm.setPrim(stage.foo) dm.addProp(stage.foo_one) dm.addProp(stage.foo_two) dm.addComputedProp(stage.foo_bbox) self.assertListEqual(dm.getPrims(), [stage.foo]) self.assertListEqual(dm.getProps(), [stage.foo_one, stage.foo_two]) self.assertListEqual(dm.getComputedProps(), [stage.foo_bbox]) # Switch selection to just bar, and convert all of foo's selected # properties to bar. dm.switchToPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.bar]) self.assertListEqual(dm.getProps(), [stage.bar_one, stage.bar_two]) self.assertListEqual(dm.getComputedProps(), [stage.bar_bbox]) # Add foo to the selection. dm.addPrim(stage.foo) # Since two prims are selected, preserve property selection. dm.switchToPrim(stage.foo) self.assertListEqual(dm.getPrims(), [stage.foo]) self.assertListEqual(dm.getProps(), [stage.bar_one, stage.bar_two]) self.assertListEqual(dm.getComputedProps(), [stage.bar_bbox]) # Add foo.one to the selection. dm.addProp(stage.foo_one) # Since properties which belong to different prims are selected, # preserve the property selection. dm.switchToPrim(stage.bar) self.assertListEqual(dm.getPrims(), [stage.bar]) self.assertListEqual(dm.getProps(), [stage.bar_one, stage.bar_two, stage.foo_one]) self.assertListEqual(dm.getComputedProps(), [stage.bar_bbox])
def test_clearProps(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) dm.setProp(stage.foo_one) dm.addProp(stage.foo_two) dm.addProp(stage.foo_three) self.assertListEqual(dm.getProps(), [stage.foo_one, stage.foo_two, stage.foo_three]) self.assertEqual(dm.getFocusProp(), stage.foo_three) # Clear the property selection. dm.clearProps() self.assertListEqual(dm.getProps(), []) self.assertEqual(dm.getFocusProp(), None)
def test_propTargets(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) self.assertDictEqual(dm.getPropTargets(), dict()) # Select a property. It should have an empty target selection. dm.addProp(stage.foo_one) self.assertDictEqual(dm.getPropTargets(), {stage.foo_one: set()}) # Add a target and connection to the property. dm.addPropTarget(stage.foo_one, stage.foo) dm.addPropTarget(stage.foo_one, stage.foo_two) self.assertDictEqual(dm.getPropTargets(), {stage.foo_one: {stage.foo, stage.foo_two}}) # Add a target to a property not already in the selection. The property # should be added to the selection. dm.addPropTarget(stage.foo_two, stage.foo) self.assertDictEqual(dm.getPropTargets(), { stage.foo_one: {stage.foo, stage.foo_two}, stage.foo_two: {stage.foo} }) # Remove the last target from a property. The property should remain # selected but have no targets. dm.removePropTarget(stage.foo_two, stage.foo) self.assertDictEqual(dm.getPropTargets(), { stage.foo_one: {stage.foo, stage.foo_two}, stage.foo_two: set() }) # Remove a property with targets. The property and its targets should # all be cleared. dm.removeProp(stage.foo_one) self.assertDictEqual(dm.getPropTargets(), {stage.foo_two: set()})
def test_propTargets(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) self.assertDictEqual(dm.getPropTargets(), dict()) # Select a property. It should have an empty target selection. dm.addProp(stage.foo_one) self.assertDictEqual(dm.getPropTargets(), {stage.foo_one: set()}) # Add a target and connection to the property. dm.addPropTarget(stage.foo_one, stage.foo) dm.addPropTarget(stage.foo_one, stage.foo_two) self.assertDictEqual(dm.getPropTargets(), {stage.foo_one: {stage.foo, stage.foo_two}}) # Add a target to a property not already in the selection. The property # should be added to the selection. dm.addPropTarget(stage.foo_two, stage.foo) self.assertDictEqual(dm.getPropTargets(), {stage.foo_one: {stage.foo, stage.foo_two}, stage.foo_two: {stage.foo}}) # Remove the last target from a property. The property should remain # selected but have no targets. dm.removePropTarget(stage.foo_two, stage.foo) self.assertDictEqual(dm.getPropTargets(), {stage.foo_one: {stage.foo, stage.foo_two}, stage.foo_two: set()}) # Remove a property with targets. The property and its targets should # all be cleared. dm.removeProp(stage.foo_one) self.assertDictEqual(dm.getPropTargets(), {stage.foo_two: set()})
def test_propNonBatchedChanges(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) counter = PropSignalCounter(dm.signalPropSelectionChanged) # Adding/removing/setting/clearing props all emit a single signal. dm.addProp(stage.foo_one) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.removeProp(stage.foo_one) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.setProp(stage.foo_one) self.assertEqual(counter.getAndClearNumSignals(), 1) dm.clearProps() self.assertEqual(counter.getAndClearNumSignals(), 1)
def test_addProp(self): stage = FakeStage() rootDataModel = FakeRootDataModel(stage) dm = SelectionDataModel(rootDataModel) # Property selection starts empty. self.assertListEqual(dm.getProps(), []) self.assertEqual(dm.getFocusProp(), None) # Add a property. dm.addProp(stage.foo_one) self.assertListEqual(dm.getProps(), [stage.foo_one]) self.assertEqual(dm.getFocusProp(), stage.foo_one) # Properties remain in the order they are added. dm.addProp(stage.foo_two) self.assertListEqual(dm.getProps(), [stage.foo_one, stage.foo_two]) self.assertEqual(dm.getFocusProp(), stage.foo_two) # Test validation. with self.assertRaises(ValueError): dm.addProp(stage.foo)