Beispiel #1
0
 def filter(self, record):
     try:
         relpath = get_rel_path(record.source_file)
         lineno = record.source_lineno
     except AttributeError:
         relpath = get_rel_path(record.pathname)
         lineno = record.lineno
     if lineno:
         record.source = "{}:{}".format(relpath, lineno)
     else:
         record.source = relpath
     return True
Beispiel #2
0
    def filter(self, record):
        try:
            relpath = get_rel_path(record.source_file) or record.source_file
            lineno = record.source_lineno
        except AttributeError:
            relpath = get_rel_path(record.pathname) or record.pathname
            lineno = record.lineno
        if lineno:
            record.source = "%s:%d" % (relpath, lineno)
        else:
            record.source = relpath

        return True
Beispiel #3
0
    def filter(self, record):
        try:
            relpath = get_rel_path(record.source_file)
            lineno = record.source_lineno
        except AttributeError:
            relpath = get_rel_path(record.pathname)
            lineno = record.lineno
        if lineno:
            record.source = "{}:{}".format(relpath, lineno)
        else:
            record.source = relpath

        return True
Beispiel #4
0
def _showwarning(message, category, filename, lineno, file=None, line=None):
    relpath = get_rel_path(filename)
    if relpath:
        # Only show warnings from inside this project
        message = "%s from %s:%d: %s" % (category.__name__, relpath, lineno,
                                         message)
        logger.warning(message)
Beispiel #5
0
def _annote_failure(fail_message=""):
    # Inspect the stack with 1 line of context, looking at the 2nd frame
    # before this one, assuming the first frame is whatever called this function,
    # and the second frame is where the assertion failure took place
    frameinfo = inspect.getframeinfo(inspect.stack(1)[2][0])
    if not fail_message:
        fail_message = str(frameinfo.code_context[0]).strip()

    filename = get_rel_path(frameinfo.filename) or frameinfo.filename
    path = "%s:%r" % (filename, frameinfo.lineno)
    return "%s (%s)" % (fail_message, path)
Beispiel #6
0
    def _soft_assert_func(expr, fail_message=''):
        if not expr:
            # inspect the calling frame to find where the original assertion failed
            # explicitly requesting one line of code context so we can set fail_message if needed
            frameinfo = inspect.getframeinfo(inspect.stack(1)[1][0])
            if not fail_message:
                fail_message = str(frameinfo.code_context[0]).strip()

            path = '%s:%r' % (get_rel_path(frameinfo.filename), frameinfo.lineno)
            fail_message = '%s (%s)' % (fail_message, path)
            _thread_locals.caught_asserts.append(fail_message)
Beispiel #7
0
def _annote_failure(fail_message=''):
    # Inspect the stack with 1 line of context, looking at the 2nd frame
    # before this one, assuming the first frame is whatever called this function,
    # and the second frame is where the assertion failure took place
    frameinfo = inspect.getframeinfo(inspect.stack(1)[2][0])
    if not fail_message:
        fail_message = str(frameinfo.code_context[0]).strip()

    filename = get_rel_path(frameinfo.filename) or frameinfo.filename
    path = '%s:%r' % (filename, frameinfo.lineno)
    return '%s (%s)' % (fail_message, path)
Beispiel #8
0
def _showwarning(message, category, filename, lineno, file=None, line=None):
    relpath = get_rel_path(filename)
    if relpath:
        # Only show warnings from inside this project
        message = "{} from {}:{}: {}".format(category.__name__, relpath, lineno, message)
        try:
            logger.warning(message)
        except ImportError:
            # In case we have both credentials.eyaml and credentials.yaml, it gets in an import loop
            # Therefore it would raise ImportError for art_client. Let's don't bother and just spit
            # it out. This should reduce number of repeated questions down by 99%.
            print("[WARNING] {}".format(message))
Beispiel #9
0
def _showwarning(message, category, filename, lineno, file=None, line=None):
    relpath = get_rel_path(filename)
    if relpath:
        # Only show warnings from inside this project
        message = "{} from {}:{}: {}".format(category.__name__, relpath, lineno, message)
        try:
            logger.warning(message)
        except ImportError:
            # In case we have both credentials.eyaml and credentials.yaml, it gets in an import loop
            # Therefore it would raise ImportError for art_client. Let's don't bother and just spit
            # it out. This should reduce number of repeated questions down by 99%.
            print("[WARNING] {}".format(message))
Beispiel #10
0
def _annotate_failure(fail_message=''):
    # frames
    # 0: call to nth_frame_info
    # 1: _annotate_failure (this function)
    # 2: _annotate_failure caller (soft assert func or CM)
    # 3: failed assertion
    frameinfo = nth_frame_info(3)
    if not fail_message:
        fail_message = str(frameinfo.code_context[0]).strip()

    filename = get_rel_path(frameinfo.filename)
    path = '%s:%r' % (filename, frameinfo.lineno)
    return '%s (%s)' % (fail_message, path)
Beispiel #11
0
def _annotate_failure(fail_message=''):
    # frames
    # 0: call to nth_frame_info
    # 1: _annotate_failure (this function)
    # 2: _annotate_failure caller (soft assert func or CM)
    # 3: failed assertion
    frameinfo = nth_frame_info(3)
    if not fail_message:
        fail_message = str(frameinfo.code_context[0]).strip()

    filename = get_rel_path(frameinfo.filename)
    path = '{}:{!r}'.format(filename, frameinfo.lineno)
    return '{} ({})'.format(fail_message, path)
Beispiel #12
0
 def process(self, msg, kwargs):
     # frames
     # 0: call to nth_frame_info
     # 1: adapter process method (this method)
     # 2: adapter logging method
     # 3: original logging call
     frameinfo = nth_frame_info(3)
     extra = kwargs.get('extra', {})
     # add extra data if needed
     if not extra.get('source_file'):
         if frameinfo.filename:
             extra['source_file'] = get_rel_path(frameinfo.filename)
             extra['source_lineno'] = frameinfo.lineno
         else:
             # calling frame didn't have a filename
             extra['source_file'] = 'unknown'
             extra['source_lineno'] = 0
     kwargs['extra'] = extra
     return msg, kwargs
Beispiel #13
0
 def process(self, msg, kwargs):
     # frames
     # 0: call to nth_frame_info
     # 1: adapter process method (this method)
     # 2: adapter logging method
     # 3: original logging call
     frameinfo = nth_frame_info(3)
     extra = kwargs.get('extra', {})
     # add extra data if needed
     if not extra.get('source_file'):
         if frameinfo.filename:
             extra['source_file'] = get_rel_path(frameinfo.filename)
             extra['source_lineno'] = frameinfo.lineno
         else:
             # calling frame didn't have a filename
             extra['source_file'] = 'unknown'
             extra['source_lineno'] = 0
     kwargs['extra'] = extra
     return msg, kwargs
Beispiel #14
0
 def filter(self, record):
     record.pathname = get_rel_path(record.pathname)
     return True
Beispiel #15
0
def _showwarning(message, category, filename, lineno, file=None, line=None):
    relpath = get_rel_path(filename)
    if relpath:
        message = "{} from {}:{}: {}".format(category.__name__, relpath,
                                             lineno, message)
        logger.warning(message)
Beispiel #16
0
 def filter(self, record):
     record.pathname = get_rel_path(record.pathname)
     return True
Beispiel #17
0
def _showwarning(message, category, filename, lineno, file=None, line=None):
    relpath = get_rel_path(filename)
    if relpath:
        # Only show warnings from inside this project
        message = "%s from %s:%d: %s" % (category.__name__, relpath, lineno, message)
        logger.warning(message)