Beispiel #1
0
    def test_getConstraints_all(self, getCon):
        """
        Add constraints and very that Igor can return them after cache updates.
        """
        # Convenience.
        igor = self.igor

        # Create the constraints for this test.
        c1 = getCon('foo', '2', '3')
        c2 = getCon('foo', '3', '4')
        c3 = getCon('foo', '4', '5')

        # The list of constraints must be empty after a reset.
        assert igor.getConstraints(None).data == tuple()
        assert igor.updateLocalCache() == (True, None, 0)
        assert igor.getConstraints(None).data == tuple()

        # Add two constraints and verify that Igor returns them *after* a cache
        # update.
        assert igor.addConstraints([c1, c2]) == (True, None, [True] * 2)
        assert igor.getConstraints(None).data == tuple()
        assert igor.updateLocalCache() == (True, None, 2)
        assert sorted(igor.getConstraints(None).data) == sorted((c1, c2))

        # Add another two constraints, only one of which is new. Verify that
        # Igor returns the correct three constraints.
        assert igor.addConstraints([c2, c3]) == (True, None, [False, True])
        assert igor.updateLocalCache() == (True, None, 3)
        assert sorted(igor.getConstraints(None).data) == sorted((c1, c2, c3))
Beispiel #2
0
    def test_getConstraints_all(self, getCon):
        """
        Add constraints and very that Igor can return them after cache updates.
        """
        # Convenience.
        igor = self.igor

        # Create the constraints for this test.
        c1 = getCon('foo', 2, 3)
        c2 = getCon('foo', 3, 4)
        c3 = getCon('foo', 4, 5)

        # The list of constraints must be empty after a reset.
        assert igor.reset() == (True, None, None)
        assert igor.getConstraints(None).data == tuple()
        assert igor.updateLocalCache() == (True, None, 0)
        assert igor.getConstraints(None).data == tuple()

        # Add two constraints and verify that Igor returns them *after* a cache
        # update.
        assert igor.addConstraints([c1, c2]) == (True, None, 2)
        assert igor.getConstraints(None).data == tuple()
        assert igor.updateLocalCache() == (True, None, 2)
        assert sorted(igor.getConstraints(None).data) == sorted((c1, c2))

        # Add another two constraints, only one of which is new. Verify that
        # Igor returns the correct three constraints.
        assert igor.addConstraints([c2, c3]) == (True, None, 1)
        assert igor.updateLocalCache() == (True, None, 3)
        assert sorted(igor.getConstraints(None).data) == sorted((c1, c2, c3))
Beispiel #3
0
 def test_basic(self):
     """
     Verify that it is safe to call any Igor methods right from the start
     without updating the cache or resetting the database.
     """
     igor = azrael.igor.Igor()
     assert igor.getConstraints(None).ok
     assert igor.getConstraints([1, 2]).ok
     assert igor.uniquePairs().ok
Beispiel #4
0
 def test_basic(self):
     """
     Verify that it is safe to call any Igor methods right from the start
     without updating the cache or resetting the database.
     """
     igor = azrael.igor.Igor()
     assert igor.getConstraints(None).ok
     assert igor.getConstraints([1, 2]).ok
     assert igor.uniquePairs().ok
Beispiel #5
0
    def test_add_unique_bug1(self, getCon):
        """
        Add two constraints that are identical except for their 'aid'.

        In the original implementation this was handled incorrectly
        because the 'aid' was not considered when adding constraints.
        This made it impossible to add more than once constraint of each
        type (eg more than one Point2Point constraint between objects).
        """
        # Convenience.
        igor = self.igor

        # Two constraints that only differ in their 'aid' attribute.
        c1 = getCon('foo', 1, 2)
        c2 = getCon('bar', 1, 2)

        # Attempt to add the first constraint twice. Igor must detect this and
        # only add it once.
        assert igor.reset().ok
        assert igor.addConstraints([c1, c1]) == (True, None, 1)

        # Attempt to both constraints. Without the bug fix Igor would only add
        # the first one, whereas with the bug fix it adds both.
        assert igor.reset().ok
        assert igor.addConstraints([c1, c2]) == (True, None, 2)

        # Update the local cache and verify that really both constraints are
        # available.
        assert igor.updateLocalCache() == (True, None, 2)
        assert sorted(igor.getConstraints(None).data) == sorted((c1, c2))
