Beispiel #1
0
    def _get_solution_provider_repository(self) -> SolutionProviderRepository:
        from crashtest.solution_providers.solution_provider_repository import (
            SolutionProviderRepository, )

        from poetry.mixology.solutions.providers.python_requirement_solution_provider import (  # noqa: E501
            PythonRequirementSolutionProvider, )

        repository = SolutionProviderRepository()
        repository.register_solution_providers(
            [PythonRequirementSolutionProvider])

        return repository
Beispiel #2
0
    def __init__(self,
                 name=None,
                 version=None):  # type: (Optional[str], Optional[str]) -> None
        self._name = name
        self._version = version
        self._display_name = None
        self._help = None
        self._command_configs = []  # type: List[CommandConfig]
        self._catch_exceptions = True
        self._terminate_after_run = True
        self._command_resolver = None
        self._io_factory = None
        self._debug = False
        self._style_set = None
        self._dispatcher = None
        self._pre_resolve_hooks = []  # type: List[Callable]

        if PY36:
            from crashtest.solution_providers.solution_provider_repository import (
                SolutionProviderRepository, )

            self._solution_provider_repository = SolutionProviderRepository()
        else:
            self._solution_provider_repository = None

        super(ApplicationConfig, self).__init__()
Beispiel #3
0
def test_render_supports_solutions():
    from crashtest.contracts.provides_solution import ProvidesSolution
    from crashtest.contracts.base_solution import BaseSolution
    from crashtest.solution_providers.solution_provider_repository import (
        SolutionProviderRepository,
    )

    class CustomError(ProvidesSolution, Exception):
        @property
        def solution(self):
            solution = BaseSolution("Solution Title.", "Solution Description")
            solution.documentation_links.append("https://example.com")
            solution.documentation_links.append("https://example2.com")

            return solution

    io = BufferedIO()

    def call():
        raise CustomError("Error with solution")

    with pytest.raises(CustomError) as e:
        call()

    trace = ExceptionTrace(
        e.value, solution_provider_repository=SolutionProviderRepository()
    )

    trace.render(io)

    expected = """
  CustomError

  Error with solution

  at {}:433 in call
      429│ 
      430│     io = BufferedIO()
      431│ 
      432│     def call():
    → 433│         raise CustomError("Error with solution")
      434│ 
      435│     with pytest.raises(CustomError) as e:
      436│         call()
      437│ 

  • Solution Title: Solution Description
    https://example.com,
    https://example2.com
""".format(
        trace._get_relative_file_path(__file__),
    )

    assert expected == io.fetch_output()
Beispiel #4
0
def test_render_falls_back_on_ascii_symbols():
    from crashtest.contracts.base_solution import BaseSolution
    from crashtest.contracts.provides_solution import ProvidesSolution
    from crashtest.solution_providers.solution_provider_repository import (
        SolutionProviderRepository, )

    class CustomError(ProvidesSolution, Exception):
        @property
        def solution(self):
            solution = BaseSolution("Solution Title.", "Solution Description")
            solution.documentation_links.append("https://example.com")
            solution.documentation_links.append("https://example2.com")

            return solution

    io = BufferedIO(supports_utf8=False)

    def call():
        raise CustomError("Error with solution")

    with pytest.raises(CustomError) as e:
        call()

    trace = ExceptionTrace(
        e.value, solution_provider_repository=SolutionProviderRepository())

    trace.render(io)

    expected = """
  CustomError

  Error with solution

  at {}:493 in call
      489| 
      490|     io = BufferedIO(supports_utf8=False)
      491| 
      492|     def call():
    > 493|         raise CustomError("Error with solution")
      494| 
      495|     with pytest.raises(CustomError) as e:
      496|         call()
      497| 

  * Solution Title: Solution Description
    https://example.com,
    https://example2.com
""".format(trace._get_relative_file_path(__file__), )

    assert expected == io.fetch_output()
def test_it_can_find_solutions():
    repository = SolutionProviderRepository()

    repository.register_solution_provider(ExceptionSolutionProvider)

    solutions = repository.get_solutions_for_exception(ExceptionProvidingException())

    assert 2 == len(solutions)
    solution1 = solutions[0]
    solution2 = solutions[1]
    assert "A simple solution" == solution1.solution_title
    assert "An exception solution" == solution2.solution_title
    assert "A simple solution description" == solution1.solution_description
    assert "An exception solution description" == solution2.solution_description
    assert ["https://example.com"] == solution1.documentation_links
    assert 0 == len(solution2.documentation_links)

    solutions = repository.get_solutions_for_exception(ExceptionWhichIsSolution())

    assert 1 == len(solutions)
    solution1 = solutions[0]
    assert "A solution" == solution1.solution_title
    assert "A solution description" == solution1.solution_description
    assert ["https://foo.bar"] == solution1.documentation_links
def test_providers_can_be_passed_to_constructor():
    repository = SolutionProviderRepository()

    assert 0 == len(repository._solution_providers)
def test_it_has_no_provider_by_default():
    repository = SolutionProviderRepository()

    assert 0 == len(repository._solution_providers)