示例#1
0
def bscr_test(args):
    """test - run tests

    usage: bscr test [-t py.test|green|nosetests|unittest] [-n] [-d]

    Without -t, we use the first available of py.test, green, nosetests, or
    unittest. With -t, we attempt to run the tests with the specified test
    runner.

    The tests are optimized for py.test. They may not work well under green
    or nose.
    """
    c = U.cmdline([{'opts': ['--dry-run', '-n'],
                    'action': 'store_true',
                    'help': 'see what would happen'},
                   {'name': 'tester',
                    'help': 'select a test runner'}])
    (o, a) = c.parse(args)

    with util.Chdir(util.dirname(__file__)):
        target = util.pj(os.path.dirname(__file__), 'test')
        print("Running tests in %s" % target)
        if o.tester == '':
            if which('py.test'):
                util.run('py.test %s' % target, not o.dryrun)
            elif which('green'):
                util.run('green -v %s' % target, not o.dryrun)
            elif which('nosetests') and importable('nose_ignoredoc'):
                tl = glob.glob(util.pj(target, 'test_*.py'))
                util.run('nosetests -v -c nose.cfg %s' % " ".join(tl),
                         not o.dryrun)
            else:
                tl = glob.glob(util.pj(target, 'test_*.py'))
                for t in tl:
                    util.run("%s -v" % t, not o.dryrun)
                    # p = subp.Popen([t, '-v'])
                    # p.wait()
        elif o.tester == 'py.test':
            util.run('py.test %s' % target, not o.dryrun)
        elif o.tester == 'green':
            util.run('green -v %s' % target, not o.dryrun)
        elif o.tester == 'nose':
            tl = glob.glob(util.pj(target, 'test_*.py'))
            util.run('nosetests -v -c nose.cfg %s' % " ".join(tl),
                     not o.dryrun)
        elif o.tester == 'unittest':
            tl = glob.glob(util.pj(target, 'test_*.py'))
            for t in tl:
                util.run("%s -v" % t, not o.dryrun)
        else:
            raise SystemExit("unrecognized tester: '%s'" % o.tester)
示例#2
0
def bscr_uninstall(args):
    """uninstall - remove bscr from your system

    If you installed with pip, you can also uninstall with pip:

        pip uninstall bscr

    However, if you used easy_install, or if you just downloaded the tarball
    and ran 'python setup.py install', uninstalling can be a pain. bscr
    provides an easier way:

        bscr uninstall

    will remove bscr from your system.
    """
    bscrpkg = os.path.dirname(__file__)
    sitepkg = os.path.dirname(bscrpkg)
    if os.path.isdir(util.pj(sitepkg, '.git')):
        print("Cowardly refusing to uninstall from a .git repo")
    else:
        eggl = glob.glob(util.pj(sitepkg, 'backscratcher*egg*'))
        egg = eggl[0]
        iflist = util.contents(util.pj(egg, 'installed-files.txt'))
        print("Preparing to uninstall:")
        with util.Chdir(egg):
            afpl = [os.path.abspath(rfp.strip()) for rfp in iflist]
        for afp in afpl:
            print("   " + afp)
        print("   rmdir " + bscrpkg)
        answer = raw_input("Proceed? > ")
        if re.match("yes", answer):
            for afp in afpl:
                if os.path.isdir(afp):
                    shutil.rmtree(afp)
                elif os.path.exists(afp):
                    os.unlink(afp)
            shutil.rmtree(bscrpkg)

    return None
示例#3
0
def perl_which(module_name):
    """
    Look for and return the path of the perl module
    """
    # pdb.set_trace()
    rval = ""
    result = pexpect.run("perl -E \"say for @INC\"")
    rlines = result.strip().split("\r\n")
    perlmod = module_name.replace("::", "/") + ".pm"
    # print("-----")
    for line in rlines:
        cpath = U.pj(line, perlmod)
        # print cpath
        if U.exists("%s" % cpath):
            rval += cpath + "\n"
    return rval.strip()
示例#4
0
def perl_which(module_name):
    """
    Look for and return the path of the perl module
    """
    # pdb.set_trace()
    rval = ""
    result = th.rm_cov_warn(pexpect.run("perl -E \"say for @INC\""))
    z = result.strip().split("\r\n")
    m = module_name.replace("::", "/") + ".pm"
    # print("-----")
    for x in z:
        cpath = U.pj(x, m)
        # print cpath
        if U.exists("%s" % cpath):
            rval += cpath + "\n"
    return rval.strip()
示例#5
0
def python_which(module_name):
    """
    Look up *module_name* in sys.path and return it if found
    """
    rval = ''
    mname = module_name.replace('.', '/')
    for path in sys.path:
        dname = U.pj(path, mname)
        pname = dname + ".py"
        cname = dname + ".pyc"
        if U.exists(dname):
            rval = dname
            break
        elif U.exists(cname):
            rval = cname
            break
        elif U.exists(pname):
            rval = pname
            break
    return rval