Beispiel #6
0
    def test_add_unique_bug1(self, getCon):
        """
        Add two constraints that are identical except for their 'aid'.

        In the original implementation this was handled incorrectly
        because the 'aid' was not considered when adding constraints.
        This made it impossible to add more than once constraint of each
        type (eg more than one Point2Point constraint between objects).
        """
        # Convenience.
        igor = self.igor

        # Two constraints that only differ in their 'aid' attribute.
        c1 = getCon('foo', '1', '2')
        c2 = getCon('bar', '1', '2')

        # Attempt to add the first constraint twice. Igor must detect this and
        # only add it once.
        assert igor.reset().ok
        assert igor.addConstraints([c1, c1]).ok is False

        # Attempt to both constraints. Without the bug fix Igor would only add
        # the first one, whereas with the bug fix it adds both.
        assert igor.reset().ok
        assert igor.addConstraints([c1, c2]) == (True, None, [True] * 2)

        # Update the local cache and verify that really both constraints are
        # available.
        assert igor.updateLocalCache() == (True, None, 2)
        assert sorted(igor.getConstraints(None).data) == sorted((c1, c2))
Beispiel #7
0
    def test_update_and_add(self, getCon):
        """
        Verify that 'updateLocalCache' downloads the correct number of
        constraints.
        """
        # Convenience.
        igor = self.igor
        igor.reset()

        # Create the constraints for this test.
        c1 = getCon('foo', 1, 2)
        c2 = getCon('foo', 2, 3)
        c3 = getCon('foo', 3, 4)
        c4 = getCon('foo', 4, 5)
        c5 = getCon('foo', 5, 6)
        c6 = getCon('foo', 6, 7)

        # There must not be any objects to download.
        assert igor.updateLocalCache() == (True, None, 0)

        # Pass an empty list.
        assert igor.addConstraints([]) == (True, None, 0)

        # Add one constraint and update the cache.
        assert igor.addConstraints([c1]) == (True, None, 1)
        assert igor.updateLocalCache() == (True, None, 1)

        # Add the same constraint. This must add no constraint, but the update
        # function must still fetch exactly one constraint.
        assert igor.addConstraints([c1]) == (True, None, 0)
        assert igor.updateLocalCache() == (True, None, 1)

        # Add two new constraints.
        assert igor.addConstraints([c2, c3]) == (True, None, 2)
        assert igor.updateLocalCache() == (True, None, 3)

        # Add two more constraints, one of which is not new. This must add one
        # new constraint and increase the total number of unique constraints to
        # four.
        assert igor.addConstraints([c3, c4]) == (True, None, 1)
        assert igor.updateLocalCache() == (True, None, 4)

        # Add five more constaints, but only two of them are actually unique.
        assert igor.addConstraints([c5, c5, c6, c6, c6]) == (True, None, 2)
        assert igor.updateLocalCache() == (True, None, 6)
        ref = sorted((c1, c2, c3, c4, c5, c6))
        assert sorted(igor.getConstraints(None).data) == ref

        # Reset igor and add two constraints, of which only one has a valid
        # 'contype'. The 'addConstraints' must only add the valid one.
        c6 = c6._replace(contype='foo')
        assert igor.reset().ok
        assert igor.addConstraints([c1, c6]) == (True, None, 1)
        assert igor.updateLocalCache() == (True, None, 1)
