Beispiel #1
0
 def test_setIDFunction(self):
     """
     L{util.setIDFunction} returns the last value passed to it.
     """
     value = object()
     previous = util.setIDFunction(value)
     result = util.setIDFunction(previous)
     self.assertIdentical(value, result)
Beispiel #2
0
 def test_setIDFunction(self):
     """
     L{util.setIDFunction} returns the last value passed to it.
     """
     value = object()
     previous = util.setIDFunction(value)
     result = util.setIDFunction(previous)
     self.assertIdentical(value, result)
Beispiel #3
0
    def test_unsignedID(self):
        """
        L{util.unsignedID} uses the function passed to L{util.setIDFunction} to
        determine the unique integer id of an object and then adjusts it to be
        positive if necessary.
        """
        foo = object()
        bar = object()

        # A fake object identity mapping
        objects = {foo: 17, bar: -73}
        def fakeId(obj):
            return objects[obj]

        util.setIDFunction(fakeId)

        self.assertEquals(util.unsignedID(foo), 17)
        self.assertEquals(util.unsignedID(bar), (sys.maxint + 1) * 2 - 73)
Beispiel #4
0
    def test_unsignedID(self):
        """
        L{util.unsignedID} uses the function passed to L{util.setIDFunction} to
        determine the unique integer id of an object and then adjusts it to be
        positive if necessary.
        """
        foo = object()
        bar = object()

        # A fake object identity mapping
        objects = {foo: 17, bar: -73}

        def fakeId(obj):
            return objects[obj]

        util.setIDFunction(fakeId)

        self.assertEquals(util.unsignedID(foo), 17)
        self.assertEquals(util.unsignedID(bar), (sys.maxint + 1) * 2 - 73)
Beispiel #5
0
 def test_str(self):
     """
     The string representation of a L{DelayedCall} instance, as returned by
     C{str}, includes the unsigned id of the instance, as well as its state,
     the function to be called, and the function arguments.
     """
     def nothing():
         pass
     dc = DelayedCall(12, nothing, (3, ), {"A": 5}, None, None, lambda: 1.5)
     ids = {dc: 200}
     def fakeID(obj):
         try:
             return ids[obj]
         except (TypeError, KeyError):
             return id(obj)
     self.addCleanup(setIDFunction, setIDFunction(fakeID))
     self.assertEquals(
         str(dc),
         "<DelayedCall 0xc8 [10.5s] called=0 cancelled=0 nothing(3, A=5)>")