Bug in Driver owner setter
Description
def test_Driver_owner():
d = Driver('driver')
assert d.owner is None
dummy = System('dummy')
dummy.add_driver(d)
assert d.owner is dummy
# Add sub-driver - OK
d1 = d.add_child(Driver('subdriver'))
assert d.owner is dummy
assert d1.owner is dummy
# Change driver's owner: BUG
other = System('other')
d.owner = other
# Check that `other` is new owner of driver and all its subdrivers - OK
assert d.owner is other
assert d1.owner is other
# Original system `dummy` should no longer possess driver `d`
assert dummy.drivers == dict() # FAILS: dummy.drivers still has key 'driver', with value `d`
Expected behaviour
Test should not fail; original owner dummy
should be devoid of drivers.
Root cause
Driver
class should not have a setter for attribute owner.
This setter is currently necessary, though, as it is used in System.add_driver
.
A robust solution should be to change the way drivers are added to systems, that is to change the public API of System.add_driver
-- see Proposal 2 in issue #41.
Edited by Etienne Lac