Best Python code snippet using avocado_python
test_autobahn.py
Source: test_autobahn.py
...25 try:26 yield27 finally:28 python_on_whales.docker.image.remove(x="autobahn-testsuite")29def get_failed_tests(report_path: str, name: str) -> List[Dict[str, Any]]:30 path = Path(report_path)31 result_summary = json.loads((path / "index.json").read_text())[name]32 failed_messages = []33 PASS = {"OK", "INFORMATIONAL"}34 entry_fields = {"case", "description", "expectation", "expected", "received"}35 for results in result_summary.values():36 if results["behavior"] in PASS and results["behaviorClose"] in PASS:37 continue38 report = json.loads((path / results["reportfile"]).read_text())39 failed_messages.append({field: report[field] for field in entry_fields})40 return failed_messages41@pytest.mark.skipif(sys.platform == "darwin", reason="Don't run on macOS")42@pytest.mark.xfail43def test_client(report_dir: Path, request: Any) -> None:44 try:45 print("Starting autobahn-testsuite server")46 autobahn_container = python_on_whales.docker.run(47 detach=True,48 image="autobahn-testsuite",49 name="autobahn",50 publish=[(9001, 9001)],51 remove=True,52 volumes=[53 (f"{request.fspath.dirname}/client", "/config"),54 (f"{report_dir}", "/reports"),55 ],56 )57 print("Running aiohttp test client")58 client = subprocess.Popen(59 ["wait-for-it", "-s", "localhost:9001", "--"]60 + [sys.executable]61 + ["tests/autobahn/client/client.py"]62 )63 client.wait()64 finally:65 print("Stopping client and server")66 client.terminate()67 client.wait()68 autobahn_container.stop()69 failed_messages = get_failed_tests(f"{report_dir}/clients", "aiohttp")70 assert not failed_messages, "\n".join(71 "\n\t".join(72 f"{field}: {msg[field]}"73 for field in ("case", "description", "expectation", "expected", "received")74 )75 for msg in failed_messages76 )77@pytest.mark.skipif(sys.platform == "darwin", reason="Don't run on macOS")78@pytest.mark.xfail79def test_server(report_dir: Path, request: Any) -> None:80 try:81 print("Starting aiohttp test server")82 server = subprocess.Popen(83 [sys.executable] + ["tests/autobahn/server/server.py"]84 )85 print("Starting autobahn-testsuite client")86 python_on_whales.docker.run(87 image="autobahn-testsuite",88 name="autobahn",89 remove=True,90 volumes=[91 (f"{request.fspath.dirname}/server", "/config"),92 (f"{report_dir}", "/reports"),93 ],94 networks=["host"],95 command=[96 "wait-for-it",97 "-s",98 "localhost:9001",99 "--",100 "wstest",101 "--mode",102 "fuzzingclient",103 "--spec",104 "/config/fuzzingclient.json",105 ],106 )107 finally:108 print("Stopping client and server")109 server.terminate()110 server.wait()111 failed_messages = get_failed_tests(f"{report_dir}/servers", "AutobahnServer")112 assert not failed_messages, "\n".join(113 "\n\t".join(114 f"{field}: {msg[field]}"115 for field in ("case", "description", "expectation", "expected", "received")116 )117 for msg in failed_messages...
score_extractor.py
Source: score_extractor.py
...12 tname = tname.strip()13 tweight = int(tweight)14 weights[tname]=tweight15 return weights;16def get_failed_tests(tree):17 result = []18 for t in tree.findall('testcase'):19 if len(t.findall('error')) + len(t.findall('failure')) > 0:20 result.append(t.attrib['name'])21 return result22def calculate_grade(weights, failures):23 total = 024 loss = 025 for w in weights:26 total += weights[w]27 for f in failures:28 loss += weights[f]29 return total - loss30def main(argv):31 if len(argv) < 4:32 print 'too few arguments'33 exit(1)34 path = argv[1]35 submission_name = argv[2].replace('/', '').strip()36 weights_file_name = argv[3]37 if os.path.exists(path):38 tree = parser.parse(path).getroot()39 weights = get_tescase_weights(weights_file_name)40 ftests = get_failed_tests(tree)41 if len(ftests) is 1 and ftests[0]=='assignment6.A6Test':42 grade = 043 else:44 grade = calculate_grade(weights, ftests)45 print '"'+submission_name+'", ', grade, ', ""'46 else:47 print '"'+submission_name+'", ', 0, ', compile_error'...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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!!