def displayDictionaryTest(): ''' Verify use cases for displayDictionary. ''' myLogger.info('\n*** DISPLAY DICTIONARY TEST ***\n') sequentialDictionary = {100: 'apple', -1: 'pear', 50: 'orange', 25: 1234, 15: 1.234, 'name': 'sequentialDictionary'} releaseDictionary = {'list1': [12, 34, 56], 'name': 'releaseDictionary', 'title': __title__, 'version': __version__, 'date': __date__} programDictionary = {'name': 'programDictionary', 'list2': ['ab', 'cd', 'ef'], 'main': __name__, 'mainTitleVersionDate': mainTitleVersionDate} myDictionary = { 'name': 'myDictionary', 'contents': {'releaseDictionary': releaseDictionary, 'programDictionary': programDictionary, 'sequentialDictionary': sequentialDictionary, 'name': 'contents'}} myConsole = sys.stdout tsrpu.displayDictionary(0, myDictionary, myConsole) myFile = open(os.path.join(myLogger.theLogPath, 'displayDictionaryTest.log'), 'w') tsrpu.displayDictionary(0, myDictionary, myFile) myFile.close()
print("%s: ImportError (tsLibCLI); " % __title__ + "importCode=%s" % str(importCode)) # ------------------------------------------------------------------- print(__header__) # ------------------------------------------------------------------- myLogger = Logger.TsLogger(name="", threshold=Logger.INFO) # ------------------------------------------------------------------- sizex, sizey = get_terminal_size() print("\n width = %d; height = %d" % (sizex, sizey)) current_os = platform.system() print("\n current_os = %s" % current_os) # ------------------------------------------------------------------- level = 0 myDictionary = ThemeToUse myConsole = sys.stdout tsrpu.displayDictionary(level, myDictionary, myConsole) myFile = open(os.path.join(myLogger.theLogPath, "tsCxGlobalsDictionaryTest.log"), "w") tsrpu.displayDictionary(level, myDictionary, myFile) myFile.close()
def wrapperTest(): ''' Verify operation of logging to devices and files. ''' ## def taskTest(): ## ''' ## Verify logging to application log. ## ''' ## theName = 'taskTest.log' ## defaultLogger = TsLogger(threshold=INFO, ## start=time.time()) ## print('\tStarted Logging to %s' % defaultLogger.name) ## defaultLogger.info('Started Logging to %s' % defaultLogger.name) ## print('\tDefault Task: %s' % \ ## defaultLogger.theTopLevelApplicationTask) ## defaultLogger.info('Default Task: %s' % \ ## defaultLogger.theTopLevelApplicationTask) ## theName = 'taskTest.log' ## myLogger = TsLogger(threshold=INFO, ## start=time.time(), ## name=theName) ## print('\tStarted Logging to %s' % myLogger.name) ## myLogger.info('Started Logging to %s' % myLogger.name) ## print('\tTask: %s' % myLogger.theTopLevelApplicationTask) ## myLogger.info('Task: %s' % myLogger.theTopLevelApplicationTask) #------------------------------------------------------------------- def propertyTest(myLogger): ''' Verify logger properties. ''' try: myLogger.info( 'appLogger= "%s"' % myLogger.appLogger) myLogger.info( 'theLogName= "%s"' % myLogger.theLogName) myLogger.info( 'theLogPath= "%s"' % myLogger.theLogPath) level = myLogger.theLogThreshold levelName = getLevelName(level) myLogger.info( 'theLogThreshold= "%s" (%s)' % (levelName, level)) except Exception as propertyErrorCode: myLogger.error( 'propertyErrorCode="%s"' % propertyErrorCode) #------------------------------------------------------------------- def levelTest(myLogger): ''' Verify logging for each level. ''' availableLevels = [ tsLogger.NOTSET, tsLogger.PRIVATE, # tsLogger.DEBUG_TRACE_LEVEL, tsLogger.DEBUG, tsLogger.INFO, tsLogger.NOTICE, tsLogger.WARNING, tsLogger.ALERT, tsLogger.ERROR, tsLogger.CRITICAL, tsLogger.EMERGENCY] if TROUBLE_SHOOTING_DEBUG: print('begin levelTest on <%s>' % myLogger.thisLogName) for level in availableLevels: levelName = tsLogger.getLevelName(level) myLogger.log( level, '%s Level report on <%s>' % (levelName, myLogger.thisLogName)) if TROUBLE_SHOOTING_DEBUG: print('end levelTest on <%s>' % myLogger.thisLogName) #------------------------------------------------------------------- def deviceTest(): ''' Verify logging to stdout, stderr and syslog. ''' separator = '-' * (72 - 8) for device in tsLogger._deviceList: print('\n\t%s' % separator) myLogger = tsLogger.TsLogger(threshold=tsLogger.INFO, start=time.time(), name=device) print('\tName: %s' % myLogger.thisRegisteredName) print('\tID: %s' % myLogger.thisLogID) levelTest(myLogger) if False and TROUBLE_SHOOTING_DEBUG: # Cannot close shared devices because there is # no mechanism to automatically re-open them. myLogger.close() #------------------------------------------------------------------- def fileTest(): ''' Verify logging to files. ''' separator = '-' * (72 - 8) for device in ['', 'myMethod.log']: print('\n\t%s' % separator) myLogger = tsLogger.TsLogger(threshold = tsLogger.NOTSET, start = time.time(), name = device) print('\tName: %s' % myLogger.thisRegisteredName) print('\tID: %s' % myLogger.thisLogID) levelTest(myLogger) #------------------------------------------------------------------- def descriptionTest(): ''' Verify text wrapping operation when outputting multi-line text to logger. ''' myLogger = tsLogger.TsLogger(threshold = tsLogger.ERROR, start = time.time(), name = 'myDescription.log', file_header = 'Error Report Started', file_footer = 'Error Report Finished', width = 70, initial_indent = '\t', subsequent_indent = '\t') print('\tName: %s' % myLogger.thisRegisteredName) print('\tID: %s' % myLogger.thisLogID) paragraph = "The textwrap module provides two convenience" \ " functions, wrap() and fill(), as well as" \ " TextWrapper, the class that does all the work,"\ " and a utility function dedent(). If you're just" \ " wrapping or filling one or two text strings, the" \ " convenience functions should be good enough;" \ " otherwise, you should use an instance of" \ " TextWrapper for efficiency." message = ['1st line; no tabs'] myLogger.description(message, level = tsLogger.ERROR, indent = 1, tab = 4, title = 'Data Corruption #1') message = ['2nd line;\tone tab'] myLogger.description(message, level = tsLogger.ERROR, indent = 1, tab = 4, title = 'Data Corruption #2') message = ['3rd line;\t\ttwo tabs', '', paragraph] myLogger.description(message, level = tsLogger.ERROR, indent = 1, tab = 4, title = 'Data Corruption #3') myLogger.close() #------------------------------------------------------------------- def rewriteTest(): ''' ''' myLogger = tsLogger.TsLogger(threshold = tsLogger.WARNING, start = time.time(), name = 'myProgress.log') print('\tName: %s' % myLogger.thisRegisteredName) print('\tID: %s' % myLogger.thisLogID) myLogger.progress('No Level update', level = tsLogger.NOTSET) myLogger.progress('Debug Level update', level = tsLogger.DEBUG) myLogger.progress('Info Level update', level = tsLogger.INFO) myLogger.progress('Warning Level update', level = tsLogger.WARNING) myLogger.progress('Error Level update', level = tsLogger.ERROR) myLogger.progress('Critical Level update', level = tsLogger.CRITICAL) myLogger.event('\n\nFinished New Logging Tests\n\n') myLogger.close() #------------------------------------------------------------------- def assertTest(): ''' ''' def pseudoOp(number): print(number) myDebugHandlers = tsLogger.TsLogger(threshold = tsLogger.DEBUG, start = time.time(), name = 'myAsserts.log') conditions = [True, False] line = 0 for cond in conditions: print('#################### cond=%s ####################' % cond) line += 1 # 1 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxASSERT( cond))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 2 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxASSERT_MSG( cond, msg='Sample #%d' % line))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 3 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxCHECK( cond, rc=123 + line))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 4 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxCHECK_MSG( cond, rc=123 + line, msg='Sample #%d' % line))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 5 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxCHECK2( cond, op=pseudoOp(line)))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 6 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxCHECK2_MSG( cond, op=pseudoOp(line), msg='Sample #%d' % line))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 7 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxFAIL())) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 8 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxFAIL_COND_MSG( cond, msg='Sample #%d' % line))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 9 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxFAIL_MSG( msg='Sample #%d' % line))) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) line += 1 # 10 try: print('line= %d; rc=%s' % ( line, myDebugHandlers.wxTRAP())) except Exception as errorCode: print('Handled Trap for line= %d; errorCode=%s' % ( line, errorCode)) #------------------------------------------------------------------- separator = '-' * 72 # taskTest() print('\n%s' % separator) deviceTest() print('\n%s' % separator) fileTest() print('\n%s' % separator) descriptionTest() print('\n%s' % separator) rewriteTest() print('\n%s' % separator) assertTest() print('\n%s' % separator) myLogger = tsLogger.TsLogger(threshold = tsLogger.DEBUG, start = time.time(), name = 'myProperties.log') level=0 head = myLogger.tsGetLoggerPath() tail = 'tsLogger-Dict.txt' deviceName = '%s/%s' % (head, tail) myFile = open(deviceName, 'w+') myDictionary = tsLogger.TsLogger.activeLoggerIDs tsrpu.displayDictionary(level, myDictionary, myFile, myLogger=None) myFile.close() propertyTest(myLogger)
print('\n%s' % separator) assertTest() print('\n%s' % separator) myLogger = tsLogger.TsLogger(threshold = tsLogger.DEBUG, start = time.time(), name = 'myProperties.log') level=0 head = myLogger.tsGetLoggerPath() tail = 'tsLogger-Dict.txt' deviceName = '%s/%s' % (head, tail) myFile = open(deviceName, 'w+') myDictionary = tsLogger.TsLogger.activeLoggerIDs tsrpu.displayDictionary(level, myDictionary, myFile, myLogger=None) myFile.close() propertyTest(myLogger) def getOptions(): ''' Parse the command line and return a list of positional arguments and a dictionanary of keyword options. NOTE: Requirement is an inappropriate, oversimplification. Invoking argparse or optparse (deprecated with Python 2.7.0) do not produce equivalent output without substantial post processing that has not yet been created. This may explain inability to migrate use of tsApplication to tsCommandLineEnv or to tsWxMultiFrameEnv.