How to use test_output_file method in Airtest

Best Python code snippet using Airtest

JTSTEST.py

Source:JTSTEST.py Github

copy

Full Screen

1#*********** LICENSE HEADER *******************************2#JAUS Tool Set3#Copyright (c) 2010, United States Government4#All rights reserved.5#6#Redistribution and use in source and binary forms, with or without7#modification, are permitted provided that the following conditions are met:8#9# Redistributions of source code must retain the above copyright notice,10#this list of conditions and the following disclaimer.11#12# Redistributions in binary form must reproduce the above copyright13#notice, this list of conditions and the following disclaimer in the14#documentation and/or other materials provided with the distribution.15#16# Neither the name of the United States Government nor the names of17#its contributors may be used to endorse or promote products derived from18#this software without specific prior written permission.19#20#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"21#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23#ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE24#LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR25#CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF26#SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS27#INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN28#CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)29#ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE30#POSSIBILITY OF SUCH DAMAGE.31#********************* END OF LICENSE ***********************************3233#------------------------------------------------------------34# JTS_UTST module -- Mark Bofill 04150935# Rewritten by Ian Durkan, 03/04/201136#------------------------------------------------------------37# JTS test module38#------------------------------------------------------------39# Description: This module builds and runs JTS unit testing40#------------------------------------------------------------4142import os43import os.path44import shutil45import JTSutst46from optparse import OptionParser47from optparse import OptionGroup4849CPP_BLD_OUTPUT_PATH = "./cpp_bldOutput.txt"50CPP_TST_OUTPUT_PATH = "./cpp_tstOutput.txt"51JAVA_BLD_OUTPUT_PATH = "./java_bldOutput.txt"52JAVA_TST_OUTPUT_PATH = "./java_tstOutput.txt"53CSHARP_BLD_OUTPUT_PATH = "./csharp_bldOutput.txt"54CSHARP_TST_OUTPUT_PATH = "./csharp_tstOutput.txt"5556base_dir = ""57do_generation = True58do_build = True59do_run = True60junit_jar_path = "./junit-3.8.2.jar"61nunit_assembly_path = "./nunit-thingy.dll"6263def run_cpp_test(test_info, build_output_file, test_output_file):64 """Run a test case, test_name, using the C++ code generator and cppunit test file for that65 test case. Append output from the build process to build_output_file and append output from66 the test run to test_output_file (both must be already-opened file objects)"""67 global base_dir68 global do_generation69 os.chdir(base_dir)7071 (test_name, test_namespace) = test_info7273 print ""74 print "Processing test, C++ version:", test_name75 print "*************************************************"76 print ""7778 exe_name = test_name.lower() + "_utst.exe"7980 # C++ unit test .cpp file names are inconsistent in capitalization.81 # most are in CamelCase but others are not. check if the camel case filename is not found82 # and adjust filename used when building test if necessary.83 cpp_name = test_name + "_utst.cpp"8485 test_dir = "./" + test_name + "/" + test_name + "_cmpt_1"86 cpp_path = test_dir + "/" + cpp_name8788 if (not os.path.isfile(cpp_path)):89 cpp_name = test_name.lower() + "_utst.cpp"9091 if (do_generation and JTSutst.Run_CodeGenerator(test_name, 'c++', build_output_file)!=0):92 print "--- Errors encountered in Code Generation phase! ( see", CPP_BLD_OUTPUT_PATH, ")"9394 os.chdir(test_dir)9596 # we need to find the absolute path to the bin directory so the location of native97 # shared libraries can be specified to csharp runtime via the PATH env. variable.98 absolute_bin_path = os.getcwd() + os.sep + "bin"99100 if (do_build and JTSutst.Build_Test_Cpp(cpp_name, exe_name, build_output_file)!=0):101 print "--- Errors encountered in test compilation phase (see ", CPP_BLD_OUTPUT_PATH, ")"102 if (do_run and JTSutst.Run_Test_Cpp("./bin/" + exe_name, test_output_file,absolute_bin_path)!=0):103 print "---Errors encountered in test execution phase (see ", CPP_TST_OUTPUT_PATH, ")"104105def run_java_test(test_info, build_output_file, test_output_file):106 """Run a test case using the Java code generator and Junit test file for that107 test case. test_info must be a tupled containing both the test's name and108 the test class' package (or None if it's in the global package)109 Appends output from the build process to build_output_file and appends output from110 the test run to test_output_file (both must be already-opened file objects)"""111 global base_dir112 global junit_jar_path113 global do_generation114 os.chdir(base_dir)115116 (test_name, test_namespace) = test_info117118 print ""119 print "Processing test, Java version:", test_name120 print "*************************************************"121 print ""122123 test_dir = "./" + test_name + "/" + test_name + "_java_1"124 test_source_name = test_name + "_utst.java"125 test_jar_path = "./bin/" + test_name + "_java_1.jar"126 relative_junit_jar_path = "../../" + junit_jar_path127128 if (test_namespace):129 test_exe = test_namespace + "." + test_name + "_utst"130 else:131 test_exe = test_name + "_utst"132133 if (do_generation and JTSutst.Run_CodeGenerator(test_name, 'java', build_output_file) != 0):134 print "--- Errors encountered in code generation phase! ( see", JAVA_BLD_OUTPUT_PATH, ")"135 os.chdir(test_dir)136137 # we need to find the absolute path to the bin directory so the location of native138 # shared libraries can be specified to java via the PATH env. variable.139 absolute_bin_path = os.getcwd() + os.sep + "bin"140141 if (do_build and JTSutst.Build_Test_Java(test_source_name, build_output_file, relative_junit_jar_path)!=0):142 print "--- Errors encountered in test build phase (see ", JAVA_BLD_OUTPUT_PATH, ")"143 if (do_run and JTSutst.Run_Test_Java(test_jar_path, test_exe, test_name, absolute_bin_path, test_output_file, relative_junit_jar_path)!=0):144 print "---Errors encountered in test execution phase (see ", JAVA_TST_OUTPUT_PATH, ")"145146def run_csharp_test(test_info, build_output_file, test_output_file):147 """Run a test case, test_name, using the C# code generator and Nunit test file for that148 test case. Append output from the build process to build_output_file and append output from149 the test run to test_output_file (both must be already-opened file objects)"""150 global base_dir151 global do_generation152 global nunit_assembly_path153 os.chdir(base_dir)154155 (test_name, test_namespace) = test_info156157 print ""158 print "Processing test, C# version:", test_name159 print "*************************************************"160 print ""161162 test_dir = "./" + test_name + "/" + test_name + "_csharp_1"163 test_exe_path = "./bin/" + test_name + "_csharp.exe"164 relative_nunit_assembly_path = "../../" + nunit_assembly_path165166 if (do_generation and JTSutst.Run_CodeGenerator(test_name, 'cs', build_output_file) != 0):167 print "--- Errors encountered in code generation phase! ( see", CSHARP_BLD_OUTPUT_PATH, ")"168169 os.chdir(test_dir)170171 # we need to find the absolute path to the bin directory so the location of native172 # shared libraries can be specified to csharp runtime via the PATH env. variable.173 absolute_bin_path = os.getcwd() + os.sep + "bin"174175 if (do_build and JTSutst.Build_Test_Csharp(test_name, test_exe_path, \176 build_output_file, relative_nunit_assembly_path) != 0):177 print "--- Errors encountered in test build phase (see ", CSHARP_BLD_OUTPUT_PATH, ")"178 if do_run and JTSutst.Run_Test_Csharp(test_exe_path, test_name, absolute_bin_path, test_output_file) != 0:179 print "---Errors encountered in test execution phase (see ", CSHARP_TST_OUTPUT_PATH, ")"180181182def run_test_set_with_runner(runner_fn, test_set, message, build_output_file, test_output_file):183 """ Run a set of tests, test_set, with the given runner function runner_fn (which should be184 set to one of run_cpp_test, run_java_test, or run_csharp_test). Append output from the build185 process to build_output_file and append output from the test run to test_output_file (both186 must be already-opened file objects)"""187188 print ""189 print "*************************************************"190 print "Running Test Set: ", message191 print "*************************************************"192 print ""193 for test_info in test_set:194 runner_fn(test_info, build_output_file, test_output_file)195196197#------------------------------------198# run References (client-of & inheritence)199#------------------------------------200def runReferences():201202 baseworkdir = os.getcwd()203 print "Processing References..."204 if (JTSutst.Run_CodeGenerator("References1","References1",baseworkdir + "/bldOutput.txt")!=0):205 print("---Errors encountered in Code Generation phase (see bldOutput.txt)")206 os.chdir("./References1/References1_cmpt_1")207 if (JTSutst.Build_Test("References1_utst.cpp","References1_utst.exe",baseworkdir + "/bldOutput.txt")!=0):208 print("---Errors encountered in test compilation phase (see bldOutput.txt)")209 if (JTSutst.Run_Test("./bin/References1_utst.exe",baseworkdir + "/tstOutput.txt")!=0):210 print("---Errors encountered in test execution phase (see tstOutput.txt)")211 os.chdir(baseworkdir)212213 baseworkdir = os.getcwd()214 print "Processing Core..."215 shutil.rmtree("./Core1", True)216 if (JTSutst.Run_CodeGenerator("Core1","Core1",baseworkdir + "/bldOutput.txt")!=0):217 print("---Errors encountered in Code Generation phase (see bldOutput.txt)")218 os.chdir("./Core1/Core1_cmpt_1")219 if (JTSutst.Build_Test("","Core1_cmpt_1.exe",baseworkdir + "/bldOutput.txt")!=0):220 print("---Errors encountered in test compilation phase (see bldOutput.txt)")221 os.chdir(baseworkdir)222223 baseworkdir = os.getcwd()224 print "Processing Inheritence..."225 shutil.rmtree("./Inheritence1/Inheritence1_cmpt_1/urn_org_jts_test_Child_1_0", True)226 if (JTSutst.Run_CodeGenerator("Inheritence1","Inheritence1",baseworkdir + "/bldOutput.txt")!=0):227 print("---Errors encountered in Code Generation phase (see bldOutput.txt)")228 os.chdir("./Inheritence1/Inheritence1_cmpt_1")229 if (JTSutst.Build_Test("Inheritence1_utst.cpp","Inheritence1_utst.exe",baseworkdir + "/bldOutput.txt")!=0):230 print("---Errors encountered in test compilation phase (see bldOutput.txt)")231 if (JTSutst.Run_Test("./bin/Inheritence1_utst.exe",baseworkdir + "/tstOutput.txt")!=0):232 print("---Errors encountered in test execution phase (see tstOutput.txt)")233 os.chdir(baseworkdir)234235236 return 0237238239def main():240 """ main entry point function"""241 global base_dir242 global do_generation243 global do_build244 global do_run245 base_dir = os.getcwd()246247 parser = OptionParser(usage="Usage: %prog [options]\n\nRun JTSTEST.py --help for info about the options."\248 "\n\nNote this script must be run from directory GUI/test/atf/ to succeed!")249250 langs_group = OptionGroup(parser, "Language Testing Options", "These options allow code generation in" \251 " specific languages to be tested. If no language testing option is selected, all languages are" \252 " are tested. Multiple languages can be specified, for example by providing both" \253 "'--test_cpp' and '--test_java'.")254255 langs_group.add_option("--test_cpp", dest="test_cpp", action="store_true", default=False,\256 help="Generate, build, and/or run C++ unit tests.")257 langs_group.add_option("--test_java", dest="test_java", action="store_true", default=False,\258 help="Generate, build, and/or run Java unit tests.")259 langs_group.add_option("--test_csharp", dest="test_csharp", action="store_true", default=False,\260 help="Generate, build, and/or run C# unit tests.")261 parser.add_option_group(langs_group)262263 parser.add_option("--skip_gen", dest="skip_gen", action="store_true", default=False,\264 help="Skips the code-generation step to save time or maintain alterations to generated code.")265 parser.add_option("--skip_build", dest="skip_build", action="store_true", default=False,\266 help="Skips the test code build step, for faster code-generation testing.")267 parser.add_option("--skip_run", dest="skip_run", action="store_true", default=False,\268 help="Skips the test run step, for testing build issues more quickly.")269270 (options, discarded) = parser.parse_args()271272 # determine which test steps we should perform273 if options.skip_gen:274 do_generation = False275276 if options.skip_build:277 do_build = False278279 if options.skip_run:280 do_run = False281282 # determine which language to use283 # if any of the --test_X options are invoked, test only in the language(s) invoked.284 # if none are invoked, test all languages.285 num_language_opts = 0;286 run_cpp_tests = run_java_tests = run_csharp_tests = False287288 if options.test_cpp:289 run_cpp_tests = True;290 num_language_opts += 1291292 if options.test_java:293 run_java_tests = True;294 num_language_opts += 1295296 if options.test_csharp:297 run_csharp_tests = True;298 num_language_opts += 1299300 if num_language_opts <= 0:301 run_cpp_tests = run_java_tests = run_csharp_tests = True302303 array_tests = [304 ('Array1', None),305 ('Array2', None),306 ('Array3', None),307 ('Array4', None),308 ('Array5', None),309 ('Array6', None),310 ('Array7', None),311 ('Array8', None),312 ('Array9', None),313 ('Array10', None),314 ]315 bitfield_tests = [('BitField1', None)]316317 body_tests = [318 ('Body1', None),319 ('Body2', None),320 ('Body3', None),321 ('Body4', None),322 ('Body5', None),323 ('Body6', None),324 ('Body7', None),325 ('Body8', None),326 ('Body9', None),327 ]328329 # the FixedField1 test is identical to Body1 test, therefore it was removed330 fixedfield_tests = [331 ('FixedField2', None),332 ('FixedField3', None)333 ]334335 header_tests = [336 ('Header1', None),337 ('Header2', None),338 ('Header3', None),339 ('Header4', None),340 ('Header5', None),341 ('Header6', None),342 ]343344 list_tests = [345 ('List1', None),346 ('List2', None),347 ('List3', None),348 ('List4', None),349 ]350351 record_tests = [352 ('Record10', None),353 ('Record11', None),354 ('Record12', None),355 ('Record15', None),356 ('Record16', None),357 ]358359 sequence_tests = [360 ('Sequence1', None),361 ('Sequence2', None),362 ('Sequence3', None),363 ]364365 variant_tests = [366 ('Variant1', None),367 ('Variant2', None),368 ('Variant3', None),369 ('Variant4', None),370 ]371372 varlength_tests = [373 ('VariableLengthStuff1', None),374 ]375 376 optionality_tests = [377 ('Optional1', None),378 ]379380 simpleset_tests = [('SimpleSet', 'src.urn_DeVivo_jaus_services_SimpleDef_1_0'),381 ('DefaultTransitionSet', 'src.urn_DeVivo_jaus_services_DefaultTransDef_1_0')]382 loopback_tests = [('Loopback1', 'src.urn_DeVivo_jaus_services_LoopbackDef_1_0'),383 ('Loopback2', 'src.urn_DeVivo_jaus_services_LoopbackDef_1_0')]384 references_tests = [('References1', None)]385 inheritance_tests = [('Inheritence1', 'src')]386387 nestedset_tests = [388 ('NestedSet', 'src.urn_DeVivo_jaus_services_NestedDef_1_0'),389 ('NestedSet2', 'src.urn_DeVivo_jaus_services_NestedDef_1_0'),390 ]391392 per_language_elements = []393394 if run_cpp_tests:395 cpp_build_output_file = open(CPP_BLD_OUTPUT_PATH, 'w')396 cpp_test_output_file = open(CPP_TST_OUTPUT_PATH, 'w')397 per_language_elements.append(("C++", run_cpp_test, cpp_build_output_file, cpp_test_output_file))398399 if run_java_tests:400 java_build_output_file = open(JAVA_BLD_OUTPUT_PATH, 'w')401 java_test_output_file = open(JAVA_TST_OUTPUT_PATH, 'w')402 per_language_elements.append(("Java", run_java_test, java_build_output_file, java_test_output_file))403404 if run_csharp_tests:405 csharp_build_output_file = open(CSHARP_BLD_OUTPUT_PATH, 'w')406 csharp_test_output_file = open(CSHARP_TST_OUTPUT_PATH, 'w')407 per_language_elements.append(("C#", run_csharp_test, csharp_build_output_file, csharp_test_output_file))408409410 for (language, test_runner, build_output_file, test_output_file) in per_language_elements:411 run_test_set_with_runner(test_runner, array_tests, language + " Array Tests", \412 build_output_file, test_output_file)413 run_test_set_with_runner(test_runner, bitfield_tests, language + " BitField Tests", \414 build_output_file, test_output_file)415 run_test_set_with_runner(test_runner, body_tests, language + " Body Tests", \416 build_output_file, test_output_file)417 run_test_set_with_runner(test_runner, fixedfield_tests, language + " FixedField Tests", \418 build_output_file, test_output_file)419 run_test_set_with_runner(test_runner, header_tests, language + " Header Tests", \420 build_output_file, test_output_file)421 run_test_set_with_runner(test_runner, list_tests, language + " List Tests", \422 build_output_file, test_output_file)423 run_test_set_with_runner(test_runner, record_tests, language + " Record Tests", \424 build_output_file, test_output_file)425 run_test_set_with_runner(test_runner, sequence_tests, language + " Sequence Tests", \426 build_output_file, test_output_file)427 run_test_set_with_runner(test_runner, variant_tests, language + " Variant Tests", \428 build_output_file, test_output_file)429 run_test_set_with_runner(test_runner, optionality_tests, language + " Optionality Tests", \430 build_output_file, test_output_file)431432 run_test_set_with_runner(test_runner, simpleset_tests, language + " Simple Set Tests", \433 build_output_file, test_output_file)434 run_test_set_with_runner(test_runner, nestedset_tests, language + " Nested Set Tests", \435 build_output_file, test_output_file)436 run_test_set_with_runner(test_runner, loopback_tests, language + " Loopback Tests", \437 build_output_file, test_output_file)438 run_test_set_with_runner(test_runner, references_tests, language + " References Tests", \439 build_output_file, test_output_file)440 run_test_set_with_runner(test_runner, inheritance_tests, language + " Inheritance Tests", \441 build_output_file, test_output_file)442443# TODO: 'core1' tests, 'variable length stuff' test - doesn't exist.444445 if run_cpp_tests:446 cpp_build_output_file.close();447 cpp_test_output_file.close();448449 if run_java_tests:450 java_build_output_file.close();451 java_test_output_file.close();452453 if run_csharp_tests:454 csharp_build_output_file.close();455 csharp_test_output_file.close();456457 return 0458#------------------------------------459460461462#------------------------------------463# stub to trigger execution of main464#------------------------------------465if __name__ == "__main__":466 main()467 ...

