[tests] Refactor setting up complex I/O mocking for modules
Modules now only have to have a single setup/teardown line in their code to fully set up the I/O part of a test.
This commit is contained in:
parent
69dceca7d0
commit
00849aa4fa
5 changed files with 35 additions and 77 deletions
|
@ -3,15 +3,36 @@
|
|||
import mock
|
||||
import json
|
||||
import shlex
|
||||
import random
|
||||
import subprocess
|
||||
|
||||
from bumblebee.input import I3BarInput
|
||||
from bumblebee.output import Widget
|
||||
|
||||
import random
|
||||
from bumblebee.config import Config
|
||||
|
||||
def rand(cnt):
|
||||
return "".join(random.choice("abcdefghijklmnopqrstuvwxyz0123456789") for i in range(cnt))
|
||||
|
||||
def setup_test(test, Module):
|
||||
test._stdin, test._select, test.stdin, test.select = epoll_mock("bumblebee.input")
|
||||
|
||||
test.popen = MockPopen()
|
||||
|
||||
test.config = Config()
|
||||
test.input = I3BarInput()
|
||||
test.engine = mock.Mock()
|
||||
test.engine.input = test.input
|
||||
test.input.need_event = True
|
||||
test.module = Module(engine=test.engine, config={ "config": test.config })
|
||||
for widget in test.module.widgets():
|
||||
widget.link_module(test.module)
|
||||
test.anyWidget = widget
|
||||
|
||||
def teardown_test(test):
|
||||
test._stdin.stop()
|
||||
test._select.stop()
|
||||
test.popen.cleanup()
|
||||
|
||||
def epoll_mock(module=""):
|
||||
if len(module) > 0: module = "{}.".format(module)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue