Exemplo n.º 1
0
def test_func_with_parser(tmpworkdir, mocker, initial, expected):
    # setup
    mocker.patch('sys.argv', ['foo.py', *initial])
    mocker.patch('watchgod.cli.set_start_method')
    mocker.patch('watchgod.cli.sys.stdin.fileno', side_effect=AttributeError)
    mock_run_process = mocker.patch('watchgod.cli.run_process')
    # test
    assert not tmpworkdir.join('sentinel').exists()
    cli('tests.test_cli.with_parser',
        str(tmpworkdir))  # run til mock_run_process
    run_function('tests.test_cli.with_parser',
                 None)  # run target function once
    file = tmpworkdir.join('sentinel')
    mock_run_process.assert_called_once_with(
        Path(str(tmpworkdir)),
        run_function,
        args=('tests.test_cli.with_parser', None),
        callback=callback)
    assert file.exists()
    assert file.read_text(encoding='utf-8') == ' '.join(expected)
Exemplo n.º 2
0
def test_run_function_tty(tmpworkdir):
    # could this cause problems by changing sys.stdin?
    assert not tmpworkdir.join('sentinel').exists()
    run_function('tests.test_cli.foobar', '/dev/tty')
    assert tmpworkdir.join('sentinel').exists()
Exemplo n.º 3
0
def test_run_function(tmpworkdir):
    assert not tmpworkdir.join('sentinel').exists()
    run_function('tests.test_cli.foobar', None)
    assert tmpworkdir.join('sentinel').exists()