# Path: dev_tools/env_tools.py
# def get_unhidden_ungenerated_python_files(directory: str) -> Iterable[str]:
# def create_virtual_env(venv_path: str,
#                        requirements_paths: Iterable[str],
#                        python_path: str,
#                        verbose: bool) -> None:
# def prepare_temporary_test_environment(
#         destination_directory: str,
#         repository: GithubRepository,
#         pull_request_number: Optional[int],
#         verbose: bool,
#         env_name: str = '.test_virtualenv',
#         python_path: str = '/usr/bin/python3.5',
#         commit_ids_known_callback: Callable[[PreparedEnv], None] = None
# ) -> PreparedEnv:
# 
# Path: dev_tools/shell_tools.py
# BOLD = 1
# DIM = 2
# RED = 31
# GREEN = 32
# YELLOW = 33
# def highlight(text: str, color_code: int, bold: bool=False) -> str:
#     def __init__(self, out_pipe: Optional[IO[str]] = None) -> None:
# async def _async_forward(async_chunks: collections.AsyncIterable,
#                          out: Optional[Union[TeeCapture, IO[str]]]
#                          ) -> Optional[str]:
# async def _async_wait_for_process(
#         future_process: Any,
#         out: Optional[Union[TeeCapture, IO[str]]] = sys.stdout,
#         err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr
# ) -> CommandOutput:
# def abbreviate_command_arguments_after_switches(
#         cmd: Tuple[str, ...]) -> Tuple[str, ...]:
# def run_cmd(*cmd: Optional[str],
#             out: Optional[Union[TeeCapture, IO[str]]] = sys.stdout,
#             err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr,
#             raise_on_fail: bool = True,
#             log_run_to_stderr: bool = True,
#             abbreviate_non_option_arguments: bool = False,
#             **kwargs
#             ) -> CommandOutput:
# def run_shell(cmd: str,
#               out: Optional[Union[TeeCapture, IO[str]]] = sys.stdout,
#               err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr,
#               raise_on_fail: bool = True,
#               log_run_to_stderr: bool = True,
#               **kwargs
#               ) -> CommandOutput:
# def output_of(*cmd: Optional[str], **kwargs) -> str:
# class TeeCapture:
# 
# Path: dev_tools/check.py
# class CheckResult:
# class Check(metaclass=abc.ABCMeta):
#     def __init__(self,
#                  check: 'Check',
#                  success: bool,
#                  message: str,
#                  unexpected_error: Optional[Exception]) -> None:
#     def __str__(self):
#     def __init__(self, *dependencies):
#     def command_line_switch(self) -> str:
#     def context(self) -> str:
#     def perform_check(self,
#                       env: env_tools.PreparedEnv,
#                       verbose: bool) -> Tuple[bool, str]:
#     def run(self,
#             env: env_tools.PreparedEnv,
#             verbose: bool,
#             previous_failures: Set['Check']) -> CheckResult:
#     def pick_env_and_run_and_report(self,
#                                     env: env_tools.PreparedEnv,
#                                     verbose: bool,
#                                     previous_failures: Set['Check']
#                                     ) -> CheckResult:


from typing import cast
from dev_tools import env_tools, shell_tools, check
import os
import re
import sys

