Mercurial > sqlpython
changeset 459:77ec18c38ff8 1.7.0
prepare to release 1.7.0
author | cat@eee |
---|---|
date | Fri, 19 Feb 2010 21:49:59 -0500 |
parents | a55e0f05f745 |
children | 455b66f15be4 |
files | sqlpython/plothandler.py sqlpython/sqlpyPlus.py sqlpython/sqlpy_gerald.py sqlpython/test_sqlpyPlus.py |
diffstat | 4 files changed, 2 insertions(+), 108 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/plothandler.py Wed Feb 17 23:20:20 2010 -0500 +++ b/sqlpython/plothandler.py Fri Feb 19 21:49:59 2010 -0500 @@ -68,7 +68,6 @@ self.yplots.append(pylab.pie(self.yserieslists[0], labels=self.xticks or self.xvalues)) self.legends = [self.legends[0]] def draw(self): - #import pdb; pdb.set_trace() if not self.yserieslists: print 'At least one quantitative column needed to plot.' return None
--- a/sqlpython/sqlpyPlus.py Wed Feb 17 23:20:20 2010 -0500 +++ b/sqlpython/sqlpyPlus.py Fri Feb 19 21:49:59 2010 -0500 @@ -336,7 +336,6 @@ imgwidth = 400 def __init__(self, blob_oid, under_limit, sqlpython_instance): self.url = '' - import pdb; pdb.set_trace() if under_limit: if self.folder_ok(): self.lobject = psycopg2.extensions.lobject(conn=sqlpython_instance.current_instance.connection, oid=blob_oid) @@ -498,6 +497,7 @@ most recent resultset is `r[-1]`. SQL bind, substitution variables are exposed as `binds`, `substs`. SQL and sqlpython commands can be issued with `sql("your command")`. + Run python code from external files with ``run("filename.py")`` ''' return Cmd.do_py(self, arg) @@ -1376,14 +1376,8 @@ Accepts strings like `foo = 'bar'` or `baz := 22`, returns (assigned? (T/F), variable, new-value) - >>> s = sqlpyPlus() - >>> s.interpret_variable_assignment(s.parsed("foo = 'bar'")) - (True, 'foo', 'bar') - >>> s.interpret_variable_assignment(s.parsed("baz := 22")) - (True, 'baz', 22) - >>> s.interpret_variable_assignment(s.parsed("foo")) - (False, 'foo', None) ''' + #TODO: quoted assignments currently failing? arg = self.parsed(arg) try: var, val = self.assignmentSplitter.split(arg, maxsplit=1)
--- a/sqlpython/sqlpy_gerald.py Wed Feb 17 23:20:20 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -import gerald - -class SchemaSet(object): - def __init__(self, connection, rdbms, connect_string): - self.schemas = {} - curs = connection.cursor() - if rdbms == 'postgres': - curs.execute('SELECT schema_name FROM information_schema.schemata') - for row in curs.fetchall(): - schema = row[0] - self.schemas[schema] = gerald.PostgresSchema(schema, connect_string) - elif rdbms == 'oracle': - curs.execute('SELECT DISTINCT owner FROM all_objects') - for row in curs.fetchall(): - schema = row[0] - - - -import psycopg2 -connstr = 'postgres:/catherine:catherine@localhost/catherine' -conn = psycopg2.connect("dbname='catherine' user='catherine' password='catherine' host='localhost'") -ss = SchemaSet(conn, 'postgres', connstr)
--- a/sqlpython/test_sqlpyPlus.py Wed Feb 17 23:20:20 2010 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -import unittest, sys, tempfile, re, os.path, pyparsing -from sqlpyPlus import * - -class Borg(object): - # from Python Cookbook, 2nd Ed., recipe 6.16 - _shared_state = {} - def __new__(cls, *a, **k): - obj = object.__new__(cls, *a, **k) - obj.__dict__ = cls._shared_state - return obj - -class OutputTrap(Borg): - old_stdout = sys.stdout - def __init__(self): - self.trap = tempfile.TemporaryFile() - sys.stdout = self.trap - def dump(self): - self.trap.seek(0) - result = self.trap.read() - self.trap.close() - self.trap = tempfile.TemporaryFile() - sys.stdout = self.trap - return result - def teardown(self): - sys.stdout = self.old_stdout - -class TestSqlPyPlus(unittest.TestCase): - transcriptReader = re.compile('testdata@eqdev> (.*?)\n(.*?)(?=testdata@eqdev>)', re.DOTALL) - transcriptFileName = 'test_sqlpyPlus.txt' - def setUp(self): - self.outputTrap = OutputTrap() - transcriptFile = open(self.transcriptFileName) - self.transcript = transcriptFile.read() - transcriptFile.close() - self.directives = self.transcriptReader.finditer(self.transcript) - self.testsession = sqlpyPlus() - self.testsession.onecmd('connect ' + connectString) - self.transcriptReader = re.compile( - '%s(.*?)\n\n(.*?)(?=%s)' % (self.testsession.prompt, self.testsession.prompt), re.DOTALL) - self.commandCleaner = '\n%s' % (self.testsession.continuationPrompt) - def assertOutput(self, commandtext, expected, lineNum): - self.testsession.onecmd(commandtext) - result = self.outputTrap.dump() - self.assertEqual(expected.strip(), result.strip(), - '\nFile %s, line %d\nCommand was:\n%s\nExpected:\n%s\nGot:\n%s\n' % - (self.transcriptFileName, lineNum, commandtext, expected, result)) - def testall(self): - for directive in self.directives: - (command, result) = directive.groups() - command = command.replace(self.commandCleaner, '\n') - self.assertOutput(command, result, lineNum=self.transcript.count('\n', 0, directive.start())) - def tearDown(self): - self.outputTrap.teardown() - -try: - connectString = sys.argv.pop(1) -except IndexError: - print 'Usage: python %s username/password@oracleSID' % os.path.split(__file__)[-1] - sys.exit() -unittest.main() - - -def transcript(cmdapp, filename='test_sqlpyPlus.txt'): - tfile = open(filename) - txt = tfile.read() - tfile.close() - prompt = pyparsing.Suppress(pyparsing.lineStart + cmd.prompt) - continuationPrompt = pyparsing.Suppress(pyparsing.lineStart + cmd.continuationPrompt) - cmdtxtPattern = (prompt + pyparsing.restOfLine + pyparsing.ZeroOrMore( - pyparsing.lineEnd + continuationPrompt + pyparsing.restOfLine))("command") - previousStartPoint = 0 - results = [] - for onecmd in cmdtxtPattern.scanString(txt): - if len(results) > 0: - results[-1]['response'] = txt[previousStartPoint:onecmd[1]] - results.append({'command': ''.join(onecmd[0].command), 'response': txt[onecmd[2]:]}) - previousStartPoint = onecmd[2] \ No newline at end of file