def restart_server(**extra_env): global server, server_out, server_options for key in extra_env: extra_env[key] = str(extra_env[key]) if server and server_options == extra_env: print(" Server already started with correct options") return stop_server() env = os.environ.copy() env.update(extra_env) env['PORT'] = '10180' env['SITE_ORIGIN'] = 'localhost:10180' env['CONTENT_ORIGIN'] = 'localhost:10180' env['GA_ID'] = '' env['DEBUG_GOOGLE_ANALYTICS'] = '' env['NODE_ENV'] = 'production' env['LOG_QUERY_LIMIT'] = '0' env['ENABLE_WATCHDOG'] = 'false' server_out = Capture() env_print = [ '%s=%s' % (name, value) for name, value in sorted(extra_env.items()) ] if env_print: env_print = ' (%s)' % ' '.join(env_print) else: env_print = '' print(' Starting server%s' % env_print) server = run('./bin/run-server --no-auto', cwd=project_base, env=env, stdout=server_out, async=True) server_options = extra_env time.sleep(3) text = [] while True: if server.commands[0].process and server.commands[0].poll(): print(' Server exited with code %s' % server.commands[0].poll()) text.extend(server_out.readlines()) for line in text: print(' %s' % line.rstrip()) print(" %s" % ("-" * 60)) raise Exception("Server didn't start") line = server_out.readline() if line: text.append(line) if 'Database is now at level' in line: # Last log message before the server is running break if 'skip-db-down-patches' in line: break print(" Server started")
def restart_server(**extra_env): global server, server_out, server_options for key in extra_env: extra_env[key] = str(extra_env[key]) if server and server_options == extra_env: print(" Server already started with correct options") return stop_server() env = os.environ.copy() env.update(extra_env) env['PORT'] = '10180' env['SITE_ORIGIN'] = 'localhost:10180' env['CONTENT_ORIGIN'] = 'localhost:10180' env['GA_ID'] = '' env['NODE_ENV'] = 'production' env['LOG_QUERY_LIMIT'] = '0' env['ENABLE_WATCHDOG'] = 'false' server_out = Capture() env_print = ['%s=%s' % (name, value) for name, value in sorted(extra_env.items())] if env_print: env_print = ' (%s)' % ' '.join(env_print) else: env_print = '' print(' Starting server%s' % env_print) server = run('./bin/run-server --no-auto', cwd=project_base, env=env, stdout=server_out, async_=True) server_options = extra_env time.sleep(3) text = [] while True: if server.commands[0].process and server.commands[0].poll(): print(' Server exited with code %s' % server.commands[0].poll()) text.extend(server_out.readlines()) for line in text: print(' %s' % line.rstrip()) print(" %s" % ("-" * 60)) raise Exception("Server didn't start") line = server_out.readline() if line: text.append(line) if 'Database is now at level' in line: # Last log message before the server is running break if 'skip-db-down-patches' in line: break print(" Server started")
import re from sarge import Capture, Feeder, run f = Feeder() c = Capture(buffer_size=1) p = run('python login_test.py', async_=True, stdout=c, input=f) c.expect('Username:'******'input username') f.feed('user\n') c.expect('Password:'******'input password') f.feed('pass\n') VERIFICATION_CODE_REGEX = re.compile(rb'Input verification code \((\d{4})\): ') match = c.expect(VERIFICATION_CODE_REGEX) print('input verification code', match.group(1)) f.feed(match.group(1) + b'\n') c.expect('>>>', timeout=5) f.feed('print(1 + 1)\n') f.feed('exit()\n') p.wait() print('final output:\n', b''.join(c.readlines()).decode('utf-8'))