-
Notifications
You must be signed in to change notification settings - Fork 4
updated dbprocessing code for sqlalchemy 2.0 #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7aae917
38f12f2
6099814
9903e22
8eb5697
028dbf5
9c54844
4becd0d
812baa8
7a12790
83c4964
fbe6787
2e1cb80
bde52aa
aca843c
8002ce0
34a04ab
edc8b6a
80c5eab
ac70274
e05685a
ba5c4bf
403d1c7
587b029
f92c10c
c862aed
62ed2ee
d60fac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| from __future__ import print_function | ||
|
|
||
| import datetime | ||
| import imp | ||
| import os | ||
| import shutil | ||
| import sys | ||
|
|
@@ -259,7 +258,9 @@ def figureProduct(self, filename=None): | |
| claimed = [] | ||
| for code, desc, arg, product in act_insp: | ||
| try: | ||
| inspect = imp.load_source('inspect', code) | ||
| fname = code | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this assignment necessary? Can't we just pass "code" directly to load_source? |
||
| inspect = None | ||
| inspect = Utils.load_source('inspect',fname, inspect) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after the comma per PEP-8 |
||
| except IOError as msg: | ||
| DBlogging.dblogger.error('Inspector: "{0}" not found: {1}'.format(code, msg)) | ||
| if os.path.isfile(code + ' '): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| #!/usr/bin/env python | ||
| import codecs | ||
| from optparse import OptionParser | ||
|
|
||
| def doProcess(infile, outfile): | ||
| with open(outfile, 'w') as output: | ||
| with open(infile) as infile: | ||
| output.write(infile.read().encode('rot13')) | ||
|
|
||
| output.write(codecs.encode(infile.read(), 'rot_13')) | ||
|
Comment on lines
-7
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. go ahead and retain the empty line at the end of the function |
||
| if __name__ == '__main__': | ||
| usage = "usage: %prog infile outfile" | ||
| parser = OptionParser(usage=usage) | ||
|
|
@@ -18,6 +18,6 @@ def doProcess(infile, outfile): | |
| infile = args[0] | ||
| outfile = args[-1] | ||
|
|
||
| print "infile", infile | ||
| print "outfile", outfile | ||
| print("infile ", infile) | ||
| print("outfile ", outfile) | ||
| doProcess(infile, outfile) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,5 @@ def doProcess(infile): | |
|
|
||
| infile = args[0] | ||
|
|
||
| print "infile", infile | ||
| print("infile ", infile) | ||
| doProcess(infile) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,10 +86,8 @@ def test_parse_dbrunner_args_bad(self): | |
| finally: | ||
| sys.stderr.close() | ||
| sys.stderr = oldstderr | ||
| self.assertEqual( | ||
| '{}: error: {}'.format(os.path.basename(sys.argv[0]), msg), err) | ||
|
|
||
|
|
||
| running_script = os.path.basename(sys.argv[0]) | ||
| self.assertTrue(err.startswith("{}: error: argument".format(running_script))) | ||
|
Comment on lines
-89
to
+90
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per PEP 8, keep two blank lines after the class definition |
||
| class DBRunnerCalcRunmeTests(unittest.TestCase, dbp_testing.AddtoDBMixin): | ||
| """DBRunner tests of calc_runme""" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| import datetime | ||
| import unittest | ||
| import tempfile | ||
| import imp | ||
| import sys | ||
| import warnings | ||
| import os | ||
|
|
||
|
|
@@ -14,6 +14,7 @@ | |
| from dbprocessing import Version | ||
| from dbprocessing import DButils | ||
| from dbprocessing import Diskfile | ||
| from dbprocessing import Utils | ||
|
|
||
| class InspectorFunctions(unittest.TestCase): | ||
| """Tests of the inspector functions""" | ||
|
|
@@ -59,9 +60,9 @@ def setUp(self): | |
| self.makeTestDB() | ||
| self.loadData(os.path.join(dbp_testing.testsdir, 'data', 'db_dumps', | ||
| 'testDB_dump.json')) | ||
| self.inspect = imp.load_source('inspect', os.path.join( | ||
| dbp_testing.testsdir, 'inspector', 'rot13_L1.py')) | ||
|
|
||
| filename = os.path.join(dbp_testing.testsdir, 'inspector', 'rot13_L1.py') | ||
| self.inspect = None | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you update load_source not to take the module argument, all these None assignments can go away (several in this file) |
||
| self.inspect = Utils.load_source('inspect', filename, self.inspect) | ||
| def tearDown(self): | ||
| super(InspectorClass, self).tearDown() | ||
| self.removeTestDB() | ||
|
|
@@ -80,10 +81,11 @@ def test_inspector(self): | |
| self.assertEqual(repr(Diskfile.Diskfile(goodfile, self.dbu)), repr(self.inspect.Inspector(goodfile, self.dbu, 1,)())) | ||
| #self.assertEqual(None, self.inspect.Inspector(goodfile, self.dbu, 1,).extract_YYYYMMDD()) | ||
| # This inspector sets the data_level - not allowed | ||
| inspect = imp.load_source('inspect', os.path.join( | ||
| dbp_testing.testsdir, 'inspector', 'rot13_L1_dlevel.py')) | ||
| with warnings.catch_warnings(record=True) as w: | ||
| self.assertEqual(repr(Diskfile.Diskfile(goodfile, self.dbu)), repr(self.inspect.Inspector(goodfile, self.dbu, 1,)())) | ||
| filename = os.path.join(dbp_testing.testsdir, 'inspector', 'rot13_L1_dlevel.py') | ||
| inspect = None | ||
| inspect = Utils.load_source('inspect', filename, inspect) | ||
| with warnings.catch_warnings(record=True) as w: | ||
| self.assertEqual(repr(Diskfile.Diskfile(goodfile, self.dbu)), repr(inspect.Inspector(goodfile, self.dbu, 1,)())) | ||
| self.assertEqual(len(w), 1) | ||
| self.assertTrue(isinstance(w[0].message, UserWarning)) | ||
| self.assertEqual('Inspector rot13_L1_dlevel.py: set level to 2.0, ' | ||
|
|
@@ -93,8 +95,9 @@ def test_inspector(self): | |
| # The file doesn't match the inspector pattern... | ||
| badfile = os.path.join( | ||
| dbp_testing.testsdir, 'inspector', 'testDB_01_first.raw') | ||
| inspect = imp.load_source('inspect', os.path.join( | ||
| dbp_testing.testsdir, 'inspector', 'rot13_L1.py')) | ||
| filename = os.path.join(dbp_testing.testsdir, 'inspector', 'rot13_L1.py') | ||
| inspect = None | ||
| inspect = Utils.load_source('inspect', filename, inspect) | ||
| self.assertEqual(None, inspect.Inspector(badfile, self.dbu, 1,)()) | ||
|
|
||
| def test_inspector_regex(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,7 +304,14 @@ def test_toDatetime(self): | |
| self.assertEqual( | ||
| datetime.datetime(2010, 1, 1, 23, 59, 59, 999999), | ||
| Utils.toDatetime(datetime.date(2010, 1, 1), end=True)) | ||
|
|
||
|
|
||
| def test_load_source(self): | ||
| """Testing load_source in Utils.py""" | ||
| filename = "temp_testfile.py" | ||
| with open(filename, "w") as f: | ||
| f.write("def hello():\n return 'Hello, world!'\n") | ||
| inspect = None | ||
| module = Utils.load_source("temp_testfile", filename, inspect) | ||
| self.assertEqual(module.hello(), 'Hello, world!') | ||
|
|
||
|
Comment on lines
+307
to
+315
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test. Do leave a blank line before it, and two after (because it's the end of the class). Use tempfile to make a temporary directory and put your test file in there, then clean it up after (with a try/finally)--that way you're not leaving it in the current directory. |
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8 specifies space (i.e. one empty line) between the functions.
Can you document parameters/returns as in the other functions?
The module argument doesn't appear to be used--can it be removed? (And then update calls to it, of course).