import json


def _updateStatsFromStdout(settings, line):
    """Parses 'line' and tries to extract encoded 'vfxtest-stats' that the
    subprocess might have logged.

    If any 'vfxtest-stats' were found the corresponding settings get updated.

    Args:
        settings (dict) : settings dictionary
        line (string)   : current STDOUT line to parse

    Returns:
        (bool)          : True if stats got found, False if not

    """
    status = False

    try:
        tokens = line.split('<vfxtest-stats>')
        stats = tokens[1].split('</vfxtest-stats>')[0]
        decoded = json.loads(stats)

        settings['files_run'] = decoded['files_run']
        settings['tests_run'] = decoded['tests_run']
        settings['errors'] = decoded['errors']


        status = True

    except (IndexError, TypeError) as e:
        pass

    return status