Best Python code snippet using localstack_python
runtest.py
Source:runtest.py
...10 env = TestFileEnvironment(os.path.join(here, 'test-data'))11 return env12stage_seq = ['create-node', 'setup-node', 'clean', 'update', 'update-path',13 'logs', 'query', 'activation', 'backup-update', 'backup-clear']14def run_stage(name, match):15 return match in stage_seq[stage_seq.index(name):]16def run_test(name, stage=None, ci=False, setup_node=False):17 try:18 if stage is None:19 if name:20 stage = 'clean'21 else:22 stage = 'setup-node'23 env = get_environment()24 if not name:25 name = 'functest%s.example.com' % int(time.time())26 print 'Creating node %s' % name27 print env.run('silver --yes create-node --wait %s' % name,28 expect_stderr=True)29 if run_stage(stage, 'setup-node') or setup_node:30 print 'Setting up node %s' % name31 print env.run('silver --yes setup-node %s' % name,32 expect_stderr=True)33 if run_stage(stage, 'clean'):34 print env.run('silver --yes deactivate --node=%s "*"' % name)35 print env.run('silver --yes clean-node %s' % name)36 if run_stage(stage, 'update'):37 print 'Doing update'38 result = env.run('silver --yes update "%s" %s'39 % (os.path.join(here, 'example-app'), name),40 expect_stderr=True)41 print result42 assert 'env CONFIG_COUCHDB_DB=functest' in result.stdout, result.stdout43 assert 'env CONFIG_COUCHDB_HOST=127.0.0.1:5984' in result.stdout, result.stdout44 assert 'env CONFIG_FILES=/var/lib/silverlining/apps/functest' in result.stdout, result.stdout45 assert 'env CONFIG_PG_DBNAME=functest' in result.stdout, result.stdout46 assert 'env CONFIG_PG_HOST=' in result.stdout, result.stdout47 assert 'env CONFIG_PG_PASSWORD=' in result.stdout, result.stdout48 assert 'env CONFIG_PG_PORT=' in result.stdout, result.stdout49 assert 'env CONFIG_PG_SQLALCHEMY=postgres://postgres@/functest' in result.stdout, result.stdout50 assert 'env CONFIG_PG_USER=www-mgr' in result.stdout, result.stdout51 assert 'env CONFIG_WRITABLE_ROOT=/var/lib/silverlining/writable-roots/functest' in result.stdout, result.stdout52 assert 'env SILVER_VERSION=silverlining/' in result.stdout, result.stdout53 result = env.run('silver --yes update --debug-single-process "%s" %s'54 % (os.path.join(here, 'example-app'), name),55 expect_stderr=True)56 print result57 resp = urllib.urlopen('http://%s/update' % name).read()58 print 'Got HTTP response:\n%s' % resp59 assert ('SILVER_CANONICAL_HOSTNAME=%s' % name) in resp60 assert 'wsgi.multiprocess=True' in resp61 assert 'wsgi.multithread=True' in resp62 assert "path='' '/update'" in resp63 resp = urllib.urlopen('http://%s/static_file.txt' % name).read()64 print 'Got static HTTP response:\n%s' % resp65 assert resp.strip() == 'This is a test'66 resp = urllib.urlopen('http://%s/write-root' % name).read()67 assert resp.strip().startswith('WRITABLE_ROOT='), resp68 resp = urllib.urlopen('http://%s/test-writable.txt' % name).read()69 assert resp.strip() == 'test writable', resp70 resp = urllib.urlopen('http://%s/test-hosted.txt' % name).read()71 assert resp.strip() == 'test hosted', resp72 if run_stage(stage, 'update-path'):73 print 'Doing update to path'74 result = env.run('silver --yes update "%s" %s/test'75 % (os.path.join(here, 'example-app'), name),76 expect_stderr=True)77 print result78 url = 'http://%s/test/update' % name79 resp = urllib.urlopen(url).read()80 print 'The actual HTTP response: (%s)' % url81 print resp82 if run_stage(stage, 'logs'):83 print 'Doing log check'84 ssh('www-data', name, ['bash', '-c', 'rm /var/log/silverlining/apps/functest/*'])85 url = 'http://%s/test/update' % name86 resp = urllib.urlopen(url).read()87 text, _, _ = ssh('www-data', name,88 ['cat', '/var/log/silverlining/apps/functest/errors.log'],89 capture_stdout=True)90 text_lines = ''.join(text.strip().splitlines(True)[1:-1]).strip()91 assert text_lines == """\92Executed application93This is stdout94This is stderr""", repr(text_lines)95 if run_stage(stage, 'query'):96 print 'Doing query'97 result = env.run('silver --yes query %s' % name)98 print result99 assert 'Site: default-disabled' in result.stdout100 assert 'default-disabled: disabled/' in result.stdout101 assert 'functest' in result.stdout102 assert re.search(r'functest.*?: %s/' % name, result.stdout)103 if run_stage(stage, 'activation'):104 print env.run('silver --yes deactivate %s/test' % name)105 print env.run('silver --yes query %s' % name)106 print env.run('silver --yes activate %s prev' % name)107 print env.run('silver --yes query %s' % name)108 if run_stage(stage, 'backup-update'):109 print env.run('silver --yes deactivate --node=%s "*"' % name)110 print env.run('silver --yes update "%s" %s'111 % (os.path.join(here, 'example-backup'), name),112 expect_stderr=True)113 url = 'http://%s/' % name114 resp = urllib.urlopen(url).read()115 print resp116 resp = env.run('silver --yes backup %s/ test-backup/' % name)117 print resp118 assert 'test-backup/mysql/mysql.dump' in resp.files_created119 assert 'test-backup/files/files.tar' in resp.files_created120 if run_stage(stage, 'backup-clear'):121 print env.run('silver --yes clear %s' % name)122 resp = env.run('silver --yes backup %s/ test-backup-cleared/' % name)123 print resp124 assert 'test_table' not in resp.files_created['test-backup-cleared/mysql/mysql.dump'].bytes125 urllib.urlopen('http://'+name).read()126 resp = env.run('silver --yes backup %s/ test-backup-bare/' % name)127 print resp128 assert 'test_table' in resp.files_created['test-backup-bare/mysql/mysql.dump'].bytes129 print env.run('silver --yes clear %s' % name)130 resp = env.run('silver --yes restore test-backup-bare/ %s' % name)131 print resp132 resp = env.run('silver --yes backup %s/ test-backup-restored/' % name)133 assert 'test_table' in resp.files_created['test-backup-restored/mysql/mysql.dump'].bytes134 finally:...
releasecheck.py
Source:releasecheck.py
2from os.path import join, basename, normpath3from subprocess import check_call4def main(version, outdir):5 check_version(version, outdir)6 run_stage(['bin/mailmap_update.py'])7 run_stage(['bin/authors_update.py'])8 run_stage(['mkdir', '-p', outdir])9 build_release_files('bdist_wheel', 'sympy-%s-py3-none-any.whl', outdir, version)10 build_release_files('sdist', 'sympy-%s.tar.gz', outdir, version)11 run_stage(['release/compare_tar_against_git.py', join(outdir, 'sympy-%s.tar.gz' % (version,)), '.'])12 run_stage(['release/test_install.py', version, outdir])13 run_stage(['release/build_docs.py', version, outdir])14 run_stage(['release/sha256.py', version, outdir])15 run_stage(['release/authors.py', version, outdir])16def green(text):17 return "\033[32m%s\033[0m" % text18def red(text):19 return "\033[31m%s\033[0m" % text20def print_header(color, *msgs):21 newlines = '\n'22 vline = '-' * 8023 print(color(newlines + vline))24 for msg in msgs:25 print(color(msg))26 print(color(vline + newlines))27def run_stage(cmd):28 cmdline = ' $ %s' % (' '.join(cmd),)29 print_header(green, 'running:', cmdline)30 try:31 check_call(cmd)32 except Exception as e:33 print_header(red, 'failed:', cmdline)34 raise e from None35 else:36 print_header(green, 'completed:', cmdline)37def build_release_files(cmd, fname, outdir, version):38 fname = fname % (version,)39 run_stage(['python', 'setup.py', '-q', cmd])40 src = join('dist', fname)41 dst = join(outdir, fname)42 run_stage(['mv', src, dst])43def check_version(version, outdir):44 from sympy.release import __version__ as checked_out_version45 if version != checked_out_version:46 msg = "version %s does not match checkout %s"47 raise AssertionError(msg % (version, checked_out_version))48 if basename(normpath(outdir)) != 'release-%s' % (version,):49 msg = "version %s does not match output directory %s"50 raise AssertionError(msg % (version, outdir))51if __name__ == "__main__":52 import sys...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!