Best Python code snippet using avocado_python
test_resolver.py
Source:test_resolver.py
1import os2import stat3import unittest4from avocado.utils import process, script5# Use the same definitions from loader to make sure the behavior6# is also the same7from selftests.functional.test_list import AVOCADO_TEST_OK as AVOCADO_INSTRUMENTED_TEST8from selftests.functional.test_list import EXEC_TEST9from selftests.utils import AVOCADO, BASEDIR10class ResolverFunctional(unittest.TestCase):11 MODE_0664 = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH12 MODE_0775 = (13 stat.S_IRUSR14 | stat.S_IWUSR15 | stat.S_IXUSR16 | stat.S_IRGRP17 | stat.S_IWGRP18 | stat.S_IXGRP19 | stat.S_IROTH20 | stat.S_IXOTH21 )22 def test_exec_test(self):23 name = "executable-test"24 with script.TemporaryScript(name, EXEC_TEST, name, self.MODE_0775) as test_file:25 cmd_line = f"{AVOCADO} --verbose list {test_file.path}"26 result = process.run(cmd_line)27 self.assertIn("exec-test: 1", result.stdout_text)28 def test_not_exec_test(self):29 name = "executable-test"30 with script.TemporaryScript(name, EXEC_TEST, name, self.MODE_0664) as test_file:31 cmd_line = f"{AVOCADO} list {test_file.path}"32 result = process.run(cmd_line)33 self.assertNotIn("exec-test ", result.stdout_text)34 def test_avocado_instrumented(self):35 name = "passtest.py"36 with script.TemporaryScript(37 name, AVOCADO_INSTRUMENTED_TEST, name, self.MODE_066438 ) as test_file:39 cmd_line = f"{AVOCADO} --verbose list {test_file.path}"40 result = process.run(cmd_line)41 self.assertIn("passtest.py:PassTest.test", result.stdout_text)42 self.assertIn("avocado-instrumented: 1", result.stdout_text)43 def test_property(self):44 test_path = os.path.join(BASEDIR, "examples", "tests", "property.py")45 cmd_line = f"{AVOCADO} --verbose list {test_path}"46 result = process.run(cmd_line)47 self.assertIn("examples/tests/property.py:Property.test", result.stdout_text)48 self.assertIn("avocado-instrumented: 1", result.stdout_text)49 def test_python_unittest_first(self):50 """Tests that avocado.Test based tests are found as python-unittest.51 This is valid because of avocado.Test's unittest.TestCase52 inheritance and compatibility.53 """54 config = "[plugins.resolver]\norder = ['python-unittest',]\n"55 with script.TemporaryScript("config", config) as config_path:56 test_path = os.path.join(BASEDIR, "examples", "tests", "passtest.py")57 cmd_line = (58 f"{AVOCADO} --config {config_path.path} " f"--verbose list {test_path}"59 )60 result = process.run(cmd_line)61 self.assertIn("python-unittest: 1", result.stdout_text)62 def test_avocado_and_python_unittest_disabled(self):63 """Tests that avocado.Test based tests are not found.64 If both python-unittest and avocado-instrumented resolver are disabled,65 avocado.Test based tests should not be resolved at all.66 """67 config = (68 "[plugins]\ndisable = ['resolver.python-unittest', "69 "'resolver.avocado-instrumented']\n"70 )71 with script.TemporaryScript("config", config) as config_path:72 test_path = os.path.join(BASEDIR, "examples", "tests", "passtest.py")73 cmd_line = (74 f"{AVOCADO} --config {config_path.path} " f"--verbose list {test_path}"75 )76 result = process.run(cmd_line)77 lines = result.stdout_text.splitlines()78 self.assertEqual(lines[-2], "TEST TYPES SUMMARY")79 self.assertEqual(lines[-1], "==================")80 def test_recursive_by_default(self):81 test_path = os.path.join(BASEDIR, "examples", "tests", "skip_conditional.py")82 cmd_line = f"{AVOCADO} --verbose list {test_path}"83 result = process.run(cmd_line)84 lines = result.stdout_text.splitlines()85 # two random tests that should be among the 10 tests found86 self.assertIn(87 "examples/tests/skip_conditional.py:BareMetal.test_specific", lines[1]88 )89 self.assertIn(90 "examples/tests/skip_conditional.py:NonBareMetal.test_bare_metal", lines[7]91 )92 self.assertEqual("avocado-instrumented: 10", lines[-1])93if __name__ == "__main__":...
test_config_caffe.py
Source:test_config_caffe.py
...54 def test_nvidia_01(self):55 self.check_parameters('nvidia', 'NVIDIA', 'hpe/nvidia_caffe:cuda9-cudnn7')56 def test_intel_01(self):57 self.check_parameters('intel', 'Intel', 'hpe/intel_caffe:cpu')58 def test_bare_metal(self):59 for fork in ('bvlc', 'nvidia', 'intel'):60 self.check_bare_metal_parameters(fork)61 def test_nvidia_precision_01(self):62 self.build_plan({'exp.framework': 'nvidia_caffe', 'DLBS_ROOT': ''})63 for dtype in ('float32', 'float16'):64 nvp = 'FLOAT' if dtype == 'float32' else 'FLOAT16'65 self.compute_vars(66 [('exp.dtype', dtype)],67 [('nvidia_caffe.precision', dtype), ('nvidia_caffe.solver_precision', nvp),68 ('nvidia_caffe.forward_precision', nvp), ('nvidia_caffe.backward_precision', nvp),69 ('nvidia_caffe.forward_math_precision', nvp), ('nvidia_caffe.backward_math_precision', nvp)]70 )71 def test_nvidia_precision_02(self):72 self.build_plan({'exp.framework': 'nvidia_caffe', 'DLBS_ROOT': ''})...
skip_conditional.py
Source:skip_conditional.py
...6 SUPPORTED_ENVS = []7 @skipUnless(8 lambda x: "BARE_METAL" in x.SUPPORTED_ENVS, "Bare metal environment is required"9 )10 def test_bare_metal(self):11 pass12 @skipIf(lambda x: getattr(x, "MEMORY", 0) < 4096, "Not enough memory for test")13 def test_large_memory(self):14 pass15 @skipUnless(16 lambda x: "VIRTUAL_MACHINE" in x.SUPPORTED_ENVS,17 "Virtual Machine environment is required",18 )19 def test_nested_virtualization(self):20 pass21 @skipUnless(22 lambda x: "CONTAINER" in x.SUPPORTED_ENVS, "Container environment is required"23 )24 def test_container(self):...
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!!