<commit_before>
import unittest
import inspect
import time
import gc
import argparse
import re
import sys
import os
import types
import traceback
from eutester.eulogger import Eulogger
from eutester.euconfig import EuConfig
import StringIO
import copy

'''
This is the base class for any test case to be included in the Eutester repo. It should include any
functionality that we expected to be repeated in most of the test cases that will be written.

Currently included:
 - Debug method
 - Allow parameterized test cases
 - Method to run test case
 - Run a list of test cases
 - Start, end and current status messages
 - Enum class for possible test results
 
Necessary to work on:
 - Argument parsing
 - Metric tracking (need to define what metrics we want
 - Standardized result summary
 - Logging standardization
 - Use docstring as description for test case
 - Standardized setUp and tearDown that provides useful/necessary cloud resources (ie group, keypair, image)
'''


class EutesterTestResult():
    '''
    standardized test results
    '''
    not_run="not_run"
    passed="passed"
    failed="failed"
    
class TestColor():
    reset = '\033[0m'
    #formats
    formats={'reset':'0',
             'bold':'1',
             'dim':'2',
             'uline':'4',
             'blink':'5',
             'reverse':'7',
             'hidden':'8',
             }
    
    foregrounds = {'black':30,
                   'red':31,
                   'green':32,
                   'yellow':33,
                   'blue':34,
                   'magenta':35,
                   'cyan':36,
                   'white':37,
                   'setasdefault':39}
    
    backgrounds = {'black':40,
                   'red':41,
                   'green':42,
                   'yellow':43,
                   'blue':44,
                   'magenta':45,
                   'cyan':46,
                   'white':47,
                   'setasdefault':49}
    
    #list of canned color schemes, for now add em as you need 'em?
    canned_colors ={'reset' : '\033[0m', #self.TestColor.get_color(fg=0)
                    'whiteonblue' : '\33[1;37;44m', #get_color(fmt=bold, fg=37,bg=44)
                    'red' : '\33[31m', #TestColor.get_color(fg=31)
                    'failred' : '\033[101m', #TestColor.get_color(fg=101) 
                    'blueongrey' : '\33[1;34;47m', #TestColor.get_color(fmt=bold, fg=34, bg=47)#'\33[1;34;47m'
                    'redongrey' : '\33[1;31;47m', #TestColor.get_color(fmt=bold, fg=31, bg=47)#'\33[1;31;47m'
                    'blinkwhiteonred' : '\33[1;5;37;41m', #TestColor.get_color(fmt=[bold,blink],fg=37,bg=41)#
                    }
    
    @classmethod
    def get_color(cls,fmt=0,fg='', bg=''):
        '''
        Description: Method to return ascii color codes to format terminal output. 
        Examples:
                blinking_red_on_black = get_color('blink', 'red', 'blue')
                bold_white_fg = get_color('bold', 'white, '')
                green_fg = get_color('','green','')
                
                print bold_white_fg+"This text is bold white"+TestColor.reset
        :type fmt: color attribute
        :param fmt: An integer or string that represents an ascii color attribute. see TestColor.formats
        
        :type fg: ascii foreground attribute
        :param fg: An integer or string that represents an ascii foreground color attribute. see TestColor.foregrounds
        
        :type bg: ascii background attribute
        :param bg: An integer or string that represents an ascii background color attribute. see TestColor.backgrounds
        '''
        
        fmts=''
        if not isinstance(fmt, types.ListType):
            fmt = [fmt]
        for f in fmt:
            if isinstance(f,types.StringType):
                f = TestColor.get_format_from_string(f)
            if f:
                fmts += str(f)+';'
        if bg:
            if isinstance(bg,types.StringType):
                bg = TestColor.get_bg_from_string(bg)
            if bg:
                bg = str(bg)
        if fg:
            if isinstance(fg,types.StringType):
                fg = TestColor.get_fg_from_string(fg)
            if fg:
                fg = str(fg)+';'
        
        return '\033['+str(fmts)+str(fg)+str(bg)+'m'
    
    @classmethod
    def get_format_from_string(cls,format):
        if format in TestColor.formats:
            return TestColor.formats[format]
        else:
            return ''
        
    @classmethod
    def get_fg_from_string(cls,fg):
        if fg in TestColor.foregrounds:
            return TestColor.foregrounds[fg]
        else:
            return ''
    @classmethod
    def get_bg_from_string(cls,bg):
        if bg in TestColor.backgrounds:
            return TestColor.backgrounds[bg]
        else:
            return ''
        
    @classmethod
    def get_canned_color(cls,color):
        try:
            return TestColor.canned_colors[color]
        except:
            return ""    
    
    
    
    
class EutesterTestUnit():
    '''
    Description: Convenience class to run wrap individual methods, and run and store and access results.
    
    type method: method
    param method: The underlying method for this object to wrap, run and provide information on 
    
    type args: list of arguments
    param args: the arguments to be fed to the given 'method'
    
    type eof: boolean
    param eof: boolean to indicate whether a failure while running the given 'method' should end the test case exectution. 
    '''
    def __init__(self,method, *args, **kwargs):
        self.method = method
        self.args = args
        self.kwargs = kwargs
        self.name = str(method.__name__)
        self.result=EutesterTestResult.not_run
        self.time_to_run=0
        self.description=self.get_test_method_description()
        self.eof=False
        self.error = ""
        print "Creating testunit:"+str(self.name)+", args:\n"
        for count, thing in enumerate(args):
            print '{0}. {1}'.format(count, thing)
        for name, value in kwargs.items():
            print '{0} = {1}'.format(name, value)
    
    @classmethod<commit_msg>remote newline in debug<commit_after>
