From 77745ab5f32f2fe12d3fa8d1d0c6b0cf84cbb3ac Mon Sep 17 00:00:00 2001 From: Andrew Geiger Date: Sun, 29 Mar 2020 00:29:39 -0400 Subject: [PATCH] Refactoring for changed module level name. --- shared/tools/data.py | 10 +- shared/tools/dump.py | 2 +- shared/tools/logging.py | 4 +- shared/tools/pretty.py | 2 +- shared/tools/thread.py | 2 +- shared/tools/venv.py | 4 +- test/shared/{corso => tools}/__init__.py | 0 test/shared/{corso => tools}/test_data.py | 124 +++++++++--------- test/shared/{corso => tools}/test_logging.py | 12 +- test/shared/{corso => tools}/test_meta.py | 126 +++++++++---------- test/shared/{corso => tools}/test_thread.py | 12 +- test/shared/{corso => tools}/test_venv.py | 112 ++++++++--------- 12 files changed, 205 insertions(+), 205 deletions(-) rename test/shared/{corso => tools}/__init__.py (100%) rename test/shared/{corso => tools}/test_data.py (95%) rename test/shared/{corso => tools}/test_logging.py (84%) rename test/shared/{corso => tools}/test_meta.py (91%) rename test/shared/{corso => tools}/test_thread.py (96%) rename test/shared/{corso => tools}/test_venv.py (94%) diff --git a/shared/tools/data.py b/shared/tools/data.py index 5424230..b3752e5 100644 --- a/shared/tools/data.py +++ b/shared/tools/data.py @@ -18,7 +18,7 @@ def datasetToListDict(dataset): """Converts a dataset into a list of dictionaries. Convenient to treat data on a row-by-row basis naturally in Python. - >>> from shared.corso.examples import simpleDataset + >>> from shared.tools.examples import simpleDataset >>> datasetToListDict(simpleDataset) [{'a': 1, 'b': 2, 'c': 3}, {'a': 4, 'b': 5, 'c': 6}, {'a': 7, 'b': 8, 'c': 9}] """ @@ -33,7 +33,7 @@ def datasetToDictList(dataset): """Converts a dataset into a dictionary of column lists. Convenient for treating data on a specific-column basis. - >>> from shared.corso.examples import simpleDataset + >>> from shared.tools.examples import simpleDataset >>> datasetToDictList(simpleDataset) {'a': [1, 4, 7], 'b': [2, 5, 8], 'c': [3, 6, 9]} """ @@ -45,7 +45,7 @@ def gatherKeys(data): """Gather all the possible keys in a list of dicts. (Note that voids in a particular row aren't too bad.) - >>> from shared.corso.examples import complexListDict + >>> from shared.tools.examples import complexListDict >>> gatherKeys(complexListDict) ['date', 'double', 'int', 'string'] """ @@ -60,8 +60,8 @@ def listDictToDataset(data, keys=None): A selection of keys can be requested (and reordered), where missing entries are filled with None values. - >>> from shared.corso.pretty import p - >>> from shared.corso.examples import simpleListDict + >>> from shared.tools.pretty import p + >>> from shared.tools.examples import simpleListDict >>> ld2ds = listDictToDataset(simpleListDict, keys=['c','b']) >>> p(ld2ds) "ld2ds" of 3 elements and 2 columns diff --git a/shared/tools/dump.py b/shared/tools/dump.py index 44c714b..94f923a 100644 --- a/shared/tools/dump.py +++ b/shared/tools/dump.py @@ -4,7 +4,7 @@ import array.array, base64, os, re -from shared.corso.meta import getDesignerContext +from shared.tools.meta import getDesignerContext __copyright__ = """Copyright (C) 2020 Corso Systems""" diff --git a/shared/tools/logging.py b/shared/tools/logging.py index f8efaaa..ebb43ca 100644 --- a/shared/tools/logging.py +++ b/shared/tools/logging.py @@ -10,7 +10,7 @@ pass # only needed for when the logger's running on a Vision client; gateway won't have this in scope. import sys, re -from shared.corso.meta import currentStackDepth, getObjectByName, GLOBAL_MESSAGE_PROJECT_NAME +from shared.tools.meta import currentStackDepth, getObjectByName, GLOBAL_MESSAGE_PROJECT_NAME __copyright__ = """Copyright (C) 2020 Corso Systems""" @@ -369,7 +369,7 @@ def messageHandler(cls, payload): Copy and paste the following directly into a gateway message event script: - from shared.corso.logging import Logger + from shared.tools.logging import Logger Logger.messageHandler(payload) """ cls._validatePayload(payload) diff --git a/shared/tools/pretty.py b/shared/tools/pretty.py index 0d61d31..4206c2a 100644 --- a/shared/tools/pretty.py +++ b/shared/tools/pretty.py @@ -9,7 +9,7 @@ from java.lang import Exception as JavaException from com.inductiveautomation.ignition.common import BasicDataset from com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities import PyDataSet -from shared.corso.meta import getObjectName, getFunctionCallSigs, sentinel +from shared.tools.meta import getObjectName, getFunctionCallSigs, sentinel __copyright__ = """Copyright (C) 2020 Corso Systems""" diff --git a/shared/tools/thread.py b/shared/tools/thread.py index a9021df..c48586f 100644 --- a/shared/tools/thread.py +++ b/shared/tools/thread.py @@ -22,7 +22,7 @@ def async(startDelaySeconds=None): sys.stderr writer. It turns out this is simply always the JVM's console, though. >>> # For a function to immediately run in another thread, simply decorated it: - >>> from shared.corso.logging import BaseLogger + >>> from shared.tools.logging import BaseLogger >>> @async ... def foo(x,y=5): ... print x,y diff --git a/shared/tools/venv.py b/shared/tools/venv.py index 184bc40..53d55d8 100644 --- a/shared/tools/venv.py +++ b/shared/tools/venv.py @@ -5,8 +5,8 @@ import sys,imp -from shared.corso.meta import currentStackDepth -from shared.corso.pretty import p,pdir +from shared.tools.meta import currentStackDepth +from shared.tools.pretty import p,pdir __copyright__ = """Copyright (C) 2020 Corso Systems""" diff --git a/test/shared/corso/__init__.py b/test/shared/tools/__init__.py similarity index 100% rename from test/shared/corso/__init__.py rename to test/shared/tools/__init__.py diff --git a/test/shared/corso/test_data.py b/test/shared/tools/test_data.py similarity index 95% rename from test/shared/corso/test_data.py rename to test/shared/tools/test_data.py index dd07aed..6299b9a 100644 --- a/test/shared/corso/test_data.py +++ b/test/shared/tools/test_data.py @@ -1,63 +1,63 @@ -import unittest, doctest - -from org.apache.commons.lang3.time import DateUtils -from java.util import Date - -from shared.corso.data import * - - -doctest.run_docstring_examples(datasetToListDict,globals()) -doctest.run_docstring_examples(datasetToDictList,globals()) -doctest.run_docstring_examples(gatherKeys,globals()) -doctest.run_docstring_examples(listDictToDataset,globals()) - - -class RecordSetTestCase(unittest.TestCase): - - def setUp(self): - self.columnNames = 'c1 c2 c3'.split() - self.numColumns = len(self.columnNames) - self.numRows = 4 - self.RecordSet = genRecordSet(self.columnNames) - - def tearDown(self): - pass - - # Test different inputs - def test_readListOfLists(self): - # generate source data - listOfLists= [list(range(i,i+self.numColumns)) - for i in range(1,self.numRows*self.numColumns,self.numColumns)] - - # generate test data - listOfRecordSets = [self.RecordSet(row) for row in listOfLists] - - # check dimensions - self.assertTrue(all(len(listOfRecordSets[i].keys()) for i in range(self.numColumns))) - self.assertEqual(len(listOfRecordSets), self.numRows) - - # verify data imported correctly - for lotRow,lorsRow in zip(listOfLists, listOfRecordSets): - self.assertEqual(lotRow,list(lorsRow)) - - # Test different inputs - def test_readListOfTuples(self): - # generate source data - listOfTuples = [tuple(range(i,i+self.numColumns)) - for i in range(1,self.numRows*self.numColumns,self.numColumns)] - - # generate test data - listOfRecordSets = [self.RecordSet(row) for row in listOfTuples] - - # check dimensions - self.assertTrue(all(len(listOfRecordSets[i].keys()) for i in range(self.numColumns))) - self.assertEqual(len(listOfRecordSets), self.numRows) - - # verify data imported correctly - for lotRow,lorsRow in zip(listOfTuples, listOfRecordSets): - self.assertEqual(lotRow,tuple(lorsRow)) - - -suite = unittest.TestLoader().loadTestsFromTestCase(RecordSetTestCase) - +import unittest, doctest + +from org.apache.commons.lang3.time import DateUtils +from java.util import Date + +from shared.tools.data import * + + +doctest.run_docstring_examples(datasetToListDict,globals()) +doctest.run_docstring_examples(datasetToDictList,globals()) +doctest.run_docstring_examples(gatherKeys,globals()) +doctest.run_docstring_examples(listDictToDataset,globals()) + + +class RecordSetTestCase(unittest.TestCase): + + def setUp(self): + self.columnNames = 'c1 c2 c3'.split() + self.numColumns = len(self.columnNames) + self.numRows = 4 + self.RecordSet = genRecordSet(self.columnNames) + + def tearDown(self): + pass + + # Test different inputs + def test_readListOfLists(self): + # generate source data + listOfLists= [list(range(i,i+self.numColumns)) + for i in range(1,self.numRows*self.numColumns,self.numColumns)] + + # generate test data + listOfRecordSets = [self.RecordSet(row) for row in listOfLists] + + # check dimensions + self.assertTrue(all(len(listOfRecordSets[i].keys()) for i in range(self.numColumns))) + self.assertEqual(len(listOfRecordSets), self.numRows) + + # verify data imported correctly + for lotRow,lorsRow in zip(listOfLists, listOfRecordSets): + self.assertEqual(lotRow,list(lorsRow)) + + # Test different inputs + def test_readListOfTuples(self): + # generate source data + listOfTuples = [tuple(range(i,i+self.numColumns)) + for i in range(1,self.numRows*self.numColumns,self.numColumns)] + + # generate test data + listOfRecordSets = [self.RecordSet(row) for row in listOfTuples] + + # check dimensions + self.assertTrue(all(len(listOfRecordSets[i].keys()) for i in range(self.numColumns))) + self.assertEqual(len(listOfRecordSets), self.numRows) + + # verify data imported correctly + for lotRow,lorsRow in zip(listOfTuples, listOfRecordSets): + self.assertEqual(lotRow,tuple(lorsRow)) + + +suite = unittest.TestLoader().loadTestsFromTestCase(RecordSetTestCase) + unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file diff --git a/test/shared/corso/test_logging.py b/test/shared/tools/test_logging.py similarity index 84% rename from test/shared/corso/test_logging.py rename to test/shared/tools/test_logging.py index 66ee520..b9a10f9 100644 --- a/test/shared/corso/test_logging.py +++ b/test/shared/tools/test_logging.py @@ -1,7 +1,7 @@ -import unittest, doctest - -from shared.corso.logging import BaseLogger - -doctest.run_docstring_examples(BaseLogger()._generateMessage,globals()) -doctest.run_docstring_examples(BaseLogger()._formatString, globals(), optionflags=doctest.ELLIPSIS) +import unittest, doctest + +from shared.tools.logging import BaseLogger + +doctest.run_docstring_examples(BaseLogger()._generateMessage,globals()) +doctest.run_docstring_examples(BaseLogger()._formatString, globals(), optionflags=doctest.ELLIPSIS) doctest.run_docstring_examples(BaseLogger()._bracketString, globals()) \ No newline at end of file diff --git a/test/shared/corso/test_meta.py b/test/shared/tools/test_meta.py similarity index 91% rename from test/shared/corso/test_meta.py rename to test/shared/tools/test_meta.py index 2c33720..e62918b 100644 --- a/test/shared/corso/test_meta.py +++ b/test/shared/tools/test_meta.py @@ -1,64 +1,64 @@ -import unittest, doctest - -from shared.corso.meta import sentinel, getFunctionCallSigs - -doctest.run_docstring_examples(sentinel,globals()) -doctest.run_docstring_examples(getFunctionCallSigs,globals()) - - -from shared.corso.meta import currentStackDepth, getObjectByName, getObjectName - - -class ObjectSearchTestCase(unittest.TestCase): - - def test_stackSearch(self): - # Generate a stack search - def foo(): - x = 33 - def bar(): - y = 2 - def baz(): - z = 3 - x = 725 - - currentDepth = currentStackDepth() - - # Start in this stack frame, go into the past - self.assertEqual(725, getObjectByName('x')) - # Start at the deepest past, and go towards the current stack frame - self.assertEqual(33, getObjectByName('x', startRecent=False)) - # Start at the deepest past and go deeper (before foo was defined!) - self.assertEqual(None, getObjectByName('x', currentDepth)) - # start at the deepest past and come towards the current stack frame - self.assertEqual(33, getObjectByName('x', currentDepth, startRecent=False)) - - self.assertEqual('foo', getObjectName(foo)) - baz() - bar() - foo() - - def test_PythonFunctionSigs(self): - # Generate a few different functions to verify signatures. - def fun1(): - pass - def fun2(x,y,z=5): - pass - self.assertEqual('()', getFunctionCallSigs(fun1)) - self.assertEqual('(x, y, z=5)', getFunctionCallSigs(fun2)) - - def test_JavaFunctionSigs(self): - from java.util import Random - - # Check the no args case - self.assertEqual('()', getFunctionCallSigs(Random().nextBoolean)) - # Check the single call method case - self.assertEqual('()', getFunctionCallSigs(Random().setSeed)) - # Check the many ways to call case - self.assertEqual('() -OR- () -OR- (, ) -OR- (, , )', getFunctionCallSigs(Random().ints)) - # Try a different join method - self.assertEqual('()|()|(, )|(, , )', getFunctionCallSigs(Random().ints, joinClause='|')) - - -suite = unittest.TestLoader().loadTestsFromTestCase(ObjectSearchTestCase) -unittest.TextTestRunner(verbosity=2).run(suite) +import unittest, doctest + +from shared.tools.meta import sentinel, getFunctionCallSigs + +doctest.run_docstring_examples(sentinel,globals()) +doctest.run_docstring_examples(getFunctionCallSigs,globals()) + + +from shared.tools.meta import currentStackDepth, getObjectByName, getObjectName + + +class ObjectSearchTestCase(unittest.TestCase): + + def test_stackSearch(self): + # Generate a stack search + def foo(): + x = 33 + def bar(): + y = 2 + def baz(): + z = 3 + x = 725 + + currentDepth = currentStackDepth() + + # Start in this stack frame, go into the past + self.assertEqual(725, getObjectByName('x')) + # Start at the deepest past, and go towards the current stack frame + self.assertEqual(33, getObjectByName('x', startRecent=False)) + # Start at the deepest past and go deeper (before foo was defined!) + self.assertEqual(None, getObjectByName('x', currentDepth)) + # start at the deepest past and come towards the current stack frame + self.assertEqual(33, getObjectByName('x', currentDepth, startRecent=False)) + + self.assertEqual('foo', getObjectName(foo)) + baz() + bar() + foo() + + def test_PythonFunctionSigs(self): + # Generate a few different functions to verify signatures. + def fun1(): + pass + def fun2(x,y,z=5): + pass + self.assertEqual('()', getFunctionCallSigs(fun1)) + self.assertEqual('(x, y, z=5)', getFunctionCallSigs(fun2)) + + def test_JavaFunctionSigs(self): + from java.util import Random + + # Check the no args case + self.assertEqual('()', getFunctionCallSigs(Random().nextBoolean)) + # Check the single call method case + self.assertEqual('()', getFunctionCallSigs(Random().setSeed)) + # Check the many ways to call case + self.assertEqual('() -OR- () -OR- (, ) -OR- (, , )', getFunctionCallSigs(Random().ints)) + # Try a different join method + self.assertEqual('()|()|(, )|(, , )', getFunctionCallSigs(Random().ints, joinClause='|')) + + +suite = unittest.TestLoader().loadTestsFromTestCase(ObjectSearchTestCase) +unittest.TextTestRunner(verbosity=2).run(suite) \ No newline at end of file diff --git a/test/shared/corso/test_thread.py b/test/shared/tools/test_thread.py similarity index 96% rename from test/shared/corso/test_thread.py rename to test/shared/tools/test_thread.py index a3c0d06..1b1e490 100644 --- a/test/shared/corso/test_thread.py +++ b/test/shared/tools/test_thread.py @@ -1,7 +1,7 @@ -import unittest, doctest - - -from shared.coros.thread import async - - +import unittest, doctest + + +from shared.coros.thread import async + + doctest.run_docstring_examples(async, globals(), optionflags=doctest.ELLIPSIS) \ No newline at end of file diff --git a/test/shared/corso/test_venv.py b/test/shared/tools/test_venv.py similarity index 94% rename from test/shared/corso/test_venv.py rename to test/shared/tools/test_venv.py index 1ec146b..f8ce810 100644 --- a/test/shared/corso/test_venv.py +++ b/test/shared/tools/test_venv.py @@ -1,56 +1,56 @@ -import unittest, doctest - -import sys - -from shared.corso.venv import Venv - - -# doctest.run_docstring_examples(Venv, globals(), optionflags=doctest.ELLIPSIS) - - -class VenvTestCases(unittest.TestCase): - - @staticmethod - def _createScopeInFunction(): - modGen = Venv('examples.venv.functionScope').anchorModuleStart() - def foo(): - return 'foo!' - modGen.anchorModuleEnd().bootstrapModule() - - def test_bootstrapInFunction(self): - def importForScopeInFunction(): - from examples.venv.functionScope import foo - - self.assertRaises(ImportError, importForScopeInFunction) - self._createScopeInFunction() - self.assertNotIn('foo', locals()) - from examples.venv.functionScope import foo - self.assertEqual(foo(), 'foo!') - - def test_withStatementEnvironment(self): - def createEnvironment(): - venv = Venv('examples.venv.presetScope').anchorModuleStart() - def bar(): - return 'bar!' - venv.anchorModuleEnd() - return venv - - def importForWithStatementIsolation(): - from examples.venv.presetScope import bar - def callBar(): - bar() - self.assertRaises(ImportError, importForWithStatementIsolation) - self.assertNotIn('bar', locals()) - - with createEnvironment(): - from examples.venv.presetScope import bar - self.assertEqual(bar(), 'bar!') - abc = 123 - - self.assertNotIn('bar', locals()) - self.assertNotIn('abc', locals()) - self.assertRaises(ImportError, importForWithStatementIsolation) - - -suite = unittest.TestLoader().loadTestsFromTestCase(VenvTestCases) -unittest.TextTestRunner(verbosity=1).run(suite) +import unittest, doctest + +import sys + +from shared.tools.venv import Venv + + +# doctest.run_docstring_examples(Venv, globals(), optionflags=doctest.ELLIPSIS) + + +class VenvTestCases(unittest.TestCase): + + @staticmethod + def _createScopeInFunction(): + modGen = Venv('examples.venv.functionScope').anchorModuleStart() + def foo(): + return 'foo!' + modGen.anchorModuleEnd().bootstrapModule() + + def test_bootstrapInFunction(self): + def importForScopeInFunction(): + from examples.venv.functionScope import foo + + self.assertRaises(ImportError, importForScopeInFunction) + self._createScopeInFunction() + self.assertNotIn('foo', locals()) + from examples.venv.functionScope import foo + self.assertEqual(foo(), 'foo!') + + def test_withStatementEnvironment(self): + def createEnvironment(): + venv = Venv('examples.venv.presetScope').anchorModuleStart() + def bar(): + return 'bar!' + venv.anchorModuleEnd() + return venv + + def importForWithStatementIsolation(): + from examples.venv.presetScope import bar + def callBar(): + bar() + self.assertRaises(ImportError, importForWithStatementIsolation) + self.assertNotIn('bar', locals()) + + with createEnvironment(): + from examples.venv.presetScope import bar + self.assertEqual(bar(), 'bar!') + abc = 123 + + self.assertNotIn('bar', locals()) + self.assertNotIn('abc', locals()) + self.assertRaises(ImportError, importForWithStatementIsolation) + + +suite = unittest.TestLoader().loadTestsFromTestCase(VenvTestCases) +unittest.TextTestRunner(verbosity=1).run(suite)