How to use test_code method in Airtest

Best Python code snippet using Airtest

topcoder_run_system_test.py

Source:topcoder_run_system_test.py Github

copy

Full Screen

...3import urllib24import json5import sys6import os7def generate_test_code(class_name, input_types, return_type, topcoder_url):8 topcoder_url = urllib.quote(topcoder_url)9 url = "http://open.dapper.net/transform.php?dappName=topcoder_test_cases&transformer=JSON&v_url=%(topcoder_url)s" % locals()10 data = json.load(urllib2.urlopen(url))11 test_code = []12 # generate inputs and expected outputs13 inputs = []14 outputs = []15 for value in data['groups']['expected_result']:16 inputs.append(value['input'][0]['value'])17 outputs.append(value['output'][0]['value'])18 for i, ip in enumerate(inputs):19 input_parts = ip.split(",")20 for j, input_type in enumerate(input_types):21 test_code.append("%s input_%d_%d = %s;" % (input_type, j, i, input_parts[j]))22 test_code.append("\n")23 for i, op in enumerate(outputs):24 test_code.append("%s output_%d = %s;" % (return_type, i, op))25 test_code.append("\n")26 # generate function calls27 try:28 method_name = data['fields']['method_name'][0]['value']29 except:30 method_name = data['fields']['method'][0]['value']31 for i in range(len(inputs)):32 input_args = ','.join(["input_%d_%d" % (j, i) for j in range(len(input_types))])33 input_log = " + \" \" + ".join(["input_%d_%d" % (j, i) + (".toString()" if input_types[j][0].isupper() else "") for j in range(len(input_types))])34 test_code.append("System.out.println(\"Running input \" + %(input_log)s);" % locals())35 test_code.append("%(return_type)s a_output_%(i)d = (new %(class_name)s()).%(method_name)s(%(input_args)s);" % locals())36 test_code.append("System.out.println(\"Expected Output: \" + output_%(i)d);" % locals())37 test_code.append("System.out.println(\"Actual Output: \" + a_output_%(i)d);" % locals())38 if '[]' in return_type:39 test_code.append("assert Arrays.equals(a_output_%(i)d, output_%(i)d);" % locals())40 elif return_type[0].isupper():41 test_code.append("assert a_output_%(i)d.equals(output_%(i)d);" % locals())42 else:43 test_code.append("assert a_output_%(i)d == output_%(i)d;" % locals())44 test_code.append("System.out.println(\"Success!\");")45 test_code.append("\n")46 return "\n".join(test_code)47def search_topcoder(class_name):48 url = "http://open.dapper.net/transform.php?dappName=topcoder_search&transformer=JSON&v_class=%(class_name)s" % locals()49 data = json.load(urllib2.urlopen(url))50 return data['fields']['problem_link'][0]['href']51def parse_problem_page(problem_link):52 url = "http://open.dapper.net/transform.php?dappName=topcoder_parse_problem_page&transformer=JSON&applyToUrl=%s" % urllib.quote(problem_link)53 data = json.load(urllib2.urlopen(url))['fields']54 url2 = "http://open.dapper.net/transform.php?dappName=topcoder_test_cases_link&transformer=JSON&applyToUrl=%s" % urllib.quote(data['test_cases_link'][0]['href'])55 data2 = json.load(urllib2.urlopen(url2))['fields']56 return (data['input_types'][0]['value'].split(","),57 data['return_type'][0]['value'],58 data2['test_cases_link'][0]['href'])59def create_test_program(test_code):60 test_code_template = """61 import java.util.Arrays;62 public class test {63 public static void main(String[] args) {64 %(test_code)s65 }66 }67 """68 f = open("test.java", "w")69 f.write(test_code_template % locals())70 f.close()71def run_test_program():72 os.system("javac test.java")73 os.system("java -ea test")74 #os.system("rm test.java")75def main():76 if len(sys.argv) != 2:77 print 'Usage: %s <java_file>' % sys.argv[0]78 sys.exit(1)79 class_name = sys.argv[1].split(".")[0]80 problem_link = search_topcoder(class_name)81 input_types, return_type, test_cases_url = parse_problem_page(problem_link)82 test_code = generate_test_code(class_name, input_types, return_type, test_cases_url)83 create_test_program(test_code)84 run_test_program()85if __name__ == '__main__':...

Full Screen

Full Screen

test_day19p1.py

Source:test_day19p1.py Github

copy

Full Screen

