Apache/2.4.7 (Ubuntu) Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) safemode : OFF MySQL: ON | Perl: ON | cURL: OFF | WGet: ON > / usr / lib / python2.7 / dist-packages / twisted / test / | server ip : 172.67.156.115 your ip : 172.70.80.31 H O M E |
Filename | /usr/lib/python2.7/dist-packages/twisted/test/test_context.py |
Size | 1.49 kb |
Permission | rw-r--r-- |
Owner | root : root |
Create time | 27-Apr-2025 09:56 |
Last modified | 24-Sep-2012 22:46 |
Last accessed | 06-Jul-2025 21:55 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.python.context}.
"""
from __future__ import division, absolute_import
from twisted.trial.unittest import SynchronousTestCase
from twisted.python import context
class ContextTest(SynchronousTestCase):
"""
Tests for the module-scope APIs for L{twisted.python.context}.
"""
def test_notPresentIfNotSet(self):
"""
Arbitrary keys which have not been set in the context have an associated
value of C{None}.
"""
self.assertEqual(context.get("x"), None)
def test_setByCall(self):
"""
Values may be associated with keys by passing them in a dictionary as
the first argument to L{twisted.python.context.call}.
"""
self.assertEqual(context.call({"x": "y"}, context.get, "x"), "y")
def test_unsetAfterCall(self):
"""
After a L{twisted.python.context.call} completes, keys specified in the
call are no longer associated with the values from that call.
"""
context.call({"x": "y"}, lambda: None)
self.assertEqual(context.get("x"), None)
def test_setDefault(self):
"""
A default value may be set for a key in the context using
L{twisted.python.context.setDefault}.
"""
key = object()
self.addCleanup(context.defaultContextDict.pop, key, None)
context.setDefault(key, "y")
self.assertEqual("y", context.get(key))
# See LICENSE for details.
"""
Tests for L{twisted.python.context}.
"""
from __future__ import division, absolute_import
from twisted.trial.unittest import SynchronousTestCase
from twisted.python import context
class ContextTest(SynchronousTestCase):
"""
Tests for the module-scope APIs for L{twisted.python.context}.
"""
def test_notPresentIfNotSet(self):
"""
Arbitrary keys which have not been set in the context have an associated
value of C{None}.
"""
self.assertEqual(context.get("x"), None)
def test_setByCall(self):
"""
Values may be associated with keys by passing them in a dictionary as
the first argument to L{twisted.python.context.call}.
"""
self.assertEqual(context.call({"x": "y"}, context.get, "x"), "y")
def test_unsetAfterCall(self):
"""
After a L{twisted.python.context.call} completes, keys specified in the
call are no longer associated with the values from that call.
"""
context.call({"x": "y"}, lambda: None)
self.assertEqual(context.get("x"), None)
def test_setDefault(self):
"""
A default value may be set for a key in the context using
L{twisted.python.context.setDefault}.
"""
key = object()
self.addCleanup(context.defaultContextDict.pop, key, None)
context.setDefault(key, "y")
self.assertEqual("y", context.get(key))