# Path: ifj2017/test/base.py
# class TestReport(object):
# 
# Path: ifj2017/test/logger.py
# class TestLogger(object):
#     BLUE = '\033[94m'
#     GREEN = '\033[32m'
#     WARNING = '\033[93m'
#     HEADER = '\033[95m'
#     FAIL = '\033[91m'
# 
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'
#     END = '\033[0m'
# 
#     disable_colors = disable_color()
#     verbose = False
#     console_width, console_height = shutil.get_terminal_size((120, 20))
# 
#     _test_case_buffer = None
#     _test_case_success = None
#     _test_case_skipped = None
# 
#     @classmethod
#     def log(cls, *args, stream=sys.stderr, end=True, indent=0):
#         def write(what):
#             if cls._test_case_buffer is not None:
#                 cls._test_case_buffer.append(what)
#             else:
#                 stream.write(what)
# 
#         write('\t' * indent)
#         to_log = ''.join(map(str, filter(None, args)))
#         if cls.disable_colors:
#             for color in (
#                     cls.BLUE, cls.GREEN, cls.WARNING, cls.HEADER,
#                     cls.FAIL, cls.BOLD, cls.UNDERLINE, cls.END
#             ):
#                 to_log = to_log.replace(color, '')
# 
#         write(to_log)
#         if not cls.disable_colors:
#             write(cls.END)
#         if end:
#             write('\n')
# 
#     @classmethod
#     def log_section(cls, section):
#         cls.log(cls.BLUE, cls.UNDERLINE, section, ':')
# 
#     @classmethod
#     def log_test(cls, name, info=None):
#         cls._test_case_buffer = []
#         cls.log(cls.BOLD, '{:3}'.format(name), info, ': ', indent=1, end=False)
# 
#     @classmethod
#     def log_test_fail(cls, result):
#         cls._test_case_success = False
#         cls.log(cls.BOLD, cls.WARNING, ' × ', result, end=False)
# 
#     @classmethod
#     def log_test_ok(cls):
#         cls._test_case_success = True
#         cls.log(cls.GREEN, cls.BOLD, '√', end=False)
# 
#     @classmethod
#     def log_warning(cls, warning, end=True):
#         cls.log(cls.FAIL, cls.BOLD, 'WARNING: ', warning, end=end)
# 
#     @classmethod
#     def log_end_test_case(cls):
#         cls.log()
#         if cls.verbose or not cls._test_case_success and not cls._test_case_skipped:
#             cls._log_buffer()
#         cls._test_case_buffer = None
# 
#     @classmethod
#     def log_price(cls, state: State, groot_price: Optional[int]):
#         # (State) -> None
#         cls.log(
#             cls.BLUE,
#             ' ',
#             state.operand_price + state.instruction_price,
#             ' ({}+{}) '.format(
#                 state.instruction_price,
#                 state.operand_price
#             ),
#             end=False
#         )
#         if groot_price != state.price:
#             cls.log_warning(
#                 'Computed price {} does not matched price from reference interpreter {}, '
#                 'please contact maintainers.'.format(state.price, groot_price),
#                 end=False
#             )
# 
#     @classmethod
#     def log_results(cls, reports):
#         total = len(reports)
#         if not total:
#             cls.log(cls.UNDERLINE, cls.BLUE, cls.WARNING, 'No tests found.')
#             return 0
# 
#         success = len(tuple(filter(attrgetter('success'), reports)))
#         skipped = len(tuple(filter(lambda r: r.success is None, reports)))
# 
#         cls.log(
#             cls.UNDERLINE,
#             cls.BOLD,
#             'RESULTS:',
#             cls.END,
#             cls.BOLD,
#             ' {:.3f}%'.format((float(success) / (total - skipped)) * 100),
#             cls.END,
#             ' ({}/{})\n'.format(success, total - skipped),
#             cls.END,
#             cls.BOLD,
#             ''.join(
#                 (
#                     ((cls.FAIL + '×', cls.GREEN + '.')[report.success]
#                      if report.success is not None
#                      else cls.BLUE + '_')
#                 ) + ('\n' if not (i % cls.console_width) else '')
#                 for i, report in enumerate(reports, start=1)),
#             ''
#         )
#         return bool(total - success)
# 
#     @classmethod
#     def _log_buffer(cls, stream=sys.stderr):
#         for to_log in cls._test_case_buffer or ():
#             stream.write(to_log)


import json
import os
import os.path as path
from glob import iglob
from operator import attrgetter
from os.path import basename
from typing import Set, Tuple, Optional
from .base import TestInfo
from .logger import TestLogger

        return sorted(
            tests,
            key=lambda test: (len(test.name), test.name)
        )

    def _load_json_file(self, section_dir):
        data = self.load_file(
            path.join(section_dir, 'tests.json'),
            allow_fail=True
        )
        if not data:
            return {}
        try:
            return json.loads(data)
        except (json.JSONDecodeError, TypeError) as e:
            TestLogger.log_warning(
                "File {} is not valid json to load ({}).".format(path.join(section_dir, 'tests.json'), e)
            )
            return {}

    def _load_compact_tests(self, section_dir, data):
        cases = []
        extensions = tuple(data.get('extensions', ()))
        try:
            for i, test_case in enumerate(data.get('tests', ())):
                name = test_case.get('name')
                code = test_case.get('code')

                if name and code:

