Skip to content

Commit

Permalink
Merge pull request ClearcodeHQ#38 from fizyk/pid_tests
Browse files Browse the repository at this point in the history
few PidExecutor tests optimisations
  • Loading branch information
fizyk committed Oct 13, 2014
2 parents 4a895c5 + 59f38c2 commit 02669a6
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions tests/executors/test_pid_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

@pytest.yield_fixture(autouse=True)
def run_around_tests():
"""Make sure the tmp file is not present."""
"""
Make sure the **filename** file is not present.
This executor actually removes filename as process used to test
PidExecutor only creates it.
"""
try:
os.remove(filename)
except OSError:
Expand All @@ -32,28 +37,23 @@ 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()
with executor:
assert executor.running() is True


def test_empty_filename():
@pytest.mark.parametrize('pid_file', (None, ""))
def test_empty_filename(pid_file):
"""Check whether an exception is raised if an empty filename is given."""
with pytest.raises(ValueError):
PidExecutor(process, None)

with pytest.raises(ValueError):
PidExecutor(process, "")
PidExecutor(process, pid_file)


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()
with executor:
assert os.path.isfile(filename) is True


def test_timeout_error():
Expand All @@ -78,7 +78,3 @@ def test_fail_if_other_executor_running():

with pytest.raises(AlreadyRunning):
executor2.start()

with pytest.raises(AlreadyRunning):
with executor2:
pass

0 comments on commit 02669a6

Please sign in to comment.