Beispiel #8
0
    def test_update_and_add(self, getCon):
        """
        Verify that 'updateLocalCache' downloads the correct number of
        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')
        c4 = getCon('foo', '4', '5')
        c5 = getCon('foo', '5', '6')
        c6 = getCon('foo', '6', '7')

        # There must not be any objects to download.
        assert igor.updateLocalCache() == (True, None, 0)

        # Pass an empty list.
        assert igor.addConstraints([]) == (True, None, 0)

        # Add one constraint and update the cache.
        assert igor.addConstraints([c1]) == (True, None, [True])
        assert igor.updateLocalCache() == (True, None, 1)

        # Add the same constraint. This must add no constraint, but the update
        # function must still fetch exactly one constraint.
        assert igor.addConstraints([c1]) == (True, None, [False])
        assert igor.updateLocalCache() == (True, None, 1)

        # Add two new constraints.
        assert igor.addConstraints([c2, c3]) == (True, None, [True] * 2)
        assert igor.updateLocalCache() == (True, None, 3)

        # Add two more constraints, one of which is not new. This must add one
        # new constraint and increase the total number of unique constraints to
        # four.
        assert igor.addConstraints([c3, c4]) == (True, None, [False, True])
        assert igor.updateLocalCache() == (True, None, 4)

        # Add five more constraints, only two of which are actually unique.
        # This must return with an error and do nothing.
        assert igor.addConstraints([c5, c5, c6, c6, c6]).ok is False
        assert igor.updateLocalCache() == (True, None, 4)
        ref = sorted((c1, c2, c3, c4))
        assert sorted(igor.getConstraints(None).data) == ref

        # Reset igor and add two constraints. Only one has a valid
        # 'contype'. The 'addConstraints' must only add the valid one.
        c6 = c6._replace(contype='foo')
        assert igor.reset().ok
        assert igor.addConstraints([c1, c6]).ok is False
        assert igor.updateLocalCache() == (True, None, 0)
Beispiel #9
0
    def test_update_and_add(self, getCon):
        """
        Verify that 'updateLocalCache' downloads the correct number of
        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')
        c4 = getCon('foo', '4', '5')
        c5 = getCon('foo', '5', '6')
        c6 = getCon('foo', '6', '7')

        # There must not be any objects to download.
        assert igor.updateLocalCache() == (True, None, 0)

        # Pass an empty list.
        assert igor.addConstraints([]) == (True, None, 0)

        # Add one constraint and update the cache.
        assert igor.addConstraints([c1]) == (True, None, [True])
        assert igor.updateLocalCache() == (True, None, 1)

        # Add the same constraint. This must add no constraint, but the update
        # function must still fetch exactly one constraint.
        assert igor.addConstraints([c1]) == (True, None, [False])
        assert igor.updateLocalCache() == (True, None, 1)

        # Add two new constraints.
        assert igor.addConstraints([c2, c3]) == (True, None, [True] * 2)
        assert igor.updateLocalCache() == (True, None, 3)

        # Add two more constraints, one of which is not new. This must add one
        # new constraint and increase the total number of unique constraints to
        # four.
        assert igor.addConstraints([c3, c4]) == (True, None, [False, True])
        assert igor.updateLocalCache() == (True, None, 4)

        # Add five more constraints, only two of which are actually unique.
        # This must return with an error and do nothing.
        assert igor.addConstraints([c5, c5, c6, c6, c6]).ok is False
        assert igor.updateLocalCache() == (True, None, 4)
        ref = sorted((c1, c2, c3, c4))
        assert sorted(igor.getConstraints(None).data) == ref

        # Reset igor and add two constraints. Only one has a valid
        # 'contype'. The 'addConstraints' must only add the valid one.
        c6 = c6._replace(contype='foo')
        assert igor.reset().ok
        assert igor.addConstraints([c1, c6]).ok is False
        assert igor.updateLocalCache() == (True, None, 0)