Full Screen

Full Screen

test_main.py

Source:test_main.py Github

copy

Full Screen

1import sys2import os3#sys.path.insert(1, "C:\\Users\YASIR\Documents\STEPin Projects\Python_mini_project\src")4import main5#definifn all the test fucntions here6def test_txt_to_hex():7 test_output_file = open("test/test_hex.hex", 'x') #generating a hex file to get it tested 8 test_input_file = open("test/template_myfile.txt", 'r') #our tepmplate txt file9 template_file = open("test/template_hex.hex", 'r') #our template hex file for camparing with generated hex file10 main.txt_to_hex(test_input_file, test_output_file) #gets generated here11 12 test_output_file = open("test/test_hex.hex", 'r') #opening again 13 template_file = open("test/template_hex.hex", 'r') #opening again14 for f, b in zip(template_file, test_output_file): #testing here15 assert f == b16 test_output_file.close()17 template_file.close()18 os.remove("test/test_hex.hex") #deleting the tested files19def test_txt_to_bin():20 test_output_file = open("test/test_bin.bin", 'x')21 test_input_file = open("test/template_myfile.txt", 'r')22 template_file = open("test/template_bin.bin", 'r')23 main.txt_to_bin(test_input_file, test_output_file)24 test_output_file = open("test/test_bin.bin", 'r')25 template_file = open("test/template_bin.bin", 'r')26 for f, b in zip(template_file, test_output_file):27 assert f == b28 test_output_file.close()29 template_file.close()30 os.remove("test/test_bin.bin")31def test_txt_to_pdf():32 #test_output_file = open("test/test_pdf.pdf", 'x')33 test_input_file = open("test/template_myfile.txt", 'r')34 template_file = open("test/template_pdf.pdf", 'rb')35 main.txt_to_pdf(test_input_file, "test_pdf.pdf")36 test_output_file = open("test_pdf.pdf", 'rb')37 for bits1, bits2 in zip(template_file, test_output_file):38 if b'/CreationDate' in bits1 or b'/CreationDate' in bits2: #ignoring the DateOfCreation while comparing all the pdf bytes39 continue40 else:41 assert bits1 == bits2 #if not the DateOfCreation byte? assert 42 test_output_file.close()43 test_input_file.close()44 template_file.close()45 46 os.remove("test_pdf.pdf")...

Full Screen

Full Screen

test_extract_attribute_column.py

Source:test_extract_attribute_column.py Github

copy

Full Screen

1from graditudelib import extract_attribute_column2import os3def test_extract_columns():4 test_output_file = "tmp_extract_column_output.csv"5 reference_output_file = "tests/fixtures/extract_column_output.csv"6 7 extract_attribute_column.extract_columns(8 reference_output_file,9 "Name",10 test_output_file11 )12 13 assert open(reference_output_file).read() == open(test_output_file).read()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful