Permalink
Browse files

Add a function for running all unit tests in one process.

This may aid in runtime type discovery.

Had to disable (the empty) pyassem_test.py for now due to its required
import path.
  • Loading branch information...
Andy Chu
Andy Chu committed Mar 19, 2018
1 parent 1478050 commit dbb5580fc00b2585a4d7761a360b368eca63fa4a
Showing with 37 additions and 14 deletions.
  1. +5 −6 asdl/arith_ast.py
  2. +10 −4 core/util.py
  3. +3 −1 opy/compiler2/pyassem_test.py
  4. +1 −3 opy/compiler2/symbols_test.py
  5. +18 −0 test/unit.sh
View
@@ -8,12 +8,11 @@
from asdl import asdl_ as asdl
from asdl import py_meta
from core import util
this_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
schema_path = os.path.join(this_dir, 'arith.asdl')
f = util.GetResourceLoader().open('asdl/arith.asdl')
_asdl_module, _type_lookup = asdl.LoadSchema(f, {}) # no app_types
f.close()
with open(schema_path) as f:
module = asdl.parse(f)
type_lookup = asdl.ResolveTypes(module)
root = sys.modules[__name__]
py_meta.MakeTypes(module, root, type_lookup)
py_meta.MakeTypes(_asdl_module, root, _type_lookup)
View
@@ -186,9 +186,8 @@ def Pop(self):
class _FileResourceLoader(object):
"""Open resources relative to argv[0]."""
def __init__(self, argv0):
bin_dir = os.path.dirname(os.path.abspath(argv0)) # ~/git/oil/bin
self.root_dir = os.path.join(bin_dir, '..') # ~/git/oil/osh
def __init__(self, root_dir):
self.root_dir = root_dir
# TODO: Make this a context manager?
def open(self, rel_path):
@@ -220,8 +219,15 @@ def GetResourceLoader():
ovm_path = os.getenv('_OVM_PATH')
#log('! OVM_PATH = %s', ovm_path)
_loader = _ZipResourceLoader(ovm_path)
elif os.getenv('_OVM_RESOURCE_ROOT'): # Unit tests set this
root_dir = os.getenv('_OVM_RESOURCE_ROOT')
_loader = _FileResourceLoader(root_dir)
else:
_loader = _FileResourceLoader(sys.argv[0])
# NOTE: This assumes all unit tests are one directory deep, e.g.
# core/util_test.py.
bin_dir = os.path.dirname(os.path.abspath(sys.argv[0])) # ~/git/oil/bin
root_dir = os.path.join(bin_dir, '..') # ~/git/oil/osh
_loader = _FileResourceLoader(root_dir)
return _loader
@@ -6,7 +6,8 @@
import unittest
from compiler2 import pyassem # module under test
# TODO: This import breaks unit test discovery.
#from compiler2 import pyassem # module under test
class PyAssemTest(unittest.TestCase):
@@ -18,6 +19,7 @@ def tearDown(self):
pass
def testFoo(self):
return
g = pyassem.FlowGraph()
print(g)
@@ -10,8 +10,6 @@
from . import symbols
from . import transformer
from .transformer import parseFile
from .visitor import walk
def list_eq(l1, l2):
@@ -36,7 +34,7 @@ def get_names(syms):
tree = parseFile(file)
s = symbols.SymbolVisitor()
walk(tree, s)
s.Dispatch(tree)
# compare module-level symbols
names2 = s.scopes[tree].get_names()
View
@@ -74,6 +74,24 @@ all() {
echo "All unit tests passed."
}
# Run all unit tests in one process.
all-in-one() {
# -s: start dir -t: top level are defaults
# NOTE: without the pattern, it finds byterun unit tests called 'test*'.
_OVM_RESOURCE_ROOT=$PWD python -m unittest discover \
--failfast --verbose --pattern '*_test.py'
# This style fails due to the arguments being filenames and not Python module
# names.
#tests-to-run | xargs python -m unittest
}
# NOTE: Show options like this:
# python -m unittest discover -h
#
# For _release/VERSION
#

0 comments on commit dbb5580

Please sign in to comment.