Skip to content

Commit

Permalink
integration tests add network_tests kwarg
Browse files Browse the repository at this point in the history
the current listing of tests that hit the network may be overly
conservative, supporting exact commands + args will be more involved
  • Loading branch information
tgbugs committed Feb 19, 2020
1 parent 9adaebc commit a66b4ba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pyontutils/googapis.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def auth(self):

def main():
from docopt import docopt, parse_defaults
args = docopt(__doc__, version='clifun-demo 0.0.0')
args = docopt(__doc__, version='googapis 0.0.0')
defaults = {o.name:o.value if o.argcount else None for o in parse_defaults(__doc__)}
options = Options(args, defaults)
main = Main(options)
Expand Down
28 changes: 20 additions & 8 deletions pyontutils/integration_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
import sys
import unittest
import subprocess
from pathlib import Path
from importlib import import_module
import git
import pytest
from pathlib import Path
#from augpathlib import AugmentedPath as Path
from git import Repo as baseRepo
from pyontutils.utils import TermColors as tc
from pyontutils.config import devconfig


SKIP_NETWORK = ('SKIP_NETWORK' in os.environ or
'FEATURES' in os.environ and 'network-sandbox' in os.environ['FEATURES'])
skipif_no_net = pytest.mark.skipif(SKIP_NETWORK, reason='Skipping due to network requirement')


def simpleskipif(skip):
def inner(function):
if skip:
Expand Down Expand Up @@ -143,7 +149,6 @@ def notest_tests(self):

assert not failed, '\n'.join('\n'.join(str(e) for e in f) for f in failed)


@classmethod
def make_test_file(cls, i_ind, ppath, post_load, module_parent, skip):
print('PPATH: ', ppath)
Expand All @@ -152,8 +157,8 @@ def make_test_file(cls, i_ind, ppath, post_load, module_parent, skip):
stem = ppath.stem
#rp = ppath.relative_to(Path.cwd())#module_parent)
rp = ppath.relative_to(module_parent)
#rp = ppath.relative_path_from(Path(module_parent))
module_path = (rp.parent / rp.stem).as_posix().replace('/', '.')
print(module_path)
def test_file(self, module_path=module_path, stem=stem, fname=fname):
try:
print(tc.ltyellow('IMPORTING:'), module_path)
Expand Down Expand Up @@ -221,7 +226,7 @@ def test_main(self, module_path=module_path, argv=argv, main=main, test=test):
return test_main

