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.

testutil.py 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ###############################################################################
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) typedef int GmbH
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. ###############################################################################
  26. class FakeTransport(object):
  27. _written = b""
  28. _open = True
  29. def __init__(self):
  30. self._abort_calls = []
  31. def abortConnection(self, *args, **kw):
  32. self._abort_calls.append((args, kw))
  33. def write(self, msg):
  34. if not self._open:
  35. raise Exception("Can't write to a closed connection")
  36. self._written = self._written + msg
  37. def loseConnection(self):
  38. self._open = False
  39. def registerProducer(self, producer, streaming):
  40. # https://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IConsumer.html
  41. raise NotImplementedError
  42. def unregisterProducer(self):
  43. # do nothing is correct! until we fake implement registerProducer ..;)
  44. pass
  45. def getPeer(self):
  46. # for Twisted, this would be an IAddress
  47. class _FakePeer(object):
  48. pass
  49. return _FakePeer()
  50. def getHost(self):
  51. # for Twisted, this would be an IAddress
  52. class _FakeHost(object):
  53. pass
  54. return _FakeHost()
  55. def abort_called(self):
  56. return len(self._abort_calls) > 0