def edit_device_profile(device_profile_path, message): resp = '' result = None try: env = environment.get(environment.InProcessTestEnvironment) url = "http://%s:%d/profile.html" % (env.server.addr[0], env.server.addr[1]) webbrowser.open(url) environment.env.handler = server.wait_for_client() resp = environment.env.handler.prompt(message) message = 'Create device profile failed!!' if resp: result = json.loads(resp) if result['return'] == 'ok': with open(device_profile_path, 'w') as device_profile_f: json.dump(result, device_profile_f, indent=4) message = 'Create device profile successfully!!' else: message = 'Create device profile is cancelled by user!!' else: message = '' logger.info(message) except: logger.error("Failed create device profile:\n%s" % traceback.format_exc()) return result
def run(suite, logger, spawn_browser=True, verbosity=1, quiet=False, failfast=False, catch_break=False, buffer=True, **kwargs): """A simple test runner. This test runner is essentially equivalent to ``unittest.main`` from the standard library, but adds support for loading test classes with extra keyword arguments. The easiest way to run a test is via the command line:: python -m semiauto test_sms See the standard library unittest module for ways in which tests can be specified. For example it is possible to automatically discover tests:: python -m semiauto discover .""" if catch_break: import unittest.signals unittest.signals.installHandler() env = environment.get(environment.InProcessTestEnvironment, addr=None if spawn_browser else ("127.0.0.1", 6666), verbose=(verbosity > 1)) url = "http://%s:%d/" % (env.server.addr[0], env.server.addr[1]) if spawn_browser: import webbrowser webbrowser.open(url) else: print >> sys.stderr, "Please connect your browser to %s" % url # Wait for browser to connect and get socket connection to client try: so = server.wait_for_client() except server.ConnectError as e: logger.error("%s: error: %s" % (sys.argv[0], e)) sys.exit(1) tests = serialize_suite(suite) test_runner = StructuredTestRunner(logger=logger, test_list=tests) # This is a hack to make the test suite metadata and the handler # available to the tests. so.suite = suite environment.env.handler = so logger.suite_start(tests=tests) try: results = test_runner.run(suite) except (SystemExit, KeyboardInterrupt) as e: sys.exit(1) logger.suite_end() return results
def run(suite, logger=None, spawn_browser=True, verbosity=1, quiet=False, failfast=False, catch_break=False, buffer=True, **kwargs): """A simple test runner. This test runner is essentially equivalent to ``unittest.main`` from the standard library, but adds support for loading test classes with extra keyword arguments. The easiest way to run a test is via the command line:: python -m semiauto test_sms See the standard library unittest module for ways in which tests can be specified. For example it is possible to automatically discover tests:: python -m semiauto discover . """ if catch_break: import unittest.signals unittest.signals.installHandler() if not logger: logger = create_logger() env = environment.get(environment.InProcessTestEnvironment, addr=("localhost", get_free_port(6666)), verbose=(verbosity > 1)) url = "http://%s:%d/" % (env.server.addr[0], env.server.addr[1]) if spawn_browser: import webbrowser webbrowser.open(url) else: print >> sys.stderr, "Please connect your browser to %s" % url # Wait for browser to connect and get socket connection to client try: so = server.wait_for_client() except server.ConnectError as e: print >> sys.stderr, "%s: error: %s" % (sys.argv[0], e) sys.exit(1) tests = runner.serialize_suite(suite) test_runner = StructuredTestRunner(logger=logger, test_list=tests) # This is a hack to make the test suite metadata and the handler # available to the tests. so.suite = suite environment.env.handler = so logger.add_handler(runner.WSHandler(so)) try: results = test_runner.run(suite) except (SystemExit, KeyboardInterrupt) as e: sys.exit(1) return results