Ejemplo n.º 1
0
		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()
Ejemplo n.º 2
0
		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()
Ejemplo n.º 3
0
		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()
Ejemplo n.º 4
0
		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()
Ejemplo n.º 5
0
		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()
Ejemplo n.º 6
0
		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()
Ejemplo n.º 7
0
		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()
Ejemplo n.º 8
0
		def run():
			response = self.master.root.missing('foo')
			yield response
			try:
				response.result
				assert 0, 'Expected an exception!'
			except AttributeError:
				pass
			g.main_quit()
Ejemplo n.º 9
0
		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()
Ejemplo n.º 10
0
		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()
Ejemplo n.º 11
0
	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
Ejemplo n.º 12
0
	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()
Ejemplo n.º 13
0
		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()
Ejemplo n.º 14
0
		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)
Ejemplo n.º 15
0
		def run():
			start = time.time()
			yield tasks.TimeoutBlocker(0.6)
			end = time.time()
			assert end > start + 0.5
			g.main_quit()
Ejemplo n.º 16
0
		def wait_for(t1, expected):
			yield t1.finished
			assert got == expected
			g.main_quit()
Ejemplo n.º 17
0
	def response(box, resp):
		reply.append(resp)
		g.main_quit()
Ejemplo n.º 18
0
		def run():
			yield None
			g.main_quit()