@classmethod
def populate_from_paths(cls, paths, mains, tests, do_mains, post_load, post_main, module_parent, skip):
def populate_from_paths(cls, paths, mains, tests, do_mains, post_load, post_main, module_parent, skip, network_tests):
npaths = len(paths)
print(npaths)
for i_ind, path in enumerate(paths):
Expand All @@ -245,6 +250,9 @@ def populate_from_paths(cls, paths, mains, tests, do_mains, post_load, post_main
test_main = cls.make_test_main(do_mains, post_main, module_path, argv,
stem in mains, stem in tests, skip)

if stem in network_tests:
skipif_no_net(test_main)

# FIXME do we need to setattr these test_files or no?
if stem in skip:
test_file = pytest.mark.skip()(test_main)
Expand All @@ -255,7 +263,8 @@ def populate_from_paths(cls, paths, mains, tests, do_mains, post_load, post_main

@classmethod
def populate_tests(cls, module_to_test, working_dir, mains=tuple(), tests=tuple(),
lasts=tuple(), skip=tuple(), ci_skip=tuple(), only=tuple(), do_mains=True,
lasts=tuple(), skip=tuple(), ci_skip=tuple(), network_tests=tuple(),
only=tuple(), do_mains=True,
post_load=lambda : None, post_main=lambda : None, module_parent=None):

if module_parent is None:
Expand All @@ -267,7 +276,9 @@ def populate_tests(cls, module_to_test, working_dir, mains=tuple(), tests=tuple(
if isinstance(module_parent, Path):
module_parent = module_parent.as_posix()

relpath = Path(module_parent).relative_to(Path(working_dir)).as_posix()
p_wd = Path(working_dir)
p_mp = Path(module_parent)
relpath = p_mp.relative_to(p_wd).as_posix()
if relpath == '.':
relpath = ''
else:
Expand Down Expand Up @@ -311,8 +322,8 @@ def populate_tests(cls, module_to_test, working_dir, mains=tuple(), tests=tuple(
modinfos = list(pkgutil.iter_modules(module_to_test.__path__))
ppaths = [modinfo_to_path(m) for m in modinfos]

cls.populate_from_paths(ppaths, mains, tests,
do_mains, post_load, post_main, module_parent, skip)
cls.populate_from_paths(ppaths, mains, tests, do_mains, post_load, post_main,
module_parent, skip, network_tests)

if not hasattr(cls, 'argv_orig'):
cls.argv_orig = sys.argv
Expand All @@ -330,6 +341,7 @@ def test_cli(self): # note this will run itself in all cases, but that is ok
env=os.environ.copy(),
stderr=subprocess.STDOUT).decode().rstrip()
except BaseException as e:
raise e
failed.append((command, e, e.stdout if hasattr(e, 'stdout') else '', ''))

msg = '\n'.join('\n'.join(str(e) for e in f) for f in failed)
Expand Down
26 changes: 21 additions & 5 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ class TestScripts(Folders, _TestScriptsBase):
only = tuple()
skip = tuple()
ci_skip = tuple()
network_tests = (
'closed_namespaces',
'combinators', # shouldn't matter
'hierarchies',
'make_catalog',
'necromancy',
'ontutils',
'qnamefix',
'scig',
'scigraph_codegen',
)
#requests.exceptions.SSLError

if auth.get_path('scigraph-services') is None:
skip += ('scigraph_deploy',) # this will fail # FIXME this should really only skip main not both main and import?
Expand All @@ -44,7 +56,10 @@ class TestScripts(Folders, _TestScriptsBase):
# I'm pretty the split was only implemented because I was trying
# to run all tests from the working_dir in one shot, but that has
# a number of problems with references to local vs installed packages
working_dir = Path(__file__).parent.parent
import inspect
sf = inspect.getsourcefile(pyontutils)
working_dir = Path(sf).parent.parent
#working_dir = Path(__file__).parent.parent

glb = auth.get_path('git-local-base')
olr = auth.get_path('ontology-local-repo')
Expand All @@ -56,7 +71,7 @@ class TestScripts(Folders, _TestScriptsBase):
else:
post_load = lambda : None
post_main = lambda : None
do_mains = False
do_mains = True

### build mains

Expand All @@ -68,10 +83,10 @@ class TestScripts(Folders, _TestScriptsBase):
mains = {'scigraph':None,
'combinators':None,
'hierarchies':None,
'closed_namespaces':None,
'googapis': None,
'closed_namespaces':None,
#'docs':['ont-docs'], # can't seem to get this to work correctly on travis so leaving it out for now
'make_catalog':['ont-catalog', '--jobs', '1'],
'make_catalog':['ont-catalog', '--jobs', '1'], # hits the network
'graphml_to_ttl':['graphml-to-ttl', 'development/methods/methods_isa.graphml'],
#['ilxcli', '--help'],
'obo_io':['obo-io', '--ttl', nsmethodsobo],
Expand Down Expand Up @@ -122,6 +137,7 @@ class TestScripts(Folders, _TestScriptsBase):
mains['mapnlxilx'] = None # requires db connection

print(skip)
TestScripts.populate_tests(pyontutils, working_dir, mains, skip=skip,
TestScripts.populate_tests(pyontutils, working_dir, mains,
skip=skip, network_tests=network_tests,
post_load=post_load, post_main=post_main,
only=only, do_mains=do_mains)

0 comments on commit a66b4ba

Please sign in to comment.