Beispiel #10
0
    def test_getConstraint(self, getCon):
        """
        Verify that Igor returns the correct 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)

        # Query the constraints for bodies that do not feature in any
        # constraints.
        assert igor.reset() == (True, None, None)
        assert igor.getConstraints([]) == (True, None, tuple())
        assert igor.getConstraints([1]) == (True, None, tuple())
        assert igor.getConstraints([1, 2]) == (True, None, tuple())

        # Add four constraints for the following tests.
        assert igor.addConstraints([c1, c2, c3]) == (True, None, 3)

        # Query the constraints that involve object one. This must return only
        # the first object, and only *after* the local Igor cache was updated.
        assert igor.getConstraints([1]) == (True, None, ())
        assert igor.updateLocalCache() == (True, None, 3)
        ret = igor.getConstraints([1])
        assert ret.data == (c1, )

        # Query the constraints that involve body 1 & 5. This must again return
        # only a single hit because body 5 is not part of any constraint.
        ret = igor.getConstraints([1, 5])
        assert ret.data == (c1, )

        # Objects 1 & 4 feature in to individual constraints.
        ret = igor.getConstraints([1, 4])
        assert sorted(ret.data) == sorted((c1, c3))

        # Objects 1 & 2 & 4 feature in all three constraints.
        ret = igor.getConstraints([1, 2, 4])
        assert len(ret.data) == 3
        assert sorted(ret.data) == sorted((c1, c2, c3))

        # Body 2 features in two constraints whereas body 10 features in none.
        ret = igor.getConstraints([2, 10])
        assert sorted(ret.data) == sorted((c1, c2))
Beispiel #11
0
    def test_getConstraint(self, getCon):
        """
        Verify that Igor returns the correct 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')

        # Query the constraints for bodies that do not feature in any
        # constraints.
        assert igor.getConstraints([]) == (True, None, tuple())
        assert igor.getConstraints([1]) == (True, None, tuple())
        assert igor.getConstraints([1, 2]) == (True, None, tuple())

        # Add four constraints for the following tests.
        assert igor.addConstraints([c1, c2, c3]) == (True, None, [True] * 3)

        # Query the constraints that involve object one. This must return only
        # the first object, and only *after* the local Igor cache was updated.
        assert igor.getConstraints(['1']) == (True, None, ())
        assert igor.updateLocalCache() == (True, None, 3)
        ret = igor.getConstraints(['1'])
        assert ret.data == (c1, )

        # Query the constraints that involve body 1 & 5. This must again return
        # only a single hit because body 5 is not part of any constraint.
        ret = igor.getConstraints(['1', '5'])
        assert ret.data == (c1, )

        # Objects 1 & 4 feature in to individual constraints.
        ret = igor.getConstraints(['1', '4'])
        assert sorted(ret.data) == sorted((c1, c3))

        # Objects 1 & 2 & 4 feature in all three constraints.
        ret = igor.getConstraints(['1', '2', '4'])
        assert len(ret.data) == 3
        assert sorted(ret.data) == sorted((c1, c2, c3))

        # Body 2 features in two constraints whereas body 10 features in none.
        ret = igor.getConstraints(['2', '10'])
        assert sorted(ret.data) == sorted((c1, c2))
Beispiel #12
0
    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, )
Beispiel #13
0
    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 nor delete anything.
        assert igor.reset().ok
        assert igor.removeConstraints([c1]) == (True, None, 0)
        assert igor.removeConstraints([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, [True] * 3)
        assert igor.updateLocalCache() == (True, None, 3)
        assert igor.removeConstraints([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, [True] * 3)
        assert igor.removeConstraints([c1, c2]) == (True, None, 2)
        assert igor.removeConstraints([c1, c2]) == (True, None, 0)
        assert igor.addConstraints([c1, c2]) == (True, None, [True] * 2)
        assert igor.removeConstraints([c1]) == (True, None, 1)
        assert igor.removeConstraints([c1, c2]) == (True, None, 1)
        assert igor.removeConstraints([c1, c2]) == (True, None, 0)
        assert igor.updateLocalCache() == (True, None, 1)
        assert igor.getConstraints(None).data == (c3, )