예제 #1
0
 def test_startable(self):
     # we can start executables
     path = os.path.join(self.path_dir, 'myscript')
     stamp_file = os.path.join(self.path_dir, 'i_was_here')
     pysrc = 'open("%s", "w").write("I was here")' % stamp_file
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path)
     cmd.run()
     cmd.wait()
     assert os.path.isfile(stamp_file)
예제 #2
0
 def test_args(self):
     # we can pass in arguments
     path = os.path.join(self.path_dir, 'myscript')
     stamp_file = os.path.join(self.path_dir, 'i_was_here')
     pysrc = 'open("%s", "w").write(sys.argv[1])' % stamp_file
     create_python_script(path, pysrc)
     cmd = BackgroundCommand([path, 'myarg'])
     cmd.run()
     cmd.wait()
     assert open(stamp_file, 'r').read() == 'myarg'
예제 #3
0
 def test_args(self):
     # we can pass in arguments
     path = os.path.join(self.path_dir, 'myscript')
     stamp_file = os.path.join(self.path_dir, 'i_was_here')
     pysrc = 'open("%s", "w").write(sys.argv[1])' % stamp_file
     create_python_script(path, pysrc)
     cmd = BackgroundCommand([path, 'myarg'])
     cmd.run()
     cmd.wait()
     assert open(stamp_file, 'r').read() == 'myarg'
예제 #4
0
 def test_startable(self):
     # we can start executables
     path = os.path.join(self.path_dir, 'myscript')
     stamp_file = os.path.join(self.path_dir, 'i_was_here')
     pysrc = 'open("%s", "w").write("I was here")' % stamp_file
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path)
     cmd.run()
     cmd.wait()
     assert os.path.isfile(stamp_file)
예제 #5
0
 def test_timeout(self):
     # we can set a timeout
     path = os.path.join(self.path_dir, 'myscript')
     pysrc = 'time.sleep(10)'
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path, timeout=0.1)
     t_stamp1 = time.time()
     cmd.start()
     cmd.wait()
     t_stamp2 = time.time()
     assert t_stamp2 - t_stamp1 < 5
     assert not cmd.is_alive()
     assert cmd.returncode == -9
     assert cmd.stderr_data == b''
     assert cmd.stdout_data == b''
     # timeouts kill processes
     assert cmd.is_killed is True
예제 #6
0
 def test_timeout(self):
     # we can set a timeout
     path = os.path.join(self.path_dir, 'myscript')
     pysrc = 'time.sleep(10)'
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path, timeout=0.1)
     t_stamp1 = time.time()
     cmd.start()
     cmd.wait()
     t_stamp2 = time.time()
     assert t_stamp2 - t_stamp1 < 5
     assert not cmd.is_alive()
     assert cmd.returncode == -9
     assert cmd.stderr_data == b''
     assert cmd.stdout_data == b''
     # timeouts kill processes
     assert cmd.is_killed is True
예제 #7
0
 def test_wait_stdout(self):
     # we can get the stdout output when wait()-ing
     path = os.path.join(self.path_dir, 'myscript')
     pysrc = 'print("Hello from myscript")'
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path)
     cmd.run()
     ret_code, stdout, stderr = cmd.wait()
     assert stdout == b'Hello from myscript\n'
예제 #8
0
 def test_wait_returncode(self):
     # we get the returncode
     path = os.path.join(self.path_dir, 'myscript')
     pysrc = 'sys.exit(42)'
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path)
     cmd.run()
     ret_code, stdout, stderr = cmd.wait()
     assert ret_code == 42
예제 #9
0
 def test_wait_stdout(self):
     # we can get the stdout output when wait()-ing
     path = os.path.join(self.path_dir, 'myscript')
     pysrc = 'print("Hello from myscript")'
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path)
     cmd.run()
     ret_code, stdout, stderr = cmd.wait()
     assert stdout == b'Hello from myscript\n'
예제 #10
0
 def test_wait_returncode(self):
     # we get the returncode
     path = os.path.join(self.path_dir, 'myscript')
     pysrc = 'sys.exit(42)'
     create_python_script(path, pysrc)
     cmd = BackgroundCommand(path)
     cmd.run()
     ret_code, stdout, stderr = cmd.wait()
     assert ret_code == 42