Skip to content

Commit

Permalink
Refactoring for changed module level name.
Browse files Browse the repository at this point in the history
  • Loading branch information
null-directory committed Mar 29, 2020
1 parent 41fa873 commit 77745ab
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 205 deletions.
10 changes: 5 additions & 5 deletions shared/tools/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
"""
Expand All @@ -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]}
"""
Expand All @@ -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']
"""
Expand All @@ -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" <DataSet> of 3 elements and 2 columns
Expand Down
2 changes: 1 addition & 1 deletion shared/tools/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions shared/tools/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion shared/tools/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion shared/tools/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions shared/tools/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
File renamed without changes.
124 changes: 62 additions & 62 deletions test/shared/corso/test_data.py → test/shared/tools/test_data.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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())
126 changes: 63 additions & 63 deletions test/shared/corso/test_meta.py → test/shared/tools/test_meta.py
Original file line number Diff line number Diff line change
@@ -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('(<long>)', getFunctionCallSigs(Random().setSeed))
# Check the many ways to call case
self.assertEqual('() -OR- (<long>) -OR- (<int>, <int>) -OR- (<long>, <int>, <int>)', getFunctionCallSigs(Random().ints))
# Try a different join method
self.assertEqual('()|(<long>)|(<int>, <int>)|(<long>, <int>, <int>)', 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('(<long>)', getFunctionCallSigs(Random().setSeed))
# Check the many ways to call case
self.assertEqual('() -OR- (<long>) -OR- (<int>, <int>) -OR- (<long>, <int>, <int>)', getFunctionCallSigs(Random().ints))
# Try a different join method
self.assertEqual('()|(<long>)|(<int>, <int>)|(<long>, <int>, <int>)', getFunctionCallSigs(Random().ints, joinClause='|'))


suite = unittest.TestLoader().loadTestsFromTestCase(ObjectSearchTestCase)
unittest.TextTestRunner(verbosity=2).run(suite)

Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit 77745ab

Please sign in to comment.