Skip to content
Snippets Groups Projects
Commit b5c85c71 authored by Georges Racinet's avatar Georges Racinet
Browse files

testing.context.FakeContextAborter: extracted from several tests

It was already duplicated between `test_errors` and `test_linguist`
and will be useful in other cases. We had to rename it a bit
to make it more explicit out of the context of a given test module.
parent 20ebc840
No related branches found
No related tags found
3 merge requests!204Making Heptapod 0.40 the new oldstable,!203Merge stable branch into default,!200Repository.FindLicense initial implementation
......@@ -51,3 +51,31 @@
set_details = fake_impl
set_trailing_metadata = fake_impl
time_remaining = fake_impl
class FakeContextAbort(RuntimeError):
pass
class FakeContextAborter(FakeServicerContext):
"""A fake context that is good enough to test various `abort()` cases.
"""
_trailing_metadata = _code = _details = None
def set_trailing_metadata(self, metadata):
self._trailing_metadata = metadata
def trailing_metadata(self):
return self._trailing_metadata
def code(self):
return self._code
def details(self):
return self._details
def abort(self, code, details):
self._code = code
self._details = details
raise FakeContextAbort()
......@@ -19,7 +19,9 @@
from ..errors import (
structured_abort
)
from ..testing.context import FakeServicerContext
from ..testing.context import (
FakeContextAborter as FakeContext,
)
StatusCode = grpc.StatusCode
......@@ -35,28 +37,6 @@
assert re.search('https://.*/-/issues/1234567', exc.details()) is not None
class FakeContext(FakeServicerContext):
_trailing_metadata = _code = _details = None
def set_trailing_metadata(self, metadata):
self._trailing_metadata = metadata
def trailing_metadata(self):
return self._trailing_metadata
def code(self):
return self._code
def details(self):
return self._details
def abort(self, code, details):
self._code = code
self._details = details
raise RuntimeError('abort-from-tests')
def test_structured_abort():
context = FakeContext()
......
......@@ -10,33 +10,10 @@
from ..linguist import (
language_stats,
)
from ..testing.context import FakeServicerContext
class FakeContextAbort(RuntimeError):
pass
class FakeContext(FakeServicerContext):
_trailing_metadata = _code = _details = None
def set_trailing_metadata(self, metadata):
self._trailing_metadata = metadata
def trailing_metadata(self):
return self._trailing_metadata
def code(self):
return self._code
def details(self):
return self._details
def abort(self, code, details):
self._code = code
self._details = details
raise FakeContextAbort()
from ..testing.context import (
FakeContextAborter as FakeContext,
FakeContextAbort,
)
def test_tokei_subprocesss_errors(tmpdir):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment