예제 #1
0
def test_if_file_created():
    """Check whether the process really created the given file."""
    assert os.path.isfile(filename) is False
    executor = PidExecutor(process, filename)
    executor.start()
    assert os.path.isfile(filename) is True
    executor.stop()
예제 #2
0
def test_timeout_error():
    """Check if timeout properly expires."""
    executor = PidExecutor(sleep, filename, timeout=1)

    with pytest.raises(TimeoutExpired):
        executor.start()

    assert executor.running() is False
예제 #3
0
def test_timeout_error():
    """Check if timeout properly expires."""
    executor = PidExecutor(sleep, filename, timeout=1)

    with pytest.raises(TimeoutExpired):
        executor.start()

    assert executor.running() is False
예제 #4
0
def test_timeout_error() -> None:
    """Check if timeout properly expires."""
    executor = PidExecutor(SLEEP, FILENAME, timeout=1)

    with pytest.raises(TimeoutExpired):
        executor.start()

    assert executor.running() is False
예제 #5
0
def test_start_and_wait(timeout):
    """Test if the executor will await for the process to create a file."""
    process = 'bash -c "sleep 2 && touch {0}  && sleep 10"'.format(filename)
    executor = PidExecutor(process, filename, timeout=timeout)
    with executor:
        assert executor.running() is True

    # check proper __str__ and __repr__ rendering:
    assert 'PidExecutor' in repr(executor)
    assert process in str(executor)
예제 #6
0
def test_start_and_wait(timeout):
    """Test if the executor will await for the process to create a file."""
    process = 'bash -c "sleep 2 && touch {0}  && sleep 10"'.format(filename)
    executor = PidExecutor(process, filename, timeout=timeout)
    with executor:
        assert executor.running() is True

    # check proper __str__ and __repr__ rendering:
    assert 'PidExecutor' in repr(executor)
    assert process in str(executor)
예제 #7
0
def test_fail_if_other_executor_running():
    """Test raising AlreadyRunning exception when port is blocked."""
    process = 'bash -c "sleep 2 && touch {0}  && sleep 10"'.format(filename)
    executor = PidExecutor(process, filename)
    executor2 = PidExecutor(process, filename)

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()
예제 #8
0
def test_start_and_wait():
    """Test if the executor will await for the process to create a file."""
    process = f'bash -c "sleep 2 && touch {FILENAME} && sleep 10"'
    with PidExecutor(process, FILENAME, timeout=5) as executor:
        assert executor.running() is True

    # check proper __str__ and __repr__ rendering:
    assert 'PidExecutor' in repr(executor)
    assert process in str(executor)
예제 #9
0
def test_start_and_wait(timeout):
    """Test if the executor will await for the process to create a file."""
    process = 'bash -c "sleep 2 && touch {0}  && sleep 10"'.format(filename)
    executor = PidExecutor(process, filename, timeout=timeout)
    executor.start()

    assert executor.running() is True
    executor.stop()
예제 #10
0
def test_fail_if_other_executor_running():
    """Test raising AlreadyRunning exception when port is blocked."""
    process = 'bash -c "sleep 2 && touch {0}  && sleep 10"'.format(filename)
    executor = PidExecutor(process, filename)
    executor2 = PidExecutor(process, filename)

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()
예제 #11
0
def test_fail_if_other_executor_running() -> None:
    """Test raising AlreadyRunning exception when port is blocked."""
    process = f'bash -c "sleep 2 && touch {FILENAME} && sleep 10"'
    executor = PidExecutor(process, FILENAME)
    executor2 = PidExecutor(process, FILENAME)

    with executor:

        assert executor.running() is True

        with pytest.raises(AlreadyRunning):
            executor2.start()
예제 #12
0
def test_if_file_created():
    """Check whether the process really created the given file."""
    assert os.path.isfile(filename) is False
    executor = PidExecutor(sleep, filename)
    with executor:
        assert os.path.isfile(filename) is True
예제 #13
0
def test_empty_filename(pid_file):
    """Check whether an exception is raised if an empty filename is given."""
    with pytest.raises(ValueError):
        PidExecutor(sleep, pid_file)
예제 #14
0
def test_if_file_created():
    """Check whether the process really created the given file."""
    assert os.path.isfile(FILENAME) is False
    executor = PidExecutor(SLEEP, FILENAME)
    with executor:
        assert os.path.isfile(FILENAME) is True
예제 #15
0
def test_empty_filename(pid_file: Optional[str]) -> None:
    """Check whether an exception is raised if an empty FILENAME is given."""
    with pytest.raises(ValueError):
        PidExecutor(SLEEP, pid_file)  # type: ignore[arg-type]