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_roots.py 1.6KB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. from twisted.python import roots
  4. from twisted.trial import unittest
  5. class RootsTests(unittest.TestCase):
  6. def testExceptions(self):
  7. request = roots.Request()
  8. try:
  9. request.write(b"blah")
  10. except NotImplementedError:
  11. pass
  12. else:
  13. self.fail()
  14. try:
  15. request.finish()
  16. except NotImplementedError:
  17. pass
  18. else:
  19. self.fail()
  20. def testCollection(self):
  21. collection = roots.Collection()
  22. collection.putEntity("x", "test")
  23. self.assertEqual(collection.getStaticEntity("x"), "test")
  24. collection.delEntity("x")
  25. self.assertEqual(collection.getStaticEntity("x"), None)
  26. try:
  27. collection.storeEntity("x", None)
  28. except NotImplementedError:
  29. pass
  30. else:
  31. self.fail()
  32. try:
  33. collection.removeEntity("x", None)
  34. except NotImplementedError:
  35. pass
  36. else:
  37. self.fail()
  38. def testConstrained(self):
  39. class const(roots.Constrained):
  40. def nameConstraint(self, name):
  41. return name == "x"
  42. c = const()
  43. self.assertIsNone(c.putEntity("x", "test"))
  44. self.assertRaises(roots.ConstraintViolation, c.putEntity, "y", "test")
  45. def testHomogenous(self):
  46. h = roots.Homogenous()
  47. h.entityType = int
  48. h.putEntity("a", 1)
  49. self.assertEqual(h.getStaticEntity("a"), 1)
  50. self.assertRaises(roots.ConstraintViolation, h.putEntity, "x", "y")