Exemplo n.º 1
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()
Exemplo n.º 2
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()
Exemplo n.º 3
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()
Exemplo n.º 4
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()
Exemplo n.º 5
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()
Exemplo n.º 6
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()
Exemplo n.º 7
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()
Exemplo n.º 8
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()
Exemplo n.º 9
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()
Exemplo n.º 10
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()
Exemplo n.º 11
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()
Exemplo n.º 12
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()
Exemplo n.º 13
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()
Exemplo n.º 14
0
 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()
Exemplo n.º 15
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()
Exemplo n.º 16
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()
Exemplo n.º 17
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()
Exemplo n.º 18
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()
Exemplo n.º 19
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()
Exemplo n.º 20
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()
Exemplo n.º 21
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()
Exemplo n.º 22
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
Exemplo n.º 23
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
Exemplo n.º 24
0
    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()
Exemplo n.º 25
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()
Exemplo n.º 26
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()
Exemplo n.º 27
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()
Exemplo n.º 28
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()
Exemplo n.º 29
0
		def run():
			yield None
			g.main_quit()
Exemplo n.º 30
0
		def run():
			start = time.time()
			yield tasks.TimeoutBlocker(0.6)
			end = time.time()
			assert end > start + 0.5
			g.main_quit()
Exemplo n.º 31
0
	def response(box, resp):
		reply.append(resp)
		g.main_quit()
Exemplo n.º 32
0
 def run():
     yield None
     g.main_quit()
Exemplo n.º 33
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)
Exemplo n.º 34
0
		def wait_for(t1, expected):
			yield t1.finished
			assert got == expected
			g.main_quit()
Exemplo n.º 35
0
 def run():
     start = time.time()
     yield tasks.TimeoutBlocker(0.6)
     end = time.time()
     assert end > start + 0.5
     g.main_quit()
Exemplo n.º 36
0
 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')
Exemplo n.º 37
0
 def LogoutWithoutConfirm(self):
     g.main_quit()
Exemplo n.º 38
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)
Exemplo n.º 39
0
 def wait_for(t1, expected):
     yield t1.finished
     assert got == expected
     g.main_quit()