def test_delete(self, getCon): """ Add- and delete several constraints. """ # Convenience. igor = self.igor # Create the constraints for this test. c1 = getCon('foo', 1, 2) c2 = getCon('foo', 2, 3) c3 = getCon('foo', 3, 4) # Attempt to delete a non-existing constraint. This must neither return # an error not delete anything. assert igor.reset().ok assert igor.deleteConstraints([c1]) == (True, None, 0) assert igor.deleteConstraints([c1, c2]) == (True, None, 0) assert igor.updateLocalCache() == (True, None, 0) # Add some constraints, delete them, and update the cache. assert igor.addConstraints([c1, c2, c3]) == (True, None, 3) assert igor.updateLocalCache() == (True, None, 3) assert igor.deleteConstraints([c1, c2]) == (True, None, 2) assert igor.updateLocalCache() == (True, None, 1) # Add/delete more constraints without every updating the cache. These # operations must not affect the local cache of constraints in Igor. assert igor.reset().ok assert igor.addConstraints([c1, c2, c3]) == (True, None, 3) assert igor.deleteConstraints([c1, c2]) == (True, None, 2) assert igor.deleteConstraints([c1, c2]) == (True, None, 0) assert igor.addConstraints([c1, c2]) == (True, None, 2) assert igor.deleteConstraints([c1]) == (True, None, 1) assert igor.deleteConstraints([c1, c2]) == (True, None, 1) assert igor.deleteConstraints([c1, c2]) == (True, None, 0) assert igor.updateLocalCache() == (True, None, 1) assert igor.getConstraints(None).data == (c3, )
def test_uniquePairs(self, getCon): """ Add- and delete constraints and verify that Igor maintins a consistent list of unique body pairs. """ # Convenience. igor = self.igor # Create the constraints for this test. c1 = getCon('foo', 1, 2) c2 = getCon('foo', 2, 3) c3 = getCon('foo', 3, 4) # There must not be any pairs after a reset. assert igor.reset() == (True, None, None) assert igor.uniquePairs() == (True, None, tuple()) # Adding a constraint must result in one unique pair of IDs *after* # updating the Igor cache. assert igor.addConstraints([c1]) == (True, None, 1) assert igor.uniquePairs() == (True, None, tuple()) assert igor.updateLocalCache() == (True, None, 1) assert igor.uniquePairs().data == ((c1.rb_a, c1.rb_b), ) # Add three more constraints, only two of which are actually new. assert igor.addConstraints([c1, c2, c3]) == (True, None, 2) assert igor.updateLocalCache() == (True, None, 3) # Verify that the set of unique pairs now covers those involved in the # constraints. ref = [(_.rb_a, _.rb_b) for _ in (c1, c2, c3)] assert set(igor.uniquePairs().data) == set(tuple(ref)) # Delete two constraints. assert igor.deleteConstraints([c1, c3]) == (True, None, 2) assert set(igor.uniquePairs().data) == set(tuple(ref)) assert igor.updateLocalCache() == (True, None, 1) assert igor.uniquePairs().data == ((c2.rb_a, c2.rb_b), )