Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runner unit tests #62

Merged
merged 2 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions mite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from .exceptions import MiteError # noqa: F401
from .context import Context
from .runner import RunnerConfig
import mite.utils


Expand All @@ -24,8 +23,8 @@

# TODO: move to test.py?
def test_context(extensions=('http',), **config):
runner_config = RunnerConfig()
runner_config._update(config.items())
runner_config = {}
runner_config.update(config.items())
c = Context(print, runner_config)
return c

Expand Down
41 changes: 5 additions & 36 deletions mite/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
logger = logging.getLogger(__name__)


class RunnerControllerTransportExample:
class RunnerControllerTransportExample: # pragma: nocover
async def hello(self):
"""Returns:
runner_id
Expand Down Expand Up @@ -40,37 +40,6 @@ async def bye(self, runner_id):
pass


class RunnerConfig:
def __init__(self):
self._config = {}

def __repr__(self):
return "RunnerConfig({})".format(", ".join(["{}={}".format(k, v) for k, v in self._config.items()]))

def _update(self, kv_list):
for k, v in kv_list:
self._config[k] = v

def get(self, key, default=None):
try:
return self._config[key]
except KeyError:
if default is not None:
return default
else:
raise

def get_fallback(self, *keys, default=None):
for key in keys:
try:
return self._config[key]
except KeyError:
pass
if default is not None:
return default
raise KeyError("None of {} found".format(keys))


class Runner:
def __init__(self, transport, msg_sender, loop_wait_min=0.01, loop_wait_max=0.5, max_work=None, loop=None,
debug=False):
Expand Down Expand Up @@ -106,9 +75,9 @@ def should_stop(self):

async def run(self):
context_id_gen = count(1)
config = RunnerConfig()
config = {}
runner_id, test_name, config_list = await self._transport.hello()
config._update(config_list)
config.update(config_list)
logger.debug("Entering run loop")
_completed = []

Expand Down Expand Up @@ -144,7 +113,7 @@ async def wait():
while not self._stop:
work, config_list, self._stop = await self._transport.request_work(runner_id, self._current_work(),
completed_data_ids, self._max_work)
config._update(config_list)
config.update(config_list)
for num, (scenario_id, scenario_data_id, journey_spec, args) in enumerate(work):
id_data = {
'test': test_name,
Expand All @@ -164,7 +133,7 @@ async def wait():
while self._current_work():
_, config_list, _ = await self._transport.request_work(runner_id, self._current_work(),
completed_data_ids, 0)
config._update(config_list)
config.update(config_list)
completed_data_ids = await wait()
await self._transport.request_work(runner_id, self._current_work(), completed_data_ids, 0)
await self._transport.bye(runner_id)
Expand Down
3 changes: 0 additions & 3 deletions test/mocks/mock_runner_conf.py

This file was deleted.

6 changes: 3 additions & 3 deletions test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def test_send():
config = RunnerConfigMock()
config = {}
sender = SenderMock()
ctx = Context(sender.send, config)

Expand All @@ -17,7 +17,7 @@ def test_send():


def test_start_transaction():
config = RunnerConfigMock()
config = {}
sender = SenderMock()
ctx = Context(sender.send, config)

Expand All @@ -30,7 +30,7 @@ def test_start_transaction():


def test_end_transaction():
config = RunnerConfigMock()
config = {}
sender = SenderMock()
ctx = Context(sender.send, config)

Expand Down