summaryrefslogtreecommitdiffstats
path: root/libmount/python/test_mount_tab_update.py
diff options
context:
space:
mode:
authorOndrej Oprala2013-08-19 15:11:06 +0200
committerKarel Zak2013-08-19 15:11:06 +0200
commit90eb39874f2dc385e84aa8e212bfa61b22a018c6 (patch)
tree26f62baf609cbf24f1c403d205343f4ff746c727 /libmount/python/test_mount_tab_update.py
parentpylibmount: add __init__.py (diff)
downloadkernel-qcow2-util-linux-90eb39874f2dc385e84aa8e212bfa61b22a018c6.tar.gz
kernel-qcow2-util-linux-90eb39874f2dc385e84aa8e212bfa61b22a018c6.tar.xz
kernel-qcow2-util-linux-90eb39874f2dc385e84aa8e212bfa61b22a018c6.zip
pylibmount: add regression tests
Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/python/test_mount_tab_update.py')
-rwxr-xr-xlibmount/python/test_mount_tab_update.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/libmount/python/test_mount_tab_update.py b/libmount/python/test_mount_tab_update.py
new file mode 100755
index 000000000..12d2db022
--- /dev/null
+++ b/libmount/python/test_mount_tab_update.py
@@ -0,0 +1,58 @@
+#!/bin/python2
+import os
+import sys
+import stat
+import errno
+import libmount as mnt
+
+def usage(tss):
+ print "\nUsage:\n\t{:s} <test> [testoptions]\nTests:\n".format(sys.argv[0])
+ for i in tss:
+ print "\t{15:-s}".format(i[0])
+ if i[2] != "":
+ print " {:s}\n".format(i[2])
+
+ print("\n")
+ return 1
+
+def mnt_run_test(tss, argv):
+ rc = -1
+ if ((len(argv) < 2) or (argv[1] == "--help") or (argv[1] == "-h")):
+ return usage(tss)
+
+ #mnt_init_debug(0)
+
+ i=()
+ for i in tss:
+ if i[0] == argv[1]:
+ rc = i[1](i, argv[1:])
+ if rc:
+ print "FAILED [rc={:d}]".format(rc)
+ break
+
+ if ((rc < 0) and (i == ())):
+ return usage(tss)
+ return not not rc #because !!rc is too mainstream for python
+
+def test_replace(ts, argv):
+ fs = mnt.Fs()
+ tb = mnt.Tab()
+
+ if (len(argv) < 3):
+ return -1
+ tb.enable_comments(True)
+ tb.parse_fstab()
+
+ fs.source = argv[1]
+ fs.target = argv[2]
+ #TODO: resolve None + string
+ fs.comment = "# this is new filesystem\n"
+ tb.add_fs(fs)
+ tb.replace_file(os.environ["LIBMOUNT_FSTAB"])
+ return 0
+
+tss = (
+ ( "--replace",test_replace, "<src> <target> Add a line to LIBMOUNT_FSTAB and replace the original file" ),
+)
+
+sys.exit(mnt_run_test(tss, sys.argv))