-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from childsish/1.0.5
1 0 6
- Loading branch information
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from .connection.input import Input | ||
from .connection.output import Output | ||
from .connection.connection_set import ConnectionSet | ||
|
||
|
||
class TestHelper: | ||
def __init__(self, stream): | ||
ins = [Input(in_) for in_ in stream.ins] | ||
outs = [Output(out) for out in stream.outs] | ||
self.ins = ConnectionSet(ins) | ||
self.outs = ConnectionSet(outs) | ||
self.stream = stream | ||
|
||
def run(self, ins): | ||
for key, value in ins.items(): | ||
self.ins[key].clear() | ||
self.ins[key].extend(value) | ||
outs = {out.name: [] for out in self.outs} | ||
while self.stream.run(self.ins, self.outs): | ||
for out in self.outs: | ||
outs[out.name].extend(out.entities) | ||
out.clear() | ||
return outs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import unittest | ||
|
||
from mimo import Stream | ||
from mimo.test_helper import TestHelper | ||
|
||
|
||
class TestTestHelper(unittest.TestCase): | ||
def test_run(self): | ||
stream = Stream(ins=['a'], outs=['b'], fn=fn) | ||
helper = TestHelper(stream) | ||
|
||
self.assertEqual({'b': [2, 4, 6, 8, 10, 12, 14, 16, 18, 0]}, | ||
helper.run({'a': [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]})) | ||
|
||
|
||
def fn(ins, outs, state): | ||
while len(ins.a) > 0: | ||
if not outs.b.push(2 * ins.a.pop()): | ||
return True | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |