def test_execute_cmd_in_background(): """Launch a process in the background then kill it by its pid. If the kill was successful, then the process was launched in the background correctly.""" pid = process.execute_cmd_in_background('sleep 101') sleep(0.1) ret = process.get_return_code_of_simple_cmd("kill {pid}".format(pid=pid)) assert ret == 0
def make_screenshot(video_file, sec, outdir='/tmp', rm=True): """Make a screenshot from a video at a given time. Work is done with mplayer. Specify the video file, the time in seconds when to take the screenshot, and the output directory. If rm is True, a previous screenshot file is removed first. By default, the screenshot is named 00000001.jpg. """ # by default, mplayer saves here the screenshot: full_path = os.path.join(outdir, MPLAYER_SCREENSHOT_FILE) if rm and os.path.exists(full_path): os.remove(full_path) cmd = screenshot.format(video_file, sec, outdir) #print cmd if process.get_return_code_of_simple_cmd(cmd) == 0: if os.path.exists(full_path): return full_path # else return None
def test_get_return_code_of_simple_cmd(): assert process.get_return_code_of_simple_cmd("date") == 0 assert process.get_return_code_of_simple_cmd("date -wrong-option") == 1