def run(): response = root.open(tmp_file, 'w') yield response stream = response.result assert os.path.isfile(tmp_file) response = root.write(stream, 'Hello\n') yield response assert response.result == None response = root.close(stream) yield response assert response.result is None assert file(tmp_file).read() == 'Hello\n' response = root.close(stream) yield response try: response.result assert 0, 'Expected an exception!' except KeyError: pass g.main_quit()
def run(): assert os.stat(tmp_file).st_mode & 0777 == 0700 response = root.chmod(tmp_file, 0655) yield response response.result assert os.stat(tmp_file).st_mode & 0777 == 0655 g.main_quit()
def run(): maker = su.SuProxyMaker('Need to become root to test this module.') yield maker.blocker root = maker.get_root() response = root.spawnvpe(os.P_NOWAIT, 'false', ['false']) yield response pid = response.result assert pid response = root.waitpid(pid, 0) yield response (pid, status) = response.result exitstatus = os.WEXITSTATUS(status) assert exitstatus != 0 response = root.spawnvpe(os.P_WAIT, 'true', ['true']) yield response assert response.result == 0 response = root.getuid() yield response assert response.result == 0 response = root.setuid(os.getuid()) yield response assert response.result is None response = root.getuid() yield response assert response.result == os.getuid() root.finish() g.main_quit()
def run(): # Fill the input buffer... sent = 0 while True: ob = tasks.OutputBlocker(writeable) tb = tasks.TimeoutBlocker(0.2) yield ob, tb if ob.happened: sent += os.write(writeable, 'Hello\n') else: assert tb.happened break assert sent > 0 #print "send %d bytes" % sent # Read it all back... got = 0 while got < sent: got += len(os.read(readable, sent - got)) ob = tasks.OutputBlocker(writeable) tb = tasks.TimeoutBlocker(0.2) yield ob, tb assert ob.happened assert not tb.happened g.main_quit()
def run(): assert os.path.isdir(tmp_dir) response = self.master.root.rmtree(tmp_dir) yield response assert response.result is None assert not os.path.exists(tmp_dir) g.main_quit()
def run(): assert os.path.isfile(tmp) response = self.master.root.unlink(tmp) yield response assert response.result is None assert not os.path.exists(tmp) g.main_quit()
def run(): maker = su.SuProxyMaker( 'Need to become root to test this module.') yield maker.blocker root = maker.get_root() response = root.spawnvpe(os.P_NOWAIT, 'false', ['false']) yield response pid = response.result assert pid response = root.waitpid(pid, 0) yield response (pid, status) = response.result exitstatus = os.WEXITSTATUS(status) assert exitstatus != 0 response = root.spawnvpe(os.P_WAIT, 'true', ['true']) yield response assert response.result == 0 response = root.getuid() yield response assert response.result == 0 response = root.setuid(os.getuid()) yield response assert response.result is None response = root.getuid() yield response assert response.result == os.getuid() root.finish() g.main_quit()
def run(): response = root.rename(join(tmp_dir, 'old'), join(tmp_dir, 'new')) yield response assert response.result == None assert file(join(tmp_dir, 'new')).read() == 'Hello\n' g.main_quit()
def check(): call = proxy.get_object('/').get_pid() yield call, tasks.TimeoutBlocker(2) if call.happened: pid = call.get_response() rox.alert('Memo is already running (PID = %d)!' % pid) os._exit(1) g.main_quit()
def run(): response = self.master.root.missing('foo') yield response try: response.result assert 0, 'Expected an exception!' except AttributeError: pass g.main_quit()
def run(): response = self.master.root.invoke() try: response.result assert 0, 'Expected an exception!' except Exception: pass yield response response.result g.main_quit()
def run(): response = root.open(tmp_file) yield response stream = response.result response = root.read(stream, 5) yield response assert "Hello" == response.result response = root.close(stream) yield response assert response.result is None g.main_quit()
def testFinished(self): readable, writeable = os.pipe() got = [] def run(fail=False): for x in range(3): got.append(x) yield None if fail: raise Exception("Fail") def wait_for(t1, expected): yield t1.finished assert got == expected g.main_quit() t1 = tasks.Task(run()) tasks.Task(wait_for(t1, [0, 1, 2])) assert not t1.finished.happened g.main() assert t1.finished.happened old = rox.report_exception try: rox.report_exception = lambda: (got.append(False), g.main_quit()) got = [] t2 = tasks.Task(run(fail=True)) tasks.Task(wait_for(t2, [0, 1, 2, False])) g.main() finally: rox.report_exception = old
def testFinished(self): readable, writeable = os.pipe() got = [] def run(fail = False): for x in range(3): got.append(x) yield None if fail: raise Exception("Fail") def wait_for(t1, expected): yield t1.finished assert got == expected g.main_quit() t1 = tasks.Task(run()) tasks.Task(wait_for(t1, [0, 1, 2])) assert not t1.finished.happened g.main() assert t1.finished.happened old = rox.report_exception try: rox.report_exception = lambda: (got.append(False), g.main_quit()) got = [] t2 = tasks.Task(run(fail = True)) tasks.Task(wait_for(t2, [0, 1, 2, False])) g.main() finally: rox.report_exception = old
def property_changed(self, win, event): if event.atom != _message_prop: return if event.state == g.gdk.PROPERTY_NEW_VALUE: if self.ignore_next_change: # This is just us sending the request self.ignore_next_change = False return val = self.window.property_get(_message_prop, 'XA_STRING', True) if val is None: raise Exception('No response to XML-RPC call') else: self.response = val[2] if self.waiting: g.main_quit()
def message_property_changed(self): if self.ignore_next_change: # This is just us sending the request self.ignore_next_change = False return val = self.invisible.window.property_get( _message_prop, 'XA_STRING', True) self.invisible.destroy() if val is None: raise Exception('No response to XML-RPC call') else: self.invisible.xmlrpc_response = val[2] assert self.invisible.xmlrpc_response is not None, `val` self.trigger() if self.waiting: g.main_quit()
def message_property_changed(self): if self.ignore_next_change: # This is just us sending the request self.ignore_next_change = False return val = self.invisible.window.property_get(_message_prop, 'XA_STRING', True) self.invisible.destroy() if val is None: raise Exception('No response to XML-RPC call') else: self.invisible.xmlrpc_response = val[2] assert self.invisible.xmlrpc_response is not None, ` val ` self.trigger() if self.waiting: g.main_quit()
def run(): ib = tasks.InputBlocker(readable) tb = tasks.TimeoutBlocker(0.2) yield ib, tb assert not ib.happened assert tb.happened os.write(writeable, "!") tb = tasks.TimeoutBlocker(0.2) yield ib, tb assert ib.happened assert not tb.happened assert os.read(readable, 1) == '!' os.close(writeable) ib = tasks.InputBlocker(readable) yield ib assert ib.happened g.main_quit()
def run(): yield None g.main_quit()
def run(): start = time.time() yield tasks.TimeoutBlocker(0.6) end = time.time() assert end > start + 0.5 g.main_quit()
def response(box, resp): reply.append(resp) g.main_quit()
assert self.done is True or isinstance(self.done, Exception) if self.done is True: # Success # If dst wasn't a fileno stream, copy from the temp file to it if self.tmp_stream: self.tmp_stream.seek(0) self.dst.write(self.tmp_stream.read()) self.tmp_stream = None if self.waiting: assert self.done self.waiting = False g.main_quit() def wait(self): """Run a recursive mainloop until the command terminates. Raises an exception on error.""" if self.child is None: self.start() self.waiting = True while not self.done: g.main() if self.done is not True: raise self.done def kill(self, sig=signal.SIGTERM): self.killed = 1 Process.kill(self, sig)
def wait_for(t1, expected): yield t1.finished assert got == expected g.main_quit()
def timed_out(self): print >> sys.stderr, 'Timed out waiting for response to', self.method_name if self.waiting: g.main_quit() raise Exception('No response to XML-RPC call')
def LogoutWithoutConfirm(self): g.main_quit()
assert self.done is True or isinstance(self.done, Exception) if self.done is True: # Success # If dst wasn't a fileno stream, copy from the temp file to it if self.tmp_stream: self.tmp_stream.seek(0) self.dst.write(self.tmp_stream.read()) self.tmp_stream = None if self.waiting: assert self.done self.waiting = False g.main_quit() def wait(self): """Run a recursive mainloop until the command terminates. Raises an exception on error.""" if self.child is None: self.start() self.waiting = True while not self.done: g.main() if self.done is not True: raise self.done def kill(self, sig = signal.SIGTERM): self.killed = 1 Process.kill(self, sig)