work in progress ...

This commit is contained in:
Romain Dorgueil
2016-12-09 08:01:04 +01:00
parent 854ef4e2bf
commit 90d3b6235b
24 changed files with 822 additions and 85 deletions

43
tests/core/test_graph.py Normal file
View File

@ -0,0 +1,43 @@
import pytest
from bonobo.core.graph import Graph
from bonobo.core.tokens import BEGIN
identity = lambda x: x
def test_graph_outputs_of():
g = Graph()
# default graph only node
assert len(g.outputs_of(BEGIN)) == 0
# unexisting node
with pytest.raises(KeyError):
g.outputs_of(0)
# create node
assert len(g.outputs_of(0, create=True)) == 0
assert len(g.outputs_of(0)) == 0
def test_graph_add_component():
g = Graph()
assert len(g.components) == 0
g.add_component(identity)
assert len(g.components) == 1
g.add_component(identity)
assert len(g.components) == 2
def test_graph_add_chain():
g = Graph()
assert len(g.components) == 0
g.add_chain(identity, identity, identity)
assert len(g.components) == 3
assert len(g.outputs_of(BEGIN)) == 1

66
tests/core/test_io.py Normal file
View File

@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
#
# Copyright 2012-2014 Romain Dorgueil
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from queue import Empty
import pytest
from bonobo.core.errors import InactiveWritableError, InactiveReadableError
from bonobo.core.io import Input
from bonobo.core.tokens import BEGIN, END
def test_input_runlevels():
q = Input()
# Before BEGIN, noone should be able to write in an Input queue.
assert not q.alive
with pytest.raises(InactiveWritableError):
q.put('hello, unborn queue.')
# Begin
q.put(BEGIN)
assert q.alive and q._runlevel == 1
q.put('foo')
# Second Begin
q.put(BEGIN)
assert q.alive and q._runlevel == 2
q.put('bar')
q.put(END)
# FIFO
assert q.get() == 'foo'
assert q.get() == 'bar'
# self.assertEqual(q.alive, False) XXX queue don't know it's dead yet, but it is ...
# Async get raises Empty (End is not returned)
with pytest.raises(Empty):
q.get(block=False)
assert q.alive
# Before killing, let's slide some data in.
q.put('baz')
# Now kill the queue...
q.put(END)
with pytest.raises(InactiveWritableError):
q.put('foo')
# Still can get remaining data
assert q.get() == 'baz'
with pytest.raises(InactiveReadableError):
q.get()

14
tests/core/test_stats.py Normal file
View File

@ -0,0 +1,14 @@
from bonobo.core.stats import WithStatistics
class MyThingWithStats(WithStatistics):
def get_stats(self, *args, **kwargs):
return (
('foo', 42),
('bar', 69),
)
def test_with_statistics():
o = MyThingWithStats()
assert o.get_stats_as_string() == 'foo=42 bar=69'

View File

@ -0,0 +1,6 @@
from bonobo.core.tokens import Token
def test_token_repr():
t = Token('Acme')
assert repr(t) == '<Acme>'