Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_context.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Tests for L{twisted.python.context}.
  5. """
  6. from twisted.python import context
  7. from twisted.trial.unittest import SynchronousTestCase
  8. class ContextTests(SynchronousTestCase):
  9. """
  10. Tests for the module-scope APIs for L{twisted.python.context}.
  11. """
  12. def test_notPresentIfNotSet(self):
  13. """
  14. Arbitrary keys which have not been set in the context have an associated
  15. value of L{None}.
  16. """
  17. self.assertIsNone(context.get("x"))
  18. def test_setByCall(self):
  19. """
  20. Values may be associated with keys by passing them in a dictionary as
  21. the first argument to L{twisted.python.context.call}.
  22. """
  23. self.assertEqual(context.call({"x": "y"}, context.get, "x"), "y")
  24. def test_unsetAfterCall(self):
  25. """
  26. After a L{twisted.python.context.call} completes, keys specified in the
  27. call are no longer associated with the values from that call.
  28. """
  29. context.call({"x": "y"}, lambda: None)
  30. self.assertIsNone(context.get("x"))
  31. def test_setDefault(self):
  32. """
  33. A default value may be set for a key in the context using
  34. L{twisted.python.context.setDefault}.
  35. """
  36. key = object()
  37. self.addCleanup(context.defaultContextDict.pop, key, None)
  38. context.setDefault(key, "y")
  39. self.assertEqual("y", context.get(key))