Example #1
0
def which_python(lazy=False, fullpath=True):
    "get an invocation for this python on the execution path"
    from pox import which_python
    # check if the versioned python is on the path
    py = which_python(lazy=False, version=True, fullpath=True)
    if not lazy and fullpath and py: return py
    import sys
    if (sys.platform[:3] == 'win'): lazy = False
    # if on the path, apply user's options
    return which_python(lazy=lazy, version=bool(py), fullpath=fullpath)
Example #2
0
def which_python(lazy=False, fullpath=True):
    "get an invocation for this python on the execution path"
    from pox import which_python
    # check if the versioned python is on the path
    py = which_python(lazy=False, version=True, fullpath=True)
    if not lazy and fullpath and py: return py
    import sys
    if (sys.platform[:3] == 'win'): lazy=False
    # if on the path, apply user's options
    return which_python(lazy=lazy, version=bool(py), fullpath=fullpath)
Example #3
0
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2018 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

from __future__ import print_function
import glob
import os
try:
    import pox
    python = pox.which_python(version=True, fullpath=False) or 'python'
except ImportError:
    python = 'python'

suite = os.path.dirname(__file__) or os.path.curdir
tests = glob.glob(suite + os.path.sep + 'test_*.py')

if __name__ == '__main__':

    for test in tests:
        print('.', end='')
        os.system('{0} {1}'.format(python, test))
    print('')
Example #4
0
def test_shutils():
    '''script to test all shutils functions'''
    from pox import shelltype, homedir, rootdir, sep, mkdir, walk, where, env, \
                    username, minpath, which, which_python, find, shellsub, \
                    expandvars, __version__ as version

    #print('testing shelltype...')
    shell = shelltype()
    try:
        assert shell in [
            'bash', 'sh', 'csh', 'zsh', 'tcsh', 'ksh', 'rc', 'es', 'cmd'
        ]
    except AssertionError:
        if shell:
            print("Warning: non-standard shell type")
            assert isinstance(shell, str)
        else:
            print("Warning: could not determine shell type")
            assert shell is None

#print('testing username...')
#print(username())

#print('testing homedir...')
#print(homedir())
    assert homedir().rstrip(sep()).endswith(username())

    #print('testing rootdir...')
    #print(rootdir())
    assert homedir().startswith(rootdir())

    #print('testing sep...')
    #print(sep())
    #print(sep('ext'))
    #   print(sep('foo'))

    #print('testing mkdir...')
    newdir = sep().join(['xxxtest', 'testxxx'])
    assert mkdir(newdir).rstrip(sep()).endswith(newdir)
    #print('cleaning up...')
    os.removedirs(newdir)

    #print('testing walk...')
    #print(walk('/usr/local','*',recurse=False,folders=True,files=False))
    folders = walk(rootdir(), '*', recurse=False, folders=True, files=False)
    assert len(folders) > 0
    ### assert all(not os.path.isfile(folder) for folder in folders)
    home = walk(homedir() + sep() + os.pardir, username(), False, True)[0]
    assert home == homedir()

    #print('testing where...')
    shells = walk(home, '.bashrc', recurse=0)
    bashrc = where('.bashrc', home)
    if bashrc:
        assert bashrc in shells
    else:
        assert not shells

#print(bashrc)

#print('testing minpath...')
#print(minpath(os.path.expandvars('$PATH')))
    path = expandvars('$PATH')
    assert minpath(path).count(sep('path')) <= path.count(sep('path'))

    #print('testing env...')
    assert env('ACSDAGHQSBFCASDCOMAOCMQOMCQWMOCQOMCOMQRCVOMQOCMQORMCQ') == {}
    if 'HOME' not in os.environ:
        os.environ['HOME'] = homedir()
    assert env('HOME', all=False) or env('USERPROFILE', all=False) == homedir()
    pathdict = env('*PATH*', minimal=True)
    assert len(pathdict) > 0
    assert all('PATH' in key for key in pathdict)

    #print('testing which...')
    assert which('python').endswith(('python', 'python.exe'))
    assert which('python') in which('python', all=True)

    #print('testing find...')
    #print(find('python','/usr/local',type='l'))
    #print(find('*py;*txt'))
    x = os.path.dirname(__file__)
    if not x:  # this file is not found
        x = which('pox;pox_launcher.py')
        if x:  # if executable found, then navigate to the test directory
            p = which_python(fullpath=False, version=True)
            x = os.sep.join((x.rsplit(os.sep, 2)[0], 'lib', p))
            x = [
                p for p in find('test_shutils.py', x, True, 'f')
                if version in p
            ]
            x = x[0] if x else ''
    if x:
        assert set(find('__init__*;__main__*;test_*', x, False,
                        'f')) == set(find('*py;*pyc', x, recurse=False))

    #print('testing shellsub...')
    command = '${HOME}/bin/which foo("bar")'
    #print(repr(command))
    #print(repr(shellsub(command)))
    assert shellsub(command) == '\\${HOME}/bin/which foo\\(\\"bar\\"\\)'

    return
Example #5
0
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2018-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/multiprocess/blob/master/LICENSE

from __future__ import print_function
import glob
import os
try:
    import pox
    python = pox.which_python(version=True, fullpath=False) or 'python'
except ImportError:
    python = 'python'

suite = os.path.dirname(__file__) or os.path.curdir
tests = glob.glob(suite + os.path.sep + 'test_*.py')
tests = glob.glob(suite + os.path.sep + '__init__.py') + \
        [i for i in tests if 'main' not in i]


if __name__ == '__main__':

    for test in tests:
        print('.', end='')
        os.system('{0} {1}'.format(python, test))
    print('')

Example #6
0
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2018 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/ppft/blob/master/LICENSE

from __future__ import print_function
import glob
import os
try:
    import pox
    python = pox.which_python(fullpath=False) or 'python'
except ImportError:
    python = 'python'

suite = os.path.dirname(__file__) or os.path.curdir
tests = glob.glob(suite + os.path.sep + '*.py')
tests = [f for f in tests if not os.path.basename(f).startswith('__')]


if __name__ == '__main__':

    for test in tests:
        print('.', end='')
        os.system('{0} {1}'.format(python, test))
    print('')

Example #7
0
#!/usr/bin/env python
#
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
# Copyright (c) 2018-2022 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/ppft/blob/master/LICENSE

from __future__ import print_function
import glob
import os
try:
    import pox
    python = pox.which_python(fullpath=False)
    if not python:
        python = 'python'
    elif not pox.which(python):
        python = pox.which_python(fullpath=False, version=True)
except ImportError:
    python = 'python'
import subprocess as sp
from sys import platform
shell = platform[:3] == 'win'

suite = os.path.dirname(__file__) or os.path.curdir
tests = glob.glob(suite + os.path.sep + '*.py')
tests = [f for f in tests if not os.path.basename(f).startswith('__')]


if __name__ == '__main__':

    for test in tests: