1###############################################################################
2#
3# The MIT License (MIT)
4#
5# Copyright (c) Crossbar.io Technologies GmbH
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24#
25###############################################################################
26
27import txaio
28
29from util import run_once
30
31
32def test_default_resolve(framework):
33    f = txaio.create_future()
34    results = []
35
36    def cb(f):
37        results.append(f)
38    txaio.add_callbacks(f, cb, None)
39    txaio.resolve(f)
40
41    run_once()
42
43    assert len(results) == 1
44    assert results[0] is None
45
46
47def test_callback(framework):
48    f = txaio.create_future()
49    results = []
50
51    def cb(f):
52        results.append(f)
53    txaio.add_callbacks(f, cb, None)
54    txaio.resolve(f, "it worked")
55
56    run_once()
57
58    assert len(results) == 1
59    assert results[0] == "it worked"
60
61
62def test_immediate_result(framework):
63    f = txaio.create_future_success("it worked")
64    results = []
65
66    def cb(f):
67        results.append(f)
68    txaio.add_callbacks(f, cb, None)
69
70    run_once()
71
72    assert len(results) == 1
73    assert results[0] == "it worked"
74