aboutsummaryrefslogtreecommitdiffstats
path: root/test/util.py
diff options
context:
space:
mode:
authorNikolaus Rath <Nikolaus@rath.org>2016-03-29 15:30:57 -0700
committerNikolaus Rath <Nikolaus@rath.org>2016-03-29 16:06:29 -0700
commit59e58de40c50ac05e24f5dc2d3267890974cde04 (patch)
tree560212f2ea2b7622df1bb6da1fa4a4ad328f82dc /test/util.py
parent92e2863fb7ff857e424329508d32225eb9b3b3e9 (diff)
downloadlibfuse-59e58de40c50ac05e24f5dc2d3267890974cde04.tar.gz
Added basic unit tests.
Fixes issue #33.
Diffstat (limited to 'test/util.py')
-rw-r--r--test/util.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/util.py b/test/util.py
new file mode 100644
index 0000000..48ec995
--- /dev/null
+++ b/test/util.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+import subprocess
+import pytest
+import os
+import time
+
+def wait_for_mount(mount_process, mnt_dir):
+ elapsed = 0
+ while elapsed < 30:
+ if os.path.ismount(mnt_dir):
+ return True
+ if mount_process.poll() is not None:
+ pytest.fail('file system process terminated prematurely')
+ time.sleep(0.1)
+ elapsed += 0.1
+ pytest.fail("mountpoint failed to come up")
+
+def cleanup(mnt_dir):
+ subprocess.call(['fusermount', '-z', '-u', mnt_dir],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.STDOUT)
+
+def umount(mount_process, mnt_dir):
+ subprocess.check_call(['fusermount', '-z', '-u', mnt_dir])
+ assert not os.path.ismount(mnt_dir)
+
+ # Give mount process a little while to terminate. Popen.wait(timeout)
+ # was only added in 3.3...
+ elapsed = 0
+ while elapsed < 30:
+ code = mount_process.poll()
+ if code is not None:
+ if code == 0:
+ return
+ pytest.fail('file system process terminated with code %s' % (code,))
+ time.sleep(0.1)
+ elapsed += 0.1
+ pytest.fail('mount process did not terminate')