def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)), 'epyunit', slst) epyu = findRelPathInSearchPath('bin/epyunit', slst, matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh', slst, matchidx=0) _call = epyu _call += " " + scri _call += " OK " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call, **callkargs) assert ret == [ 0, [ 'fromA', 'arbitrary output', 'arbitrary signalling OK string', 'arbitrary output' ], [], ] pass
def setUpClass(cls): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) cls.epyu = findRelPathInSearchPath('bin/epyunit',slst,matchidx=0) cls.scri = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) cls.cache = True
def setUpClass(self): syskargs = {} self.sx = epyunit.SystemCalls.SystemCalls(**syskargs) pycall = findRelPathInSearchPath('python', os.environ.get('PATH')) if not pycall: pycall = findRelPathInSearchPath('python.exe', os.environ.get('PATH')) if not pycall: raise Exception("Cannot find Python")
def testCase010(self): """The mdofied output by the option:: --exitign=True original default output for case EXIT9OK3NOK2:: EXIT: 0 STDOUT: fromH OK OK OK STDERR: NOK NOK """ slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)), 'epyunit', slst) epyu = findRelPathInSearchPath('bin/epyunit', slst, matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh', slst, matchidx=0) _call = epyu # _call += " --rdbg=127.0.0.1:5678 " _call += " --rdbg " # _call += " --pass " # _call += " --passall " # _call += " --exitign=True " _call += " -- " _call += scri _call += " EXIT9OK3NOK2 " syskargs = {} # # make a simple system call, the actual unittest is processed within the subprocess # sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call, **callkargs) assert ret == [1, ['fromH', 'OK', 'OK', 'OK'], ['NOK', 'NOK']] pass
def _matchsub(_apat,_rfs): # almost literal p = findRelPathInSearchPath(_apat,_rfs) if p: # a match trial return p # plugins p = findRelPathInSearchPath("plugins"+os.path.sep+_apat,_rfs) if p: # a match trial return p # dropins p = findRelPathInSearchPath("dropins"+os.path.sep+"*"+os.path.sep+"plugins"+os.path.sep+_apat,_rfs) if p: # a match trial return p
def testCase010(self): """The mdofied output by the option:: --exitign=True original default output for case EXIT9OK3NOK2:: EXIT: 0 STDOUT: fromH OK OK OK STDERR: NOK NOK """ slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) epyu = findRelPathInSearchPath('bin/epyunit',slst,matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) _call = epyu # _call += " --rdbg=127.0.0.1:5678 " _call += " --rdbg " # _call += " --pass " # _call += " --passall " # _call += " --exitign=True " _call += " -- " _call += scri _call += " EXIT9OK3NOK2 " syskargs = {} # # make a simple system call, the actual unittest is processed within the subprocess # sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call,**callkargs) assert ret == [1, ['fromH', 'OK', 'OK', 'OK'], ['NOK', 'NOK']] pass
def testCall_sys_path(self): fx = findRelPathInSearchPath(self.rdbgsub, self.eclipsepath + os.sep + 'plugins') sys.path.insert(0, fx) _call = epyu _call += ' --passall ' _call += ' --rdbg ' # _call += ' --rdbg-root='+ self.eclipsepath # _call += ' --rdbg-sub='+ self.rdbgsub _call += ' --rdbg-root=' + self.eclipsepath + 'notvalid' _call += ' --rdbg-sub=' + self.rdbgsub + 'notvalid' _call += ' ' + call_scripy _cl = _call.split() ret = epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions(_cl) retX = ( True, 'localhost:5678', 0, self.eclipsepath + 'notvalid', self.rdbgsub + 'notvalid', ) self.assertEqual(ret, retX) sx = epyunit.debug.checkRDbg.scanEclipseForPydevd( **{ 'altpat': self.rdbgsub, }) assert os.path.basename(sx) == 'pydevd.py' pass
def testCall_sys_path(self): fx = findRelPathInSearchPath(self.rdbgsub,self.eclipsepath+os.sep+'plugins') sys.path.insert(0,fx) _call = epyu _call += ' --passall ' _call += ' --rdbg ' # _call += ' --rdbg-root='+ self.eclipsepath # _call += ' --rdbg-sub='+ self.rdbgsub _call += ' --rdbg-root='+ self.eclipsepath + 'notvalid' _call += ' --rdbg-sub='+ self.rdbgsub + 'notvalid' _call += ' ' + call_scripy _cl = _call.split() ret = epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions(_cl) retX = ( True, 'localhost:5678', 0, self.eclipsepath + 'notvalid', self.rdbgsub + 'notvalid', ) self.assertEqual(ret, retX) sx = epyunit.debug.checkRDbg.scanEclipseForPydevd(**{'altpat':self.rdbgsub,}) assert os.path.basename(sx) == 'pydevd.py' pass
def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)), 'epyunit', slst) myscript = findRelPathInSearchPath('epyunit/myscript.sh', slst, matchidx=0) sx = epyunit.SystemCalls.SystemCalls() # _env = os.environ.copy() # _env['PATH'] = os.pathsep.join(sys.path) ret = sx.callit(myscript + " EXIT8") assert ret[0] == 8 assert ret[1] == [ "fromG", 'arbitrary output', 'arbitrary signalling NOK string', 'arbitrary output' ] assert ret[2] == [ 'arbitrary err output', 'arbitrary err signalling NOK string', 'arbitrary err output' ] pass
def _matchsub(_apat, _rfs): # almost literal p = findRelPathInSearchPath(_apat, _rfs) if p: # a match trial return p # plugins p = findRelPathInSearchPath("plugins" + os.path.sep + _apat, _rfs) if p: # a match trial return p # dropins p = findRelPathInSearchPath( "dropins" + os.path.sep + "*" + os.path.sep + "plugins" + os.path.sep + _apat, _rfs) if p: # a match trial return p
def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) epyu = findRelPathInSearchPath('bin/epyunit',slst,matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) _call = epyu _call += " --priotype=False " + scri _call += " EXIT9OK3NOK2 " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call,**callkargs) assert ret == [1, ['fromH', 'OK', 'OK', 'OK'], ['NOK', 'NOK']] pass
def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)), 'epyunit', slst) epyu = findRelPathInSearchPath('bin/epyunit', slst, matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh', slst, matchidx=0) _call = epyu _call += " --priotype=False " + scri _call += " EXIT9OK3NOK2 " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call, **callkargs) assert ret == [1, ['fromH', 'OK', 'OK', 'OK'], ['NOK', 'NOK']] pass
def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) epyu = findRelPathInSearchPath('bin/epyunit',slst,matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) _call = epyu _call += " " + scri _call += " OK " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call,**callkargs) assert ret == [0, ['fromA', 'arbitrary output', 'arbitrary signalling OK string', 'arbitrary output' ], [],] pass
def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) myscript = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) sx = epyunit.SystemCalls.SystemCalls() # _env = os.environ.copy() # _env['PATH'] = os.pathsep.join(sys.path) ret = sx.callit(myscript+" EXIT9OK3NOK2") assert ret[0] == 9 assert ret[1] == ['fromH', 'OK', 'OK', 'OK'] assert ret[2] == ['NOK', 'NOK', ] pass
def testCase000(self): slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) myscript = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) sx = epyunit.SystemCalls.SystemCalls() # _env = os.environ.copy() # _env['PATH'] = os.pathsep.join(sys.path) ret = sx.callit(myscript+" PRIO") assert ret[0] == 0 assert ret[1] == ["fromC", 'arbitrary output', 'arbitrary signalling OK string', 'arbitrary output'] assert ret[2] == ['arbitrary signalling ERROR string'] pass
def testCall_cli(self): fx = findRelPathInSearchPath(self.rdbgsub,self.eclipsepath+os.sep+'plugins') sys.path.insert(0,fx) _call = epyu _call += ' --passall ' _call += ' --rdbg ' _call += ' --rdbg-root='+ self.eclipsepath + 'notvalid' _call += ' --rdbg-sub='+ self.rdbgsub + 'notvalid' _call += ' ' + call_scripy _cl = _call.split() ret = epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions(_cl) retX = ( True, 'localhost:5678', 0, self.eclipsepath + 'notvalid', self.rdbgsub + 'notvalid', ) self.assertEqual(ret, retX) pass
def testCall_cli(self): fx = findRelPathInSearchPath(self.rdbgsub, self.eclipsepath + os.sep + 'plugins') sys.path.insert(0, fx) _call = epyu _call += ' --passall ' _call += ' --rdbg ' _call += ' --rdbg-root=' + self.eclipsepath + 'notvalid' _call += ' --rdbg-sub=' + self.rdbgsub + 'notvalid' _call += ' ' + call_scripy _cl = _call.split() ret = epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions(_cl) retX = ( True, 'localhost:5678', 0, self.eclipsepath + 'notvalid', self.rdbgsub + 'notvalid', ) self.assertEqual(ret, retX) pass
__docformat__ = "restructuredtext en" import unittest import os,sys from filesysobjects.FileSysObjects import setUpperTreeSearchPath,findRelPathInSearchPath import epyunit.SystemCalls # ####################### # slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) epyu = findRelPathInSearchPath('bin/epyunit',slst,matchidx=0) class CallUnits(unittest.TestCase): def testCase010(self): """Simple call, providing a return value only. """ _call = epyu + " --selftest " #_call += " --rdbg " #_call += " --rdbg-forward all " #_call += " --pderd_debug_self " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {}
__docformat__ = "restructuredtext en" import unittest import os,sys from filesysobjects.FileSysObjects import setUpperTreeSearchPath,findRelPathInSearchPath import epyunit.SystemCalls # ####################### # slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)),'epyunit',slst) epyu = findRelPathInSearchPath('bin/epyunit',slst,matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh',slst,matchidx=0) class CallUnits(unittest.TestCase): def testCase010(self): _call = epyu + " --exittype=True " _call += scri + " OK " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call,**callkargs) retX = [0, ['fromA', 'arbitrary output', 'arbitrary signalling OK string', 'arbitrary output'],[]]
def _subcall_myscript(slang,**kargs): """Calls the operational checks provided by 'myscript' for language variant. Args: slang: Programming language of called script, current supported are: bash python **kargs: out: verbose: debug: Returns: None. Raises: In case of assertion errors. """ _out = kargs.get('out',None) _verbose = kargs.get('verbose',0) _debug = kargs.get('debug',0) if _verbose>0: kargs['verbose'] = _verbose if kargs.get('debug') > 0: kargs['debug'] = _debug # create a complete subprocess unit test controller with configuration data sx = SubprocessUnit() import epyunit #for path to mymodule.sh if slang.lower() in ('bash', 'sh', 'shell',): _sx = "myscript.sh" cx = epyunit.__path__[0]+os.sep+_sx if "win32" in sys.platform: p = os.environ.get('PATH') fp = findRelPathInSearchPath('bash.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bash.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bin/bash.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bin\\bash.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bash',p,subsplit=True) if not fp: raise Exception("Missing:bash") cx = fp + ' ' + cx else: if not findRelPathInSearchPath('bash',os.environ.get('PATH'),subsplit=True): raise Exception("Missing:bash") cx = ' bash ' + cx elif slang.lower() == 'python': _sx = "myscript.py" cx = epyunit.__path__[0]+os.sep+_sx if "win32" in sys.platform: p = os.environ.get('PATH') fp = findRelPathInSearchPath('python.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('python.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bin/python.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bin\\python.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('python',p,subsplit=True) if not fp: raise Exception("Missing:python") cx = fp + ' ' + cx else: if not findRelPathInSearchPath('python',os.environ['PATH'],subsplit=True): raise Exception("\nPATH="+str(os.environ['PATH'])+"\nMissing:python") cx = ' python ' + cx # + " --rdbg " elif slang.lower() == 'perl': _sx = "myscript.pl" cx = epyunit.__path__[0]+os.sep+_sx if "win32" in sys.platform: p = os.environ.get('PATH') fp = findRelPathInSearchPath('perl.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('perl.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bin/perl.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('bin\\perl.exe',p,subsplit=True) if not fp: fp = findRelPathInSearchPath('perl',p,subsplit=True) if not fp: raise Exception("Missing:perl") cx = fp + ' ' + cx else: if not findRelPathInSearchPath('perl',os.environ['PATH'],subsplit=True): raise Exception("Missing:perl") cx = ' perl ' + cx else: raise Exception("Unknown language type:"+str(slang)) # add rules to be applied ont the subprocesses _myRules = SProcUnitRules() # # perform the tests for defined filter # # #*** DEFAULT *** # _myParams = {'exitval':123,'stdoutok':["arbitrary output"],'stderrok':[],} _myrx = {'reset':True, 'exitign': False, 'exitval': 123, 'exittype':'VAL',} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose >1: print _myRules sx.setkargs(**{'rules':_myRules, 'env': os.environ}) ret = sx.callit(cx) if ret[0] == 126: print >>sys.stderr ,"check exec permissions of 'myscript.*'" if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" DEFAULT ***" if _verbose>1: sx.displayit(ret) retX = [123,["arbitrary output"],[]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** A-OK *** # _myParams = {'exitval':0,'stdoutok':["fromA", "arbitrary output","arbitrary signalling OK string","arbitrary output"],'stderrok':[],} _myrx = {'reset':True, 'exitign': False, 'exitval': 0, 'exittype':'OK', 'stdoutok_val':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules sx.setkargs(**{'rules':_myRules,}) ret = sx.callit(cx+' -- OK') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" OK ***" if _verbose>1: sx.displayit(ret) retX = [0,["fromA", "arbitrary output","arbitrary signalling OK string","arbitrary output"],[]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** C-OK *** # _myParams = {'exitval':0,'stdoutok':["fromC", "arbitrary output","arbitrary signalling OK string","arbitrary output"],'stderrok':[],} _myrx = {'reset':True, 'exitign': False, 'exittype':'OK','stdoutok':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules sx.setkargs(**{'rules':_myRules,}) ret = sx.callit(cx+' -- PRIO') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" PRIO ***" if _verbose>1: sx.displayit(ret) retX = [0,["fromC", "arbitrary output","arbitrary signalling OK string","arbitrary output"],["arbitrary signalling ERROR string"]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** D-OK *** # _myParams = {'exitval':0,'stdoutok':["fromD", "arbitrary output","arbitrary signalling OK string","arbitrary output"],'stderrok':[],} _myrx = {'reset':True, 'exitign': False, 'exittype':'OK','stdoutok':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules sx.setkargs(**{'rules':_myRules,}) ret = sx.callit(cx+' -- EXITOK') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" EXITOK ***" if _verbose>1: sx.displayit(ret) retX = [0,["fromD", "arbitrary output","arbitrary signalling OK string","arbitrary output"],[]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** E-NOK *** # _myParams = {'exitval':1,'stdoutok':["fromE", "arbitrary output","arbitrary signalling OK string","arbitrary output"],'stderrok':[],} _myrx = {'reset':True, 'multiline':True, 'exitign': False, 'exittype':'NOK','stdoutok':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules sx.setkargs(**{'rules':_myRules,}) ret = sx.callit(cx+' -- EXITNOK') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" EXITNOK ***" if _verbose>1: sx.displayit(ret) retX = [1,["fromE", "arbitrary output","arbitrary signalling OK string","arbitrary output"],[]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** F-NOK7 *** # _myParams = {'exitval':7,'stdoutok':["fromF", "arbitrary output","arbitrary signalling NOK string","arbitrary output"],'stderrok':[],} _myrx = {'reset':True, 'exitign': False, 'exittype':'VAL','exitval':7,'stdoutok':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules sx.setkargs(**{'rules':_myRules,}) ret = sx.callit(cx+' -- EXIT7') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" EXIT7 ***" if _verbose>1: sx.displayit(ret) retX = [7,["fromF", "arbitrary output","arbitrary signalling NOK string","arbitrary output"],[]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** G-NOK8 *** # _myParams = {'exitval':8,'stdoutok':["fromG", 'arbitrary output', 'arbitrary signalling NOK string', 'arbitrary output'],'stderrok': ['arbitrary err output', 'arbitrary err signalling NOK string', 'arbitrary err output'],} _myrx = {'reset':True, 'exitign': False, 'exittype':'VAL','exitval':8,'stdoutok':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules ret = sx.callit(cx+' -- EXIT8') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" EXIT8 ***" if _verbose>1: sx.displayit(ret) retX = [8,["fromG", 'arbitrary output', 'arbitrary signalling NOK string', 'arbitrary output'], ['arbitrary err output', 'arbitrary err signalling NOK string', 'arbitrary err output']] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #***H-NOK9 *** # _myParams = {'exitval':9,'stdoutok':["fromH", 'OK', 'OK', 'OK'],'stderrok': ['NOK', 'NOK',],} _myrx = {'reset':True, 'exitign': False, 'exittype':'VAL','exitval':9,'stdoutok':["NOK","NOK","NOK"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules ret = sx.callit(cx+' -- EXIT9OK3NOK2') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" EXIT9OK3NOK2 ***" if _verbose>1: sx.displayit(ret) retX = [9,["fromH", 'OK', 'OK', 'OK'], ['NOK', 'NOK']] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** I-OK0 *** # _myParams = {'exitval':0,'stdoutok':[],'stderrok': ['fromI', 'NOK', 'NOK'],} _myrx = {'reset':True, 'exitign': False, 'exittype':'VAL','exitval':0,'stdoutok':[]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules ret = sx.callit(cx+' -- STDERRONLY') if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" STDERRONLY ***" if _verbose>1: sx.displayit(ret) retX = [0,[], ['fromI', 'NOK', 'NOK']] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) # #*** DEFAULT-123 *** # _myParams = {'exitval':123,'stdoutok':["arbitrary output"],'stderrok': [],} _myrx = {'reset':True, 'exitign': False, 'exittype':'NOK','stdoutok':["arbitrary output","arbitrary signalling OK string","arbitrary output"]} _myRules.setrules(**_myrx) _myRules.setkargs(**_myParams) if _verbose>1: print _myRules ret = sx.callit(cx) if _out: if _verbose: print "\n#*** epyunit/"+str(_sx)+" DEFAULT ***" if _verbose>1: sx.displayit(ret) retX = [123,["arbitrary output"],[]] try: if ret[1]: ret[1] = map(lambda x: x.replace('\r',''),ret[1]) if ret[2]: ret[2] = map(lambda x: x.replace('\r',''),ret[2]) assert ret ==retX except: print >>sys.stderr, "" print >>sys.stderr, "retX="+str(retX) print >>sys.stderr, "ret= "+str(ret) assert sx.apply(ret) pass
def testCase000(self): _s = sys.path[:] import testdata s = os.sep # start of upward search - file is converted into it's containing directory node any_sub_path = os.path.normpath('examples/a/b0/c/a/b0/c/F') spath = testdata.mypath spath += s+ any_sub_path # check environment assert os.path.exists(spath) # store new search list, here without required sys.path _plist = [] # 0. build a search path list - if not yet available # adds each directory from spath to its matching # subnode "a/b" # setUpperTreeSearchPath(spath,os.path.normpath('a/b0'), _plist) # expected plist _plist_ref = [ os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c'), os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0'), os.path.normpath(testdata.mypath+'/examples/a/b0/c/a'), os.path.normpath(testdata.mypath+'/examples/a/b0/c'), os.path.normpath(testdata.mypath+'/examples/a/b0'), ] assert _plist_ref == _plist # 1. make it canonical - optional, here just a demo _chk_ref = _plist[:] _plist.extend(_plist[:]) # duplicate all for demonstration assert _plist != _chk_ref clearPath(_plist,**{'redundant':True,'shrink':True}) # and clear them immediately assert _plist == _chk_ref # 2. find the requested entry rel = "F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = "b0/F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/F') assert rp_ref == rp rel = "b0/c/F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = "b0/[c]/F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = "a/b0/[c]/F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = "a/b?/[c]/F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = "a/b*/[c]/F" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = "b0/*" rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c') assert rp_ref == rp rel = "b0"+os.path.sep+"F*" # bash specific rp = findRelPathInSearchPath(rel,_plist,**{'matchidx':1}) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/F') #FIXME: #assert rp_ref == rp rel = os.path.normpath("c/a/b0/*/F") rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = os.path.normpath("c/F") rp = findRelPathInSearchPath(rel,_plist) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/c/F') assert rp_ref == rp rel = os.path.normpath("c/F") rp = findRelPathInSearchPath(rel,_plist,**{'matchidx':1}) rp_ref = os.path.normpath(testdata.mypath+'/examples/a/b0/c/F') assert rp_ref == rp # 2.a. find the requested entry rp = findRelPathInSearchPath("F[0-5]*",_plist) expected = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/F1') assert expected == rp # 2.b. find the requested entry - here as demo with a relative path rp = findRelPathInSearchPath("c/*/b0/F[0-5]*",_plist) expected = os.path.normpath(testdata.mypath+'/examples/a/b0/c/a/b0/F1') assert expected == rp
__docformat__ = "restructuredtext en" import unittest import os, sys from filesysobjects.FileSysObjects import setUpperTreeSearchPath, findRelPathInSearchPath import epyunit.SystemCalls # ####################### # slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)), 'epyunit', slst) epyu = findRelPathInSearchPath('bin/epyunit', slst, matchidx=0) scri = findRelPathInSearchPath('epyunit/myscript.sh', slst, matchidx=0) class CallUnits(unittest.TestCase): def testCase010(self): _call = epyu + " --priotype=False " #_call += " --rdbg -- " _call += " -- " _call += scri + " OK " syskargs = {} sx = epyunit.SystemCalls.SystemCalls(**syskargs) callkargs = {} ret = sx.callit(_call, **callkargs)
from __future__ import absolute_import import unittest import os from filesysobjects.FileSysObjects import setUpperTreeSearchPath, findRelPathInSearchPath from pysourceinfo.PySourceInfo import getCallerModulePythonPath # ####################### # slst = [] setUpperTreeSearchPath(os.path.abspath(os.path.dirname(__file__)), 'epyunit', slst) epyu = findRelPathInSearchPath('bin/epyunit', slst, matchidx=0) class CallUnits(unittest.TestCase): def testCase000(self): """Selftest. """ call = epyu + " --selftest " exit_code = os.system(call) assert exit_code == 0 # ####################### # if __name__ == '__main__':