class TestAndPrepareCoverageCheck(check.Check):
    """Checks if the code passes unit tests.

    As a side effect, produces coverage files used by the coverage checks.
    """

    def command_line_switch(self):
        return 'pytest'

    def context(self):
        return 'pytest'

    def perform_check(self, env: env_tools.PreparedEnv, verbose: bool):
        do_coverage = True
        base_path = cast(str, env.destination_directory)
        rc_path = os.path.join(base_path,
                               'dev_tools',
                               'conf',
                               '.coveragerc')
        target_path = base_path
        result = shell_tools.run_cmd(
            env.bin('pytest'),
            target_path,
            None if verbose else '--quiet',
            *([
                  '--cov',
                  '--cov-report=annotate',
                  '--cov-config={}'.format(rc_path)
              ] if do_coverage else []),

# Path: dev_tools/env_tools.py
# def get_unhidden_ungenerated_python_files(directory: str) -> Iterable[str]:
# def create_virtual_env(venv_path: str,
#                        requirements_paths: Iterable[str],
#                        python_path: str,
#                        verbose: bool) -> None:
# def prepare_temporary_test_environment(
#         destination_directory: str,
#         repository: GithubRepository,
#         pull_request_number: Optional[int],
#         verbose: bool,
#         env_name: str = '.test_virtualenv',
#         python_path: str = '/usr/bin/python3.5',
#         commit_ids_known_callback: Callable[[PreparedEnv], None] = None
# ) -> PreparedEnv:
# 
# Path: dev_tools/shell_tools.py
# BOLD = 1
# DIM = 2
# RED = 31
# GREEN = 32
# YELLOW = 33
# def highlight(text: str, color_code: int, bold: bool=False) -> str:
#     def __init__(self, out_pipe: Optional[IO[str]] = None) -> None:
# async def _async_forward(async_chunks: collections.AsyncIterable,
#                          out: Optional[Union[TeeCapture, IO[str]]]
#                          ) -> Optional[str]:
# async def _async_wait_for_process(
#         future_process: Any,
#         out: Optional[Union[TeeCapture, IO[str]]] = sys.stdout,
#         err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr
# ) -> CommandOutput:
# def abbreviate_command_arguments_after_switches(
#         cmd: Tuple[str, ...]) -> Tuple[str, ...]:
# def run_cmd(*cmd: Optional[str],
#             out: Optional[Union[TeeCapture, IO[str]]] = sys.stdout,
#             err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr,
#             raise_on_fail: bool = True,
#             log_run_to_stderr: bool = True,
#             abbreviate_non_option_arguments: bool = False,
#             **kwargs
#             ) -> CommandOutput:
# def run_shell(cmd: str,
#               out: Optional[Union[TeeCapture, IO[str]]] = sys.stdout,
#               err: Optional[Union[TeeCapture, IO[str]]] = sys.stderr,
#               raise_on_fail: bool = True,
#               log_run_to_stderr: bool = True,
#               **kwargs
#               ) -> CommandOutput:
# def output_of(*cmd: Optional[str], **kwargs) -> str:
# class TeeCapture:
# 
# Path: dev_tools/check.py
# class CheckResult:
# class Check(metaclass=abc.ABCMeta):
#     def __init__(self,
#                  check: 'Check',
#                  success: bool,
#                  message: str,
#                  unexpected_error: Optional[Exception]) -> None:
#     def __str__(self):
#     def __init__(self, *dependencies):
#     def command_line_switch(self) -> str:
#     def context(self) -> str:
#     def perform_check(self,
#                       env: env_tools.PreparedEnv,
#                       verbose: bool) -> Tuple[bool, str]:
#     def run(self,
#             env: env_tools.PreparedEnv,
#             verbose: bool,
#             previous_failures: Set['Check']) -> CheckResult:
#     def pick_env_and_run_and_report(self,
#                                     env: env_tools.PreparedEnv,
#                                     verbose: bool,
#                                     previous_failures: Set['Check']
#                                     ) -> CheckResult:


# Path: dev_tools/check_pytest_with_coverage.py
from typing import cast
from dev_tools import env_tools, shell_tools, check
import os
import re
import sys


class TestAndPrepareCoverageCheck(check.Check):
    """Checks if the code passes unit tests.

    As a side effect, produces coverage files used by the coverage checks.
    """

    def command_line_switch(self):
        return 'pytest'

    def context(self):
        return 'pytest'

    def perform_check(self, env: env_tools.PreparedEnv, verbose: bool):
        do_coverage = True
        base_path = cast(str, env.destination_directory)
        rc_path = os.path.join(base_path,
                               'dev_tools',
                               'conf',
                               '.coveragerc')
        target_path = base_path
        result = shell_tools.run_cmd(
            env.bin('pytest'),
            target_path,
            None if verbose else '--quiet',
            *([
                  '--cov',
                  '--cov-report=annotate',
                  '--cov-config={}'.format(rc_path)
              ] if do_coverage else []),

            out=shell_tools.TeeCapture(sys.stdout),