# Path: ifj2017/test/base.py
# class TestReport(object):
# 
# Path: ifj2017/test/logger.py
# class TestLogger(object):
#     BLUE = '\033[94m'
#     GREEN = '\033[32m'
#     WARNING = '\033[93m'
#     HEADER = '\033[95m'
#     FAIL = '\033[91m'
# 
#     BOLD = '\033[1m'
#     UNDERLINE = '\033[4m'
#     END = '\033[0m'
# 
#     disable_colors = disable_color()
#     verbose = False
#     console_width, console_height = shutil.get_terminal_size((120, 20))
# 
#     _test_case_buffer = None
#     _test_case_success = None
#     _test_case_skipped = None
# 
#     @classmethod
#     def log(cls, *args, stream=sys.stderr, end=True, indent=0):
#         def write(what):
#             if cls._test_case_buffer is not None:
#                 cls._test_case_buffer.append(what)
#             else:
#                 stream.write(what)
# 
#         write('\t' * indent)
#         to_log = ''.join(map(str, filter(None, args)))
#         if cls.disable_colors:
#             for color in (
#                     cls.BLUE, cls.GREEN, cls.WARNING, cls.HEADER,
#                     cls.FAIL, cls.BOLD, cls.UNDERLINE, cls.END
#             ):
#                 to_log = to_log.replace(color, '')
# 
#         write(to_log)
#         if not cls.disable_colors:
#             write(cls.END)
#         if end:
#             write('\n')
# 
#     @classmethod
#     def log_section(cls, section):
#         cls.log(cls.BLUE, cls.UNDERLINE, section, ':')
# 
#     @classmethod
#     def log_test(cls, name, info=None):
#         cls._test_case_buffer = []
#         cls.log(cls.BOLD, '{:3}'.format(name), info, ': ', indent=1, end=False)
# 
#     @classmethod
#     def log_test_fail(cls, result):
#         cls._test_case_success = False
#         cls.log(cls.BOLD, cls.WARNING, ' × ', result, end=False)
# 
#     @classmethod
#     def log_test_ok(cls):
#         cls._test_case_success = True
#         cls.log(cls.GREEN, cls.BOLD, '√', end=False)
# 
#     @classmethod
#     def log_warning(cls, warning, end=True):
#         cls.log(cls.FAIL, cls.BOLD, 'WARNING: ', warning, end=end)
# 
#     @classmethod
#     def log_end_test_case(cls):
#         cls.log()
#         if cls.verbose or not cls._test_case_success and not cls._test_case_skipped:
#             cls._log_buffer()
#         cls._test_case_buffer = None
# 
#     @classmethod
#     def log_price(cls, state: State, groot_price: Optional[int]):
#         # (State) -> None
#         cls.log(
#             cls.BLUE,
#             ' ',
#             state.operand_price + state.instruction_price,
#             ' ({}+{}) '.format(
#                 state.instruction_price,
#                 state.operand_price
#             ),
#             end=False
#         )
#         if groot_price != state.price:
#             cls.log_warning(
#                 'Computed price {} does not matched price from reference interpreter {}, '
#                 'please contact maintainers.'.format(state.price, groot_price),
#                 end=False
#             )
# 
#     @classmethod
#     def log_results(cls, reports):
#         total = len(reports)
#         if not total:
#             cls.log(cls.UNDERLINE, cls.BLUE, cls.WARNING, 'No tests found.')
#             return 0
# 
#         success = len(tuple(filter(attrgetter('success'), reports)))
#         skipped = len(tuple(filter(lambda r: r.success is None, reports)))
# 
#         cls.log(
#             cls.UNDERLINE,
#             cls.BOLD,
#             'RESULTS:',
#             cls.END,
#             cls.BOLD,
#             ' {:.3f}%'.format((float(success) / (total - skipped)) * 100),
#             cls.END,
#             ' ({}/{})\n'.format(success, total - skipped),
#             cls.END,
#             cls.BOLD,
#             ''.join(
#                 (
#                     ((cls.FAIL + '×', cls.GREEN + '.')[report.success]
#                      if report.success is not None
#                      else cls.BLUE + '_')
#                 ) + ('\n' if not (i % cls.console_width) else '')
#                 for i, report in enumerate(reports, start=1)),
#             ''
#         )
#         return bool(total - success)
# 
#     @classmethod
#     def _log_buffer(cls, stream=sys.stderr):
#         for to_log in cls._test_case_buffer or ():
#             stream.write(to_log)


# Path: ifj2017/test/loader.py
import json
import os
import os.path as path
from glob import iglob
from operator import attrgetter
from os.path import basename
from typing import Set, Tuple, Optional
from .base import TestInfo
from .logger import TestLogger


        return sorted(
            tests,
            key=lambda test: (len(test.name), test.name)
        )

    def _load_json_file(self, section_dir):
        data = self.load_file(
            path.join(section_dir, 'tests.json'),
            allow_fail=True
        )
        if not data:
            return {}
        try:
            return json.loads(data)
        except (json.JSONDecodeError, TypeError) as e:
            TestLogger.log_warning(
                "File {} is not valid json to load ({}).".format(path.join(section_dir, 'tests.json'), e)
            )
            return {}

    def _load_compact_tests(self, section_dir, data):
        cases = []
        extensions = tuple(data.get('extensions', ()))
        try:
            for i, test_case in enumerate(data.get('tests', ())):
                name = test_case.get('name')
                code = test_case.get('code')

                if name and code:

                    TestLogger.log_warning(