/usr/lib/python3/dist-packages/twisted/test/test_context.py is in python3-twisted-experimental 13.2.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # 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))
|