def testCase13a(): print("Case13a: include codePath error but exclude from string - aborts") delegate = delegateSetup(None, ["*test*"], ["*not*"], None) try: Tf.RaiseCodingError("does not abort - word not excluded") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("lets not abort - word not excluded") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("abort please - word excluded") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase6(): print("Case6: Exclude some but abort on at least one string error") delegate = delegateSetup(["*abort*"], None, ["*not*"], None) try: Tf.RaiseCodingError("does not abort") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("not abort") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("aborting on this!!") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase12a(): print("Case12a: include string error but exclude from path - aborts") delegate = delegateSetup(["please"], None, None, ["*usdImaging*"]) try: Tf.RaiseCodingError("does not abort - not in usdImaging") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("lets not abort - not in usdImaging") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("abort please - not in usdImaging") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase12(): print( "Case12: include string error but exclude from path - does not abort") delegate = delegateSetup(["*"], None, None, ["*test*"]) try: Tf.RaiseCodingError("does not abort - nothing in pxr is aborted") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("lets not abort - nothing in pxr is aborted") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("abort not please - nothing in pxr is aborted") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase11a(): print("Case11a: All string errors consumed by exclude list without using " "glob") delegate = delegateSetup(None, ["ConditionalAbort"], None, ["*test*"]) try: Tf.RaiseCodingError("does not abort") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("lets not abort") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("abort not please") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase11(): print("Case11: Exclude some but abort on at least one codePath error") # Note this is done using string exclude filters delegate = delegateSetup(None, ["*test*"], ["*not*"], None) try: Tf.RaiseCodingError("does not abort") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("not abort") except Tf.ErrorException as e: Tf.RepostErrors(e) try: Tf.RaiseCodingError("aborting on this!!") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase8(): print("Case8: Ignore all codePath errors") delegate = delegateSetup(None, ["*"], None, ["*"]) try: Tf.RaiseCodingError("") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase2(): print("Case2: Ignore all string errors") delegate = delegateSetup(["*"], None, ["*"], None) try: Tf.RaiseCodingError("") except Tf.ErrorException as e: Tf.RepostErrors(e)
def test_Notices(self): self.log.info("Issuing a couple of different types of errors.") try: Tf.RaiseRuntimeError("Runtime error!") assert False, "expected exception" except Tf.ErrorException: pass try: Tf.RaiseCodingError("Coding error!") assert False, "expected exception" except Tf.ErrorException: pass self.log.info("Issuing a few generic warnings.") Tf.Warn("Warning 1") Tf.Warn("Warning 2") Tf.Warn("Warning 3") self.log.info("Issuing a status message.") Tf.Status("Status: Almost done testing.") # Assert that two errors, three warnings and one status message were # issued. self.assertNotIn('IssuedError', self.notices) self.assertEqual(self.notices['IssuedWarning'], 3) self.assertEqual(self.notices['IssuedStatus'], 1) self.outputFile.close()
def testError_Python(self): """Errors in Python-invoked code should still propagate to Python normally.""" with self.assertRaises(Tf.ErrorException): Tf.RaiseCodingError("coding error!") with self.assertRaises(Tf.ErrorException): Tf.RaiseRuntimeError("runtime error!")
def testBatching(self): self._StartRecording() with mayaUsdLib.DiagnosticBatchContext(): Tf.Warn("spooky warning") Tf.Status("informative status") for i in range(5): Tf.Status("repeated status %d" % i) for i in range(3): Tf.Warn("spam warning %d" % i) try: Tf.RaiseCodingError("coding error!") except: pass log = self._StopRecording() # Note: we use assertItemsEqual because coalescing may re-order the # diagnostic messages. self.assertItemsEqual(log, [ ("spooky warning", OM.MCommandMessage.kWarning), ("informative status", OM.MCommandMessage.kInfo), ("repeated status 0 -- and 4 similar", OM.MCommandMessage.kInfo), ("spam warning 0 -- and 2 similar", OM.MCommandMessage.kWarning) ])
def testCase4(): print("Case4: Empty lists of inclusion filters for string errors") delegate = delegateSetup(None, None, ["blah"], None) try: Tf.RaiseCodingError("") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase3(): print("Case3: Empty lists of error filters") delegate = delegateSetup(None, None, None, None) try: Tf.RaiseCodingError("") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testError(self): """Simulate error in non-Python-invoked code by using Tf.RepostErrors.""" self._StartRecording() try: Tf.RaiseCodingError("blah") except Tf.ErrorException as e: Tf.RepostErrors(e) log = self._StopRecording() self.assertEqual(len(log), 1) logText, logCode = log[0] # When this test is executed as a result of the unittest.main() call at # the bottom of this file (e.g. when this script is executed directly # via the shebang, when the script file is passed to a Python # interpreter on the command-line, or when the script file's contents # is read and executed through compile() and exec(), the module will be # reported as "__main__". Otherwise, when this file is imported as a # module and then executed using unittest.main(module=<module name>), # the module name will match the file name and be reported as # "testDiagnosticDelegate". We make the regex here recognize both # cases. if (Tf.GetEnvSetting('MAYAUSD_SHOW_FULL_DIAGNOSTICS')): self.assertRegex( logText, "^Python coding error: blah -- Coding Error in " "(__main__|testDiagnosticDelegate)\.testError at line [0-9]+ of " ) else: self.assertEqual(logText, "Python coding error: blah") self.assertEqual(logCode, OM.MCommandMessage.kError)
def testCase5a(): print("Case5a: Empty lists of exclude filters for string errors, include " "list does contain error") delegate = delegateSetup(["*included*"], None, None, None) try: Tf.RaiseCodingError("error string included") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase5(): print("Case5: Empty lists of exclude filters for string errors, include " "list does not contain any error") delegate = delegateSetup(["blah"], None, None, None) try: Tf.RaiseCodingError("error string not included") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testCase10a(): print("Case10a: Empty lists of exclude filters for codePath errors, " "include list does contain error") delegate = delegateSetup(None, ["*test*"], None, None) try: Tf.RaiseCodingError("codePath included") except Tf.ErrorException as e: Tf.RepostErrors(e)
def testError(self): """Simulate error in non-Python-invoked code by using Tf.RepostErrors.""" self._StartRecording() try: Tf.RaiseCodingError("blah") except Tf.ErrorException as e: Tf.RepostErrors(e) log = self._StopRecording() self.assertEqual(len(log), 1) logText, logCode = log[0] self.assertRegexpMatches(logText, "^Python coding error: blah -- Coding Error in " "__main__\.testError at line [0-9]+ of ") self.assertEqual(logCode, OM.MCommandMessage.kError)
def test_Exception(self): with self.assertRaises(RuntimeError): Tf._TakesBase(Raiser()) with self.assertRaises(Tf.ErrorException) as cm: Tf._mightRaise(True) for x in cm.exception: self.assertTrue(len(repr(x))) with self.assertRaises(Tf.ErrorException): Tf.RaiseCodingError("some error") with self.assertRaises(Tf.ErrorException): Tf.RaiseRuntimeError("some error") with self.assertRaises(Tf.ErrorException): Tf._doErrors()
def Run(self): ''' The main entry point to launch a process using UsdView. ''' parser = argparse.ArgumentParser(prog=sys.argv[0], description=self.GetHelpDescription()) traceCollector = None with Timer() as totalTimer: self.RegisterPositionals(parser) self.RegisterOptions(parser) arg_parse_result = self.ParseOptions(parser) self.ValidateOptions(arg_parse_result) if arg_parse_result.traceToFile: from pxr import Trace traceCollector = Trace.Collector() if arg_parse_result.tracePython: traceCollector.pythonTracingEnabled = True traceCollector.enabled = True self.__LaunchProcess(arg_parse_result) if traceCollector: traceCollector.enabled = False if arg_parse_result.timing and arg_parse_result.quitAfterStartup: totalTimer.PrintTime('open and close usdview') if traceCollector: if arg_parse_result.traceFormat == 'trace': Trace.Reporter.globalReporter.Report( arg_parse_result.traceToFile) elif arg_parse_result.traceFormat == 'chrome': Trace.Reporter.globalReporter.ReportChromeTracingToFile( arg_parse_result.traceToFile) else: Tf.RaiseCodingError( "Invalid trace format option provided: %s -" "trace/chrome are the valid options" % arg_parse_result.traceFormat)