How to use _build_command_line method in autotest

Best Python code snippet using autotest_python

gtest.py

Source:gtest.py Github

copy

Full Screen

...39 failed.append(fixture)40 return (tests, failed)41def _run_apptest(config, shell, args, apptest):42 """Runs an apptest and checks the output for signs of gtest failure."""43 command = _build_command_line(config, args, apptest)44 logging.getLogger().debug("Command: %s" % " ".join(command))45 start_time = time.time()46 try:47 output = _run_test_with_timeout(config, shell, args, apptest)48 except Exception as e:49 _print_error(command, e)50 return False51 # Fail on output with gtest's "[ FAILED ]" or a lack of "[ PASSED ]".52 # The latter condition ensures failure on broken command lines or output.53 # Check output instead of exit codes because mojo shell always exits with 0.54 if output.find("[ FAILED ]") != -1 or output.find("[ PASSED ]") == -1:55 _print_error(command, output)56 return False57 ms = int(round(1000 * (time.time() - start_time)))58 logging.getLogger().debug("Passed with output (%d ms):\n%s" % (ms, output))59 return True60def _get_fixtures(config, shell, args, apptest):61 """Returns an apptest's "Suite.Fixture" list via --gtest_list_tests output."""62 arguments = args + ["--gtest_list_tests"]63 command = _build_command_line(config, args, apptest)64 logging.getLogger().debug("Command: %s" % " ".join(command))65 try:66 tests = _run_test_with_timeout(config, shell, arguments, apptest)67 logging.getLogger().debug("Tests for %s:\n%s" % (apptest, tests))68 # Remove log lines from the output and ensure it matches known formatting.69 tests = re.sub("^(\[|WARNING: linker:).*\n", "", tests, flags=re.MULTILINE)70 if not re.match("^(\w*\.\r?\n( \w*\r?\n)+)+", tests):71 raise Exception("Unrecognized --gtest_list_tests output:\n%s" % tests)72 tests = tests.split("\n")73 test_list = []74 for line in tests:75 if not line:76 continue77 if line[0] != " ":78 suite = line.strip()79 continue80 test_list.append(suite + line.strip())81 return test_list82 except Exception as e:83 _print_error(command, e)84 return []85def _print_error(command_line, error):86 """Properly format an exception raised from a failed command execution."""87 exit_code = ""88 if hasattr(error, 'returncode'):89 exit_code = " (exit code %d)" % error.returncode90 print "\n[ FAILED ] Command%s: %s" % (exit_code, " ".join(command_line))91 print 72 * "-"92 print error.output if hasattr(error, 'output') else error93 print 72 * "-"94def _build_command_line(config, args, apptest):95 """Build the apptest command line. This value isn't executed on Android."""96 paths = Paths(config)97 # On Linux, always run tests with xvfb, but not for --gtest_list_tests.98 use_xvfb = (config.target_os == Config.OS_LINUX and99 not "--gtest_list_tests" in args)100 prefix = [paths.xvfb, paths.build_dir] if use_xvfb else []101 return prefix + [paths.mojo_runner] + args + [apptest]102# TODO(msw): Determine proper test timeout durations (starting small).103def _run_test_with_timeout(config, shell, args, apptest, timeout_in_seconds=10):104 """Run the given test with a timeout and return the output or an error."""105 result = multiprocessing.Queue()106 process = multiprocessing.Process(107 target=_run_test, args=(config, shell, args, apptest, result))108 process.start()109 process.join(timeout_in_seconds)110 if process.is_alive():111 process.terminate()112 process.join()113 return "Error: Test timeout after %s seconds" % timeout_in_seconds114 return result.get()115def _run_test(config, shell, args, apptest, result):116 """Run the given test and puts the output in |result|."""117 if (config.target_os != Config.OS_ANDROID):118 command = _build_command_line(config, args, apptest)119 result.put(subprocess.check_output(command, stderr=subprocess.STDOUT))120 return121 assert shell122 (r, w) = os.pipe()123 with os.fdopen(r, "r") as rf:124 with os.fdopen(w, "w") as wf:125 shell.StartActivity('MojoShellActivity', args + [apptest], wf, wf.close)...

Full Screen

Full Screen

inotify.py

Source:inotify.py Github

copy

Full Screen

...14 """15 Profiler based on inotifywait from inotify-tools16 """17 version = 118 def _build_command_line(self, paths, test):19 default_opts = "-m -t 0 --format='%T|%,e|%w|%f' --timefmt '%m/%d %X'"20 paths_valid = [p for p in paths if os.path.exists(p)]21 paths_str = ' '.join(paths_valid)22 output_option = '-o %s' % os.path.join(test.profdir, 'inotify')23 options = '%s %s' % (default_opts, output_option)24 return '%s %s %s' % (self.inotifywait, options, paths_str)25 def initialize(self, paths=[]):26 try:27 self.inotifywait = os_dep.command('inotifywait')28 except ValueError:29 logging.error('Command inotifywait from inotify-tools is not present')30 self.inotifywait = None31 self.paths = paths32 def start(self, test):33 if self.inotifywait is None:34 logging.error("Profiler inotify won't perform any action because "35 "the inotifywait tool from inotify-tools is missing "36 "on this system")37 return38 # monitor the test directories by default39 if not self.paths:40 self.paths = [test.bindir, test.srcdir, test.tmpdir]41 self.command_line = self._build_command_line(self.paths, test)42 logging.debug('running inotify profiler command: %s',43 self.command_line)44 p = subprocess.Popen(self.command_line,45 shell=True,46 stdout=subprocess.PIPE,47 stderr=subprocess.PIPE)48 self.pid = p.pid49 def stop(self, test):50 if self.inotifywait is None:51 return52 try:53 os.kill(self.pid, 15)54 except OSError:55 pass...

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 autotest 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