import unittest
import inspect
import time
import gc
import argparse
import re
import sys
import os
import types
import traceback
from eutester.eulogger import Eulogger
from eutester.euconfig import EuConfig
import StringIO
import copy

'''
This is the base class for any test case to be included in the Eutester repo. It should include any
functionality that we expected to be repeated in most of the test cases that will be written.

Currently included:
 - Debug method
 - Allow parameterized test cases
 - Method to run test case
 - Run a list of test cases
 - Start, end and current status messages
 - Enum class for possible test results
 
Necessary to work on:
 - Argument parsing
 - Metric tracking (need to define what metrics we want
 - Standardized result summary
 - Logging standardization
 - Use docstring as description for test case
 - Standardized setUp and tearDown that provides useful/necessary cloud resources (ie group, keypair, image)
'''


class EutesterTestResult():
    '''
    standardized test results
    '''
    not_run="not_run"
    passed="passed"
    failed="failed"
    
class TestColor():
    reset = '\033[0m'
    #formats
    formats={'reset':'0',
             'bold':'1',
             'dim':'2',
             'uline':'4',
             'blink':'5',
             'reverse':'7',
             'hidden':'8',
             }
    
    foregrounds = {'black':30,
                   'red':31,
                   'green':32,
                   'yellow':33,
                   'blue':34,
                   'magenta':35,
                   'cyan':36,
                   'white':37,
                   'setasdefault':39}
    
    backgrounds = {'black':40,
                   'red':41,
                   'green':42,
                   'yellow':43,
                   'blue':44,
                   'magenta':45,
                   'cyan':46,
                   'white':47,
                   'setasdefault':49}
    
    #list of canned color schemes, for now add em as you need 'em?
    canned_colors ={'reset' : '\033[0m', #self.TestColor.get_color(fg=0)
                    'whiteonblue' : '\33[1;37;44m', #get_color(fmt=bold, fg=37,bg=44)
                    'red' : '\33[31m', #TestColor.get_color(fg=31)
                    'failred' : '\033[101m', #TestColor.get_color(fg=101) 
                    'blueongrey' : '\33[1;34;47m', #TestColor.get_color(fmt=bold, fg=34, bg=47)#'\33[1;34;47m'
                    'redongrey' : '\33[1;31;47m', #TestColor.get_color(fmt=bold, fg=31, bg=47)#'\33[1;31;47m'
                    'blinkwhiteonred' : '\33[1;5;37;41m', #TestColor.get_color(fmt=[bold,blink],fg=37,bg=41)#
                    }
    
    @classmethod
    def get_color(cls,fmt=0,fg='', bg=''):
        '''
        Description: Method to return ascii color codes to format terminal output. 
        Examples:
                blinking_red_on_black = get_color('blink', 'red', 'blue')
                bold_white_fg = get_color('bold', 'white, '')
                green_fg = get_color('','green','')
                
                print bold_white_fg+"This text is bold white"+TestColor.reset
        :type fmt: color attribute
        :param fmt: An integer or string that represents an ascii color attribute. see TestColor.formats
        
        :type fg: ascii foreground attribute
        :param fg: An integer or string that represents an ascii foreground color attribute. see TestColor.foregrounds
        
        :type bg: ascii background attribute
        :param bg: An integer or string that represents an ascii background color attribute. see TestColor.backgrounds
        '''
        
        fmts=''
        if not isinstance(fmt, types.ListType):
            fmt = [fmt]
        for f in fmt:
            if isinstance(f,types.StringType):
                f = TestColor.get_format_from_string(f)
            if f:
                fmts += str(f)+';'
        if bg:
            if isinstance(bg,types.StringType):
                bg = TestColor.get_bg_from_string(bg)
            if bg:
                bg = str(bg)
        if fg:
            if isinstance(fg,types.StringType):
                fg = TestColor.get_fg_from_string(fg)
            if fg:
                fg = str(fg)+';'
        
        return '\033['+str(fmts)+str(fg)+str(bg)+'m'
    
    @classmethod
    def get_format_from_string(cls,format):
        if format in TestColor.formats:
            return TestColor.formats[format]
        else:
            return ''
        
    @classmethod
    def get_fg_from_string(cls,fg):
        if fg in TestColor.foregrounds:
            return TestColor.foregrounds[fg]
        else:
            return ''
    @classmethod
    def get_bg_from_string(cls,bg):
        if bg in TestColor.backgrounds:
            return TestColor.backgrounds[bg]
        else:
            return ''
        
    @classmethod
    def get_canned_color(cls,color):
        try:
            return TestColor.canned_colors[color]
        except:
            return ""    
    
    
    
    
class EutesterTestUnit():
    '''
    Description: Convenience class to run wrap individual methods, and run and store and access results.
    
    type method: method
    param method: The underlying method for this object to wrap, run and provide information on 
    
    type args: list of arguments
    param args: the arguments to be fed to the given 'method'
    
    type eof: boolean
    param eof: boolean to indicate whether a failure while running the given 'method' should end the test case exectution. 
    '''
    def __init__(self,method, *args, **kwargs):
        self.method = method
        self.args = args
        self.kwargs = kwargs
        self.name = str(method.__name__)
        self.result=EutesterTestResult.not_run
        self.time_to_run=0
        self.description=self.get_test_method_description()
        self.eof=False
        self.error = ""
        print "Creating testunit:"+str(self.name)+", args:"
        for count, thing in enumerate(args):
            print '{0}. {1}'.format(count, thing)
        for name, value in kwargs.items():
            print '{0} = {1}'.format(name, value)
    
    @classmethod
{'fraction_non_alphanumeric': 0.10228921489601805, 'fraction_numerical': 0.02176366274383363, 'mean_word_length': 1.917234893016694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '622913', 'n_tokens_mistral': 3783, 'n_tokens_neox': 3526, 'n_words': 1012}