Best Python code snippet using tempest_python
test.py
Source:test.py
1#!/usr/bin/env python2import subprocess3import getopt4import signal5import time6import sys7numfail = 08fix_tests = [9 #10 # FIX session level test cases. See Volume 2 of the FIX 4.4 specification for11 # details.12 #13 "2b_MsgSeqNumHigherThanExpected",14 "2c_MsgSeqNumLowerThanExpected",15 "4b_TestRequestMessageIsReceived"16]17def green(s):18 return "\033[32m" + s + "\033[0m"19def red(s):20 return "\033[31m" + s + "\033[0m"21try:22 opts, args = getopt.getopt(sys.argv[1:], "v")23except getopt.GetoptError, err:24 print str(err)25 sys.exit(1)26verbose = 027for o, a in opts:28 if o == "-v":29 verbose += 130if verbose == 2:31 out = open('/dev/stdout', 'w')32 err = open('/dev/stderr', 'w')33else:34 out = open('/dev/null', 'w')35 err = open('/dev/null', 'w')36def popen_fix_server():37 args = [38 "./tools/fix/fix_server",39 "-p", "9000", 40 "-f", "./tools/fix/scripts/%s" % test]41 return subprocess.Popen(args, stderr = err, stdout = out)42def popen_fix_client():43 args = [44 "./tools/fix/fix_client",45 "-h", "localhost", 46 "-p", "9000", 47 "-f", "./tools/fix/scripts/%s" % test]48 return subprocess.Popen(args, stderr = err, stdout = out)49for test in fix_tests:50 if verbose == 2:51 print "%s\n%s\n" % (test, "-" * len(test))52 server = popen_fix_server()53 result = 154 try:55 client = popen_fix_client()56 result = client.wait()57 finally:58 if result != 0:59 if verbose == 2:60 status = "\n%s\n" % red("FAIL")61 else:62 status = "%-40s [%s]" % (test, red("FAIL"))63 print status64 numfail = numfail + 165 while server.poll() is None:66 server.terminate()67 while client.poll() is None:68 client.terminate()69 else:70 if verbose == 2:71 status = "\n%s\n" % green("PASS")72 elif verbose == 1:73 status = "%-40s [%s]" % (test, green("PASS"))74 if verbose != 0:75 print status76if numfail > 0:77 print "\n" + red("FIX tests run: %d, Failures: %d" % (len(fix_tests), numfail))78else:79 print "\nOK (%d FIX tests)" % (len(fix_tests))80if numfail != 0:81 result = 182else:83 result = 084if result != 0:85 sys.exit(result)86fast_tests = [87 "IncrementOperator",88 "ConstantOperator",89 "DefaultOperator",90 "DeltaOperator",91 "CopyOperator",92 "NoneOperator",93]94def popen_fast_server():95 args = [96 "./tools/fast/fast_server",97 "-p", "9000",98 "-f", "./tools/fast/scripts/%s" % test,99 "-t", "./tools/fast/scripts/%s.xml" % test]100 return subprocess.Popen(args, stderr = err, stdout = out)101def popen_fast_client():102 args = [103 "./tools/fast/fast_client",104 "-h", "localhost",105 "-p", "9000",106 "-f", "./tools/fast/scripts/%s" % test,107 "-t", "./tools/fast/scripts/%s.xml" % test]108 return subprocess.Popen(args, stderr = err, stdout = out)109for test in fast_tests:110 if verbose == 2:111 print "%s\n%s\n" % (test, "-" * len(test))112 server = popen_fast_server()113 result = 1114 try:115 client = popen_fast_client()116 result = client.wait()117 finally:118 if result != 0:119 if verbose == 2:120 status = "\n%s\n" % red("FAIL")121 else:122 status = "%-40s [%s]" % (test, red("FAIL"))123 print status124 numfail = numfail + 1125 while server.poll() is None:126 server.terminate()127 while client.poll() is None:128 client.terminate()129 else:130 if verbose == 2:131 status = "\n%s\n" % green("PASS")132 elif verbose == 1:133 status = "%-40s [%s]" % (test, green("PASS"))134 if verbose != 0:135 print status136if numfail > 0:137 print "\n" + red("FAST tests run: %d, Failures: %d" % (len(fast_tests), numfail))138else:139 print "\nOK (%d FAST tests)" % (len(fast_tests))140if numfail != 0:141 result = 1142else:143 result = 0...
conanfile.py
Source:conanfile.py
1# docopt Conan package2# Dmitriy Vetutnev, Odant 2019 - 20203from conans import ConanFile, CMake, tools4class docoptConan(ConanFile):5 name = "docopt"6 version = "0.6.2+1"7 license = "MIT https://github.com/docopt/docopt.cpp/blob/master/LICENSE-MIT"8 description = "docopt creates beautiful command-line interfaces"9 url = "https://github.com/odant/conan-docopt"10 settings = {11 "os": ["Windows", "Linux"],12 "compiler": ["Visual Studio", "gcc"],13 "build_type": ["Debug", "Release"],14 "arch": ["x86", "x86_64", "mips"]15 }16 options = {17 "with_unit_tests": [True, False],18 "ninja": [True, False]19 }20 default_options = {21 "with_unit_tests": False,22 "ninja": True23 }24 generators = "cmake"25 exports_sources = "src/*", "CMakeLists.txt", "fix_tests.patch", "fix_MSVC_2019.patch", "Finddocopt.cmake"26 no_copy_source = True27 build_policy = "missing"28 def build_requiments(self):29 if self.options.ninja:30 self.build_requires("ninja/1.9.0")31 def source(self):32 tools.patch(patch_file="fix_tests.patch")33 tools.patch(patch_file="fix_MSVC_2019.patch")34 def build(self):35 build_type = "RelWithDebInfo" if self.settings.build_type == "Release" else "Debug"36 gen = "Ninja" if self.options.ninja == True else None37 cmake = CMake(self, build_type=build_type, generator=gen, msbuild_verbosity='normal')38 cmake.verbose = True39 if self.options.with_unit_tests:40 cmake.definitions["WITH_TESTS"] = "ON"41 cmake.configure()42 cmake.build()43 if self.options.with_unit_tests:44 if cmake.is_multi_configuration:45 self.run("ctest --verbose --build-config %s" % build_type)46 else:47 self.run("ctest --verbose")48 def package(self):49 self.copy("Finddocopt.cmake", dst=".", src=".")50 self.copy("docopt.h", dst="include", src="src")51 self.copy("docopt_value.h", dst="include", src="src")52 self.copy("docopt_s.lib", dst="lib", src="lib")53 self.copy("docopt_s.pdb", dst="bin", src="lib")54 self.copy("libdocopt.a", dst="lib", src="lib")55 def package_id(self):56 self.info.options.with_unit_tests = "any"57 self.info.options.ninja = "any"58 def package_info(self):...
fix_6502_tests.py
Source:fix_6502_tests.py
1#!/usr/bin/env python32# vim: set shiftwidth=4 tabstop=4:3import io4TAB = ' ' * 85def fix_tests(source_lines):6 return [fix_line(l) for l in source_lines]7def fix_line(l):8 if l.count('Emulator::UniqueCPU cpu = execute_example_program(program);'):9 return f'{TAB * 2}TestMemory test_memory(program);\n{l.replace("program", "test_memory")}\n'10 else:11 return l12def read_lines():13 with io.open('./tests/cpu_6502_tests.cpp', 'r') as f:14 return f.read().splitlines(keepends=True)15if __name__ == '__main__':16 lines = read_lines()17 with io.open('./tests/cpu_6502_tests.cpp', 'w') as f:18 for l in fix_tests(lines):...
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!!