PageRenderTime 65ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/tests/test_llxmlrpc_peer.py

https://bitbucket.org/lindenlab/viewer-beta/
Python | 81 lines | 29 code | 8 blank | 44 comment | 4 complexity | 62ae78c760dd81fe0b4f9a9a800c0264 MD5 | raw file
Possible License(s): LGPL-2.1
  1. #!/usr/bin/env python
  2. """\
  3. @file test_llxmlrpc_peer.py
  4. @author Nat Goodspeed
  5. @date 2008-10-09
  6. @brief This script asynchronously runs the executable (with args) specified on
  7. the command line, returning its result code. While that executable is
  8. running, we provide dummy local services for use by C++ tests.
  9. $LicenseInfo:firstyear=2008&license=viewerlgpl$
  10. Second Life Viewer Source Code
  11. Copyright (C) 2010, Linden Research, Inc.
  12. This library is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU Lesser General Public
  14. License as published by the Free Software Foundation;
  15. version 2.1 of the License only.
  16. This library is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. Lesser General Public License for more details.
  20. You should have received a copy of the GNU Lesser General Public
  21. License along with this library; if not, write to the Free Software
  22. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. $/LicenseInfo$
  25. """
  26. import os
  27. import sys
  28. from threading import Thread
  29. from SimpleXMLRPCServer import SimpleXMLRPCServer
  30. mydir = os.path.dirname(__file__) # expected to be .../indra/newview/tests/
  31. sys.path.insert(0, os.path.join(mydir, os.pardir, os.pardir, "lib", "python"))
  32. sys.path.insert(1, os.path.join(mydir, os.pardir, os.pardir, "llmessage", "tests"))
  33. from testrunner import freeport, run, debug
  34. class TestServer(SimpleXMLRPCServer):
  35. def _dispatch(self, method, params):
  36. try:
  37. func = getattr(self, method)
  38. except AttributeError:
  39. raise Exception('method "%s" is not supported' % method)
  40. else:
  41. # LLXMLRPCListener constructs XMLRPC parameters that arrive as a
  42. # 1-tuple containing a dict.
  43. return func(**(params[0]))
  44. def hello(self, who):
  45. # LLXMLRPCListener expects a dict return.
  46. return {"hi_there": "Hello, %s!" % who}
  47. def getdict(self):
  48. return dict(nested_dict=dict(a=17, b=5))
  49. def log_request(self, code, size=None):
  50. # For present purposes, we don't want the request splattered onto
  51. # stderr, as it would upset devs watching the test run
  52. pass
  53. def log_error(self, format, *args):
  54. # Suppress error output as well
  55. pass
  56. if __name__ == "__main__":
  57. # Instantiate a TestServer on the first free port in the specified port
  58. # range. Doing this inline is better than in a daemon thread: if it blows
  59. # up here, we'll get a traceback. If it blew up in some other thread, the
  60. # traceback would get eaten and we'd run the subject test program anyway.
  61. xmlrpcd, port = freeport(xrange(8000, 8020),
  62. lambda port: TestServer(('127.0.0.1', port)))
  63. # Pass the selected port number to the subject test program via the
  64. # environment. We don't want to impose requirements on the test program's
  65. # command-line parsing -- and anyway, for C++ integration tests, that's
  66. # performed in TUT code rather than our own.
  67. os.environ["PORT"] = str(port)
  68. sys.exit(run(server=Thread(name="xmlrpc", target=xmlrpcd.serve_forever), *sys.argv[1:]))