1from day19 import day19_part1 as test_code2# Rotate point tests3# rotate_point(point: tuple, rotation: int, axis: int) -> tuple4print(f"test_code: {test_code}")5def test_rotate_zero():6 assert test_code.rotate_point((1, 2, 3), 0, 0) == (1, 2, 3)7def test_rotate_90_origin():8 # x, y, z = (0,0,0)9 assert test_code.rotate_point((0, 0, 0), 1, 0) == (0, 0, 0)10 assert test_code.rotate_point((0, 0, 0), 1, 1) == (0, 0, 0)11 assert test_code.rotate_point((0, 0, 0), 1, 2) == (0, 0, 0)12def test_rotate_90_x():13 # x, y, z = (1,0,0)14 assert test_code.rotate_point((1, 0, 0), 1, 0) == (1, 0, 0)15 assert test_code.rotate_point((1, 0, 0), 1, 1) == (0, 0, -1)16 assert test_code.rotate_point((1, 0, 0), 1, 2) == (0, 1, 0)17def test_rotate_90_y():18 # x, y, z = (0,1,0)19 assert test_code.rotate_point((0, 1, 0), 1, 0) == (0, 0, 1)20 assert test_code.rotate_point((0, 1, 0), 1, 1) == (0, 1, 0)21 assert test_code.rotate_point((0, 1, 0), 1, 2) == (-1, 0, 0)22def test_rotate_90_z():23 # x, y, z = (0,0,1)24 assert test_code.rotate_point((0, 0, 1), 1, 0) == (0, -1, 0)25 assert test_code.rotate_point((0, 0, 1), 1, 1) == (1, 0, 0)26 assert test_code.rotate_point((0, 0, 1), 1, 2) == (0, 0, 1)27def test_rotate_180_origin():28 # x, y, z = (0,0,0)29 assert test_code.rotate_point((0, 0, 0), 2, 0) == (0, 0, 0)30 assert test_code.rotate_point((0, 0, 0), 2, 1) == (0, 0, 0)31 assert test_code.rotate_point((0, 0, 0), 2, 2) == (0, 0, 0)32def test_rotate_180_x():33 # x, y, z = (1,0,0)34 assert test_code.rotate_point((1, 0, 0), 2, 0) == (1, 0, 0)35 assert test_code.rotate_point((1, 0, 0), 2, 1) == (-1, 0, 0)36 assert test_code.rotate_point((1, 0, 0), 2, 2) == (-1, 0, 0)37def test_rotate_180_y():38 # x, y, z = (0,1,0)39 assert test_code.rotate_point((0, 1, 0), 2, 0) == (0, -1, 0)40 assert test_code.rotate_point((0, 1, 0), 2, 1) == (0, 1, 0)41 assert test_code.rotate_point((0, 1, 0), 2, 2) == (0, -1, 0)42def test_rotate_180_z():43 # x, y, z = (0,0,1)44 assert test_code.rotate_point((0, 0, 1), 2, 0) == (0, 0, -1)45 assert test_code.rotate_point((0, 0, 1), 2, 1) == (0, 0, -1)46 assert test_code.rotate_point((0, 0, 1), 2, 2) == (0, 0, 1)47def test_rotate_270_origin():48 # x, y, z = (0,0,0)49 assert test_code.rotate_point((0, 0, 0), 3, 0) == (0, 0, 0)50 assert test_code.rotate_point((0, 0, 0), 3, 1) == (0, 0, 0)51 assert test_code.rotate_point((0, 0, 0), 3, 2) == (0, 0, 0)52def test_rotate_270_x():53 # x, y, z = (1,0,0)54 assert test_code.rotate_point((1, 0, 0), 3, 0) == (1, 0, 0)55 assert test_code.rotate_point((1, 0, 0), 3, 1) == (0, 0, 1)56 assert test_code.rotate_point((1, 0, 0), 3, 2) == (0, -1, 0)57def test_rotate_270_y():58 # x, y, z = (0,1,0)59 assert test_code.rotate_point((0, 1, 0), 3, 0) == (0, 0, -1)60 assert test_code.rotate_point((0, 1, 0), 3, 1) == (0, 1, 0)61 assert test_code.rotate_point((0, 1, 0), 3, 2) == (1, 0, 0)62def test_rotate_270_z():63 # x, y, z = (0,0,1)64 assert test_code.rotate_point((0, 0, 1), 3, 0) == (0, 1, 0)65 assert test_code.rotate_point((0, 0, 1), 3, 1) == (-1, 0, 0)...

Full Screen

Full Screen

1.py

Source:1.py Github

copy

Full Screen

1import Intcode2memory_factor = 1003# Test 14TEST_CODE = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99".split(",")5TEST_CODE = [int(x) for x in TEST_CODE]6computer = Intcode.Intcode()7computer.memory = TEST_CODE.copy()8computer.increase_memory(memory_factor)9computer.run()10print('Test 1', computer.output == TEST_CODE)11#Test 212TEST_CODE = "1102,34915192,34915192,7,4,7,99,0".split(",")13TEST_CODE = [int(x) for x in TEST_CODE]14computer = Intcode.Intcode()15computer.memory = TEST_CODE.copy()16computer.increase_memory(memory_factor)17computer.run()18print('Test 2', len(str(computer.output[0])) == 16)19#Test 320TEST_CODE = "104,1125899906842624,99".split(",")21TEST_CODE = [int(x) for x in TEST_CODE]22computer = Intcode.Intcode()23computer.memory = TEST_CODE.copy()24computer.increase_memory(memory_factor)25computer.run()26print('Test 3', computer.output[0] == TEST_CODE[1])27# Real run28with open("input", "r") as f:29 mem = f.read().split(",")30INITIAL_MEMORY = [int(x) for x in mem]31computer = Intcode.Intcode()32computer.memory = INITIAL_MEMORY.copy()33computer.increase_memory(memory_factor)34computer.run()35print(computer.output[0])...

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