Exemplo n.º 1
0
def test_standard(capsys):
    t = Task(print, args=('hello, world!', ), kwargs={'end': ''}).start()
    t.join()
    assert t.state == STATE_FINISHED
    captured = capsys.readouterr()
    assert captured.err == ''
    assert captured.out == 'hello, world!'
Exemplo n.º 2
0
def test_action_start(capsys):
    # without delay
    t = Task(
        print,
        args=('started', ),
        kwargs={'end': ' '},
    ) + Task(print,
             args=('hello, world!', ),
             kwargs={'end': ''},
             action_stop=print,
             args_stop=(' stopped', ),
             kwargs_stop={'end': ''})
    t.start()
    t.join()
    assert t.state == STATE_FINISHED
    captured = capsys.readouterr()
    assert captured.err == ''
    assert captured.out == 'started hello, world!'

    # with delay
    t.start(.1)
    sleep(.05)
    assert t.state == STATE_TO_START
    t.stop().join()
    assert t.state == STATE_STOPPED
    captured = capsys.readouterr()
    assert captured.err == ''
    assert captured.out == ''
    t.cont().join()
    captured = capsys.readouterr()
    assert t.state == STATE_FINISHED
    assert captured.err == ''
    assert captured.out == 'started hello, world!'
Exemplo n.º 3
0
def test_action_final(capsys):
    t = Task(print, args=('hello, world!', ), kwargs={'end': ''}) + Task(
        print, args=(' finished', ), kwargs={'end': ''})
    t.start()
    t.join()
    captured = capsys.readouterr()
    assert t.state == STATE_FINISHED
    assert captured.err == ''
    assert captured.out == 'hello, world! finished'
Exemplo n.º 4
0
def test_action_stop(capsys):
    t = Task(print,
             args=('hello, world!', ),
             kwargs={'end': ''},
             duration=.1,
             action_stop=print,
             args_stop=(' stopped', ),
             kwargs_stop={'end': ''}) + Task(
                 print, args=(' finished', ), kwargs={'end': ''})
    t.start()
    sleep(.05)
    t.stop()
    t.join()
    captured = capsys.readouterr()
    assert t.state == STATE_STOPPED
    assert captured.err == ''
    assert captured.out == 'hello, world! stopped'
Exemplo n.º 5
0
def test_action_cont(capsys):
    # with duration
    t = Task(print,
             args=('hello, world!', ),
             kwargs={'end': ''},
             duration=.1,
             action_stop=print,
             args_stop=(' stopped', ),
             kwargs_stop={'end': ''},
             action_cont=print,
             args_cont=(' continued', ),
             kwargs_cont={'end': ''}) + Task(
                 print, args=(' finished', ), kwargs={'end': ''})
    t.start().stop()
    t.join()
    assert t.state == STATE_STOPPED
    t.cont().join()
    captured = capsys.readouterr()
    assert t.state == STATE_FINISHED
    assert captured.err == ''
    assert captured.out == 'hello, world! stopped continued finished'

    # without duration
    t = Task(print,
             args=('hello, world!', ),
             kwargs={'end': ''},
             action_stop=print,
             args_stop=(' stopped', ),
             kwargs_stop={'end': ''},
             action_cont=print,
             args_cont=(' continued', ),
             kwargs_cont={'end': ''}) + Task(
                 print, args=(' finished', ), kwargs={'end': ''})
    t.start().stop()
    t.join()
    assert t.state == STATE_FINISHED
    t.cont().join()
    captured = capsys.readouterr()
    assert t.state == STATE_FINISHED
    assert captured.err == ''
    assert captured.out == 'hello, world! finished'