def attemptFile(*fls):
    return all(fls) and filebaseConsumer(*fls)

def errorOut():
    sys.stderr.write('''Assessment Error:  Must specify an assessor source in order to assess prospects.
Try using: cmdassess.py -d <hostname or IP>...
   Or try: cmdassess.py -p <preassessor path> -o <postassessor path>\n''')
    return None

def chooseAssessorSource(db, *files):
    return attemptDB(db) or attemptFile(*files) or errorOut()

def main(inputFile, preAssessorPath, postAssessorPath, assessorDBhost, runTests, showHelp):
    if runTests:
        return 0 if all(map(apply, testModule())) else 1
    if showHelp:
        sys.stdout.write('''Assess a Command
Usage: cmdassess.py [-f <file>] [-t] [-h]\n''')
        return 0
    return _do_main(showResults, 
                    chooseAssessorSource(assessorDBhost, 
                                         preAssessorPath, 
                                         postAssessorPath),
                    inputFile)

if __name__=="__main__":
    ahoy(main, "showHelp", "runTests",
         f="inputFile", t="runTests",
         p="preAssessorPath", o="postAssessorPath",
         d="assessorDBhost")
            test_00_tablify, 
            test_00_alignKeys,
            test_00_render]

def subst(subj, **attribs):
    def _rplc(accum, pair):
        def _go(oldy, newy):
            return accum.replace("{:%s:}"%(oldy), "%s"%(newy))
        return _go(*pair)
    return reduce(_rplc, attribs.items(), subj)

def cleanArty(artifice):
    def _conv():
        def ci(p):
            return map(lambda x: subst(x, **artifice), p)
        return dict(map(ci, artifice.items()))
    def _cmp(nuu):
        return nuu if nuu==artifice else cleanArty(nuu)
    return _cmp(_conv())

def runTests(): # rig:3
    return 0 if all(map(apply, testModule())) else 1

def main(*wanted): 
    if "runTest" in wanted or "--t" in wanted:
        return runTests()
    return sum(consume_stdin(partial(rndrObs, wanted)))

if __name__=="__main__":
    ahoy(main)
        def loadModule(modname):
            return load(__import__( modname )) 
        return loadModule( path.splitext(moduleName)[0] )
    def runDiagnostics(targetDir="./"):
        def modules():
            return [x for x in listdir(targetDir) if x.endswith(".py") and x.count(".")==1]
        def valid(expression, otherwiseMsg):
            return expression() or bad(otherwiseMsg) 
        def testModules(moduleNames):
            return all(map(loadAndTestModule, moduleNames))
        return testModules([x for x in modules() if "__" not in x])
    def conclude(results):
        return 0 if results else rprt("\nFAILURES!\n\n") and 1
    def decideAction(tpth):
        if path.isfile(tpth):
            return loadAndTestModule(tpth)
        if path.isdir(tpth):
            return runDiagnostics(tpth)
        return bad("Unknown test path: %s"%(testPath))
    return conclude(decideAction(testPath or "./"))

def testModule():
    def test_00_test():
        def tstIter(x):
            return test(lambda x: x, x, x)
        return all(map(tstIter, list("aoeu!@#$%^&*(){}[]_-/=+?")+range(10)+[True, False, None, [], (), {}] ))
    return [test_00_test]

if __name__=="__main__":
    ahoy(main, "verbose")
    err("-q" not in argv, "No valid Assessor Data to write.\n", assessorData)
    return None


def insertAssessorsFromFile(host, lineFetcher, sourceFile, port=27017):
    return map(partial(insertAssessorIntoDB, _connectDB(host, port)), lineFetcher(sourceFile.read()))


def shew(chunks):  # rig:3
    for x in chunks:
        out(x, x)
    return 0


def testModule():
    return [partial(out, True, "No tests for this module yet.")]


def main(host, isPostAssessor, port):
    if not host:
        return err(True, "Must specify database host.\n") and 1

    def fetcher():
        return isPostAssessor and buildPostAssessors or buildPreAssessors

    return shew(insertAssessorsFromFile(host, fetcher(), stdin, port or 27017))


if __name__ == "__main__":
    ahoy(main, "isPostAssessor", o="isPostAssessor", d="host", h="host", p="port")
Esempio n. 5
0
    return pipeline(checkForTestingData(), 
                    readBytes,
		    str.strip,
                    genReporter,
                    reportToDb,
                    show)

@reportyFunc
def skipTestDueToLackOfPymongo(): # rig:3
    print "\n\tWARNING: The Mongo module was not found.  Database "
    print "\treporting  tests  will be  skipped.  Install pymongo "
    print "\tmodules in  order to get  accurate tests on database "
    print "\treporting."
    return True

def testModule():
    try:
        __import__("pymongo")
    except ImportError:
        return [skipTestDueToLackOfPymongo]
    return [testDatabase]

def runTests(): # rig:3
    return 0 if all(map(apply, testModule())) else 1

def main(dbhost, runtest):
    return runTests() if runtest else consumeStdinAndExit(dbhost)

if __name__=="__main__":
    ahoy(main, "runtest", t="runtest", h="dbhost")
Esempio n. 6
0
def cudgelObs(command, stdout="", retCode=0, stderr="", **etc):
    def determineScrutinizer():
        if stdout:
            return "| grep '%s'"%(cmdSanitize(stdout))
        if stderr:
            return "2>&1 | grep '%s'"%(cmdSanitize(stderr))
        if retCode!=0:
            return "; echo $? | grep %s"%(retCode)
        return "&& echo 'OK'"
    def renderCud():
        return "%s %s || (echo 'Failure')"%(command,
                                            determineScrutinizer())
    return showCudg(renderCud())

def obsp(o):
    return o.get("artificeBreed")=="observation"

def handleObs(observations):
    return [cudgelObs(**o) for o in observations if obsp(o)]

def cudgelize(observations):
    return 0 if all(handleObs(observations)) else 1

def main(runTests, inputSource):
    return runTests and performTests() or cudgelize(
        observationsFrom(inputSource or sys.stdin))

if __name__=="__main__":
    ahoy(main, "runTests", t="runTests", f="inputSource")