Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.

Commit d8d9d0c

Browse files
committed
Tests
1 parent a20fe25 commit d8d9d0c

21 files changed

+299
-107
lines changed
File renamed without changes.

tests/abstracts/test_job.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from zenaton.abstracts.job import Job
2+
3+
4+
def test_has_handle():
5+
assert hasattr(Job(), 'handle')

tests/abstracts/test_task.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from zenaton.abstracts.task import Task
2+
3+
4+
def test_has_handle():
5+
assert hasattr(Task(), 'handle')

tests/abstracts/test_workflow.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from zenaton.abstracts.workflow import Workflow
2+
3+
4+
def test_has_handle():
5+
assert hasattr(Workflow(), 'handle')

tests/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
1+
from .fixtures.fixtures import dummy_object
2+
from .fixtures.fixture_client import client
3+
from .fixtures.fixture_task import task0, task1, task2, task3
4+
from .fixtures.fixture_workflow import sequential_workflow, version_workflow
5+
from .fixtures.fixture_event import my_event
6+
from .fixtures.fixture_engine import engine
7+
from .fixtures.fixture_wait import wait, wait_event

tests/fixtures/fake_task.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/fixtures/fake_workflow.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/fixtures/fixture_builder.py

Whitespace-only changes.

tests/fixtures/fake_client.py renamed to tests/fixtures/fixture_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@
2222

2323

2424
@pytest.fixture
25-
def FakeClient():
25+
def client():
2626
return Client(app_id, api_token, app_env)
27-
28-
29-
client = Client(app_id, api_token, app_env)

tests/fixtures/fixture_engine.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pytest
2+
3+
from zenaton.engine import Engine
4+
from zenaton.client import Client
5+
6+
7+
@pytest.fixture
8+
def engine():
9+
Client()
10+
return Engine()

tests/fixtures/fixture_event.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
3+
from zenaton.abstracts.event import Event
4+
5+
6+
class MyEvent(Event):
7+
pass
8+
9+
10+
@pytest.fixture
11+
def my_event():
12+
return MyEvent()

tests/fixtures/fixture_task.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import time
2+
3+
import pytest
4+
5+
from zenaton.abstracts.task import Task
6+
from zenaton.traits.zenatonable import Zenatonable
7+
8+
9+
class Task0(Task, Zenatonable):
10+
11+
def handle(self):
12+
print('Task 0 starts')
13+
time.sleep(3)
14+
print('Task 0 ends')
15+
return 0
16+
17+
18+
@pytest.fixture
19+
def task0():
20+
return Task0()
21+
22+
23+
class Task1(Task, Zenatonable):
24+
25+
def handle(self):
26+
print('Task 1 starts')
27+
time.sleep(5)
28+
print('Task 1 ends')
29+
return 1
30+
31+
32+
@pytest.fixture
33+
def task1():
34+
return Task1()
35+
36+
37+
class Task2(Task, Zenatonable):
38+
39+
def handle(self):
40+
print('Task 2 starts')
41+
time.sleep(7)
42+
print('Task 2 ends')
43+
return 2
44+
45+
46+
@pytest.fixture
47+
def task2():
48+
return Task2()
49+
50+
51+
class Task3(Task, Zenatonable):
52+
53+
def handle(self):
54+
print('Task 3 starts')
55+
time.sleep(9)
56+
print('Task 3 ends')
57+
return 3
58+
59+
60+
@pytest.fixture
61+
def task3():
62+
return Task3()

tests/fixtures/fixture_wait.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
from zenaton.tasks.wait import Wait
4+
from .fixture_event import MyEvent
5+
6+
7+
@pytest.fixture
8+
def wait():
9+
return Wait()
10+
11+
12+
@pytest.fixture
13+
def wait_event():
14+
return Wait(MyEvent)

tests/fixtures/fixture_workflow.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import pytest
2+
3+
from .fixture_task import task0, task1, task2, task3
4+
from .fixture_event import MyEvent
5+
6+
from zenaton.abstracts.workflow import Workflow
7+
from zenaton.traits.zenatonable import Zenatonable
8+
from zenaton.workflows.version import Version
9+
10+
11+
class SequentialWorkflow(Workflow, Zenatonable):
12+
13+
def __init__(self):
14+
self.id_ = 'MyTestWorkflowId'
15+
16+
def handle(self):
17+
18+
a = task0.execute()
19+
20+
if a > 0:
21+
task1.execute()
22+
else:
23+
task2.execute()
24+
25+
task3.execute()
26+
27+
def id(self):
28+
return self.id_
29+
30+
def set_id(self, id_):
31+
self.id_ = id_
32+
33+
def on_event(self, event):
34+
if issubclass(MyEvent, type(event)):
35+
return True
36+
else:
37+
return False
38+
39+
40+
41+
@pytest.fixture
42+
def sequential_workflow():
43+
return SequentialWorkflow()
44+
45+
46+
class VersionWorkflow(Version):
47+
48+
def versions(self):
49+
return [SequentialWorkflow, ]
50+
51+
52+
@pytest.fixture
53+
def version_workflow():
54+
return VersionWorkflow()

tests/fixtures/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ class DummyClass:
66

77

88
@pytest.fixture
9-
def DummyObject():
9+
def dummy_object():
1010
return DummyClass()

tests/query/test_builder.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
import pytest
2-
3-
from zenaton.query.builder import Builder
4-
5-
@pytest.mark.usefixtures("FakeSequentialWorkflow")
6-
def test_test(FakeSequentialWorkflow):
7-
assert hasattr(FakeSequentialWorkflow, 'handle')
8-

tests/tasks/__init__.py

Whitespace-only changes.

tests/tasks/test_wait.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
3+
from zenaton.tasks.wait import Wait
4+
from zenaton.exceptions import ExternalError
5+
from ..fixtures.fixture_event import MyEvent
6+
7+
8+
def test_init():
9+
with pytest.raises(ExternalError):
10+
Wait(1)
11+
12+
13+
@pytest.mark.usefixtures("wait")
14+
def test_has_handle(wait):
15+
assert hasattr(wait, 'handle')
16+
17+
18+
@pytest.mark.usefixtures("wait", "wait_event", "my_event")
19+
def test_valid_param(wait, my_event):
20+
assert not wait.valid_param(1)
21+
assert wait.valid_param(None)
22+
assert wait.valid_param("foo")
23+
assert wait.valid_param(MyEvent)
24+
25+
26+
@pytest.mark.usefixtures("wait", "my_event")
27+
def test_event_class(wait, my_event):
28+
assert not wait.event_class("foo")
29+
assert wait.event_class(MyEvent)

0 commit comments

Comments
 (0)