Exemple #1
0
	def testConsole(self):
		pyexec = cmd_rt.execution([])
		self.failUnlessRaises(Dead, pyexec, console = DeadConsole)
		pyexec = cmd_rt.execution([], context = [
			('foo=1', cmd_load.single_loader_descriptor)
		])
		l = {}
		self.failUnlessRaises(Dead, pyexec, locals = l, console = DeadConsole)
		self.failUnlessEqual(l['foo'], 1)
		pyexec = cmd_rt.execution([], context = [
			('noraise=1', cmd_load.single_loader_descriptor),
			('file://' + self.tmp, cmd_load.file_loader_descriptor)
		])
		self.std(pyexec, console = True)
Exemple #2
0
	def testStdinExecution(self):
		f = file(self.tmp)
		try:
			pyexec = cmd_rt.execution([], stdin = file(self.tmp))
		finally:
			f.close()
		self.std(pyexec)
Exemple #3
0
	def testExecutionWithContext(self):
		mainsrc = 'nothing="something"'
		pyexec = cmd_rt.execution([], context = [
				('noraise=1', cmd_load.single_loader_descriptor),
				('file://' + self.tmp, cmd_load.file_loader_descriptor)
			],
			main = (
				mainsrc, cmd_load.single_loader(mainsrc)
			)
		)
		l = self.std(pyexec, noraise = True, mainsrc = mainsrc)
		self.failUnlessEqual(l['nothing'], "something")

		# using module:
		pyexec = cmd_rt.execution([], context = [
				('noraise=1', cmd_load.single_loader_descriptor),
				('module:' + self.tmpmodname, cmd_load.module_loader_descriptor)
			],
			main = (
				mainsrc, cmd_load.single_loader(mainsrc)
			)
		)
		l = self.std(pyexec, noraise = True, mainsrc = mainsrc)
		self.failUnlessEqual(l['nothing'], "something")
Exemple #4
0
def run(connection, ca, co, in_xact=False, environ=os.environ):
    pythonexec = cmd_rt.execution(
        ca,
        context=getattr(co, 'python_context', None),
        loader=getattr(co, 'python_main', None),
        postmortem=co.python_postmortem,
    )
    builtin_overload = {
        'gtc': connection.connector,
        'gtx': connection,
        'query': connection.query,
        'cquery': connection.cquery,
        'statement': connection.statement,
        'execute': connection.execute,
        'settings': connection.settings,
        'cursor': connection.cursor,
        'proc': connection.proc,
        'xact': connection.xact,
    }
    __builtins__.update(builtin_overload)

    # Some points of configuration need to be demanded by a script.
    src = pythonexec.get_main_source()
    if src is not None:
        hard_params = dict(extract_parameters(src))
        if hard_params:
            if hard_params.get('disconnected', 'false') != 'true':
                connection.connect()
            else:
                in_xact = False

            iso = hard_params.get('isolation')
            if iso is not None:
                if iso == 'none':
                    in_xact = False
                else:
                    in_xact = True
                    connection.xact(isolation=iso)
        else:
            connection.connect()
    else:
        connection.connect()

    try:
        if in_xact is True:
            connection.xact.start()
        try:
            rv = pythonexec(console=SavingConsole, environ=environ)
        except:
            if in_xact is True:
                connection.xact.abort()
            raise
        if in_xact is True:
            if rv == 0:
                connection.xact.commit()
            else:
                connection.xact.abort()
    finally:
        connection.close()
        for x in builtin_overload.iterkeys():
            del __builtins__[x]
    return rv
Exemple #5
0
	def testMainWithArg(self):
		tl = cmd_load.file_loader(self.tmp)
		pyexec = cmd_rt.execution(
			['foobar.py'], main = (self.tmp, tl)
		)
		self.std(pyexec)
Exemple #6
0
	def testArgExecution(self):
		pyexec = cmd_rt.execution(
			[self.tmp],
		)
		self.std(pyexec)
Exemple #7
0
	def testLoaderExecution(self):
		pyexec = cmd_rt.execution(
			[], loader = (self.tmp, cmd_load.file_loader_descriptor)
		)
		self.std(pyexec)
Exemple #8
0
	def testMainExecution(self):
		tl = cmd_load.file_loader(self.tmp)
		pyexec = cmd_rt.execution(
			[], main = (self.tmp, tl)
		)
		self.std(pyexec)