[Libguestfs] [PATCH] Add missing python bindings tests

Hiroyuki Katsura hiroyuki.katsura.0513 at gmail.com
Wed Apr 3 15:55:52 UTC 2019


Signed-off-by: Hiroyuki Katsura <hiroyuki.katsura.0513 at gmail.com>
---
 python/t/test020Create.py           | 25 ++++++++++++++
 python/t/test030CreateFlags.py      | 27 +++++++++++++++
 python/t/test040CreateMultiple.py   | 32 ++++++++++++++++++
 python/t/test050HandleProperties.py | 50 +++++++++++++++++++++++++++
 python/t/test430ProgressMessages.py | 52 +++++++++++++++++++++++++++++
 5 files changed, 186 insertions(+)
 create mode 100644 python/t/test020Create.py
 create mode 100644 python/t/test030CreateFlags.py
 create mode 100644 python/t/test040CreateMultiple.py
 create mode 100644 python/t/test050HandleProperties.py
 create mode 100644 python/t/test430ProgressMessages.py

diff --git a/python/t/test020Create.py b/python/t/test020Create.py
new file mode 100644
index 000000000..476ffd059
--- /dev/null
+++ b/python/t/test020Create.py
@@ -0,0 +1,25 @@
+# libguestfs Python bindings
+# Copyright (C) 2019 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#)
+
+import unittest
+import guestfs
+
+
+class Test020Create(unittest.TestCase):
+    def test_create(self):
+        _ = guestfs.GuestFS(python_return_dict=True)
diff --git a/python/t/test030CreateFlags.py b/python/t/test030CreateFlags.py
new file mode 100644
index 000000000..2e9b48203
--- /dev/null
+++ b/python/t/test030CreateFlags.py
@@ -0,0 +1,27 @@
+# libguestfs Python bindings
+# Copyright (C) 2019 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#)
+
+import unittest
+import guestfs
+
+
+class Test030CreateFlags(unittest.TestCase):
+    def test_create_flags(self):
+        g = guestfs.GuestFS(python_return_dict=True, 
+                environment=False)
+        g.parse_environment()
diff --git a/python/t/test040CreateMultiple.py b/python/t/test040CreateMultiple.py
new file mode 100644
index 000000000..cc0050695
--- /dev/null
+++ b/python/t/test040CreateMultiple.py
@@ -0,0 +1,32 @@
+# libguestfs Python bindings
+# Copyright (C) 2019 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#)
+
+import unittest
+import guestfs
+
+
+def ignore(_):
+    pass
+
+
+class Test040CreateMultiple(unittest.TestCase):
+    def test_create_multiple(self):
+        g1 = guestfs.GuestFS(python_return_dict=True)
+        g2 = guestfs.GuestFS(python_return_dict=True)
+        g3 = guestfs.GuestFS(python_return_dict=True)
+        ignore((g1, g2, g3))
diff --git a/python/t/test050HandleProperties.py b/python/t/test050HandleProperties.py
new file mode 100644
index 000000000..fc053d779
--- /dev/null
+++ b/python/t/test050HandleProperties.py
@@ -0,0 +1,50 @@
+
+# libguestfs Python bindings
+# Copyright (C) 2019 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#)
+
+import unittest
+import guestfs
+
+
+class Test050HandleProperties(unittest.TestCase):
+    def test_verbose(self):
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.set_verbose(1)
+        self.assertEqual(g.get_verbose(), 1)
+        g.set_verbose(0)
+        self.assertEqual(g.get_verbose(), 0)
+
+    def test_autosync(self):
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.set_autosync(1)
+        self.assertEqual(g.get_autosync(), 1)
+        g.set_autosync(0)
+        self.assertEqual(g.get_autosync(), 0)
+
+    def test_path(self):
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.set_path(".")
+        self.assertEqual(g.get_path(), ".")
+
+    def test_add_drive(self):
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.add_drive("/dev/null")
+    
+    def test_add_cdrom(self):
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.add_cdrom("/dev/zero")
diff --git a/python/t/test430ProgressMessages.py b/python/t/test430ProgressMessages.py
new file mode 100644
index 000000000..79e0491ff
--- /dev/null
+++ b/python/t/test430ProgressMessages.py
@@ -0,0 +1,52 @@
+# libguestfs Python bindings
+# Copyright (C) 2019 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import unittest
+import os
+import guestfs
+
+callback_invoked = 0
+
+
+def callback(ev, eh, buf, array):
+    global callback_invoked
+    callback_invoked += 1
+
+    
+class Test430ProgressMessages(unittest.TestCase):
+    def test_progress_messages(self):
+        global callback_invoked 
+        g = guestfs.GuestFS(python_return_dict=True)
+        g.add_drive('/dev/null')
+        g.launch()
+
+        events = guestfs.EVENT_PROGRESS
+
+        eh = g.set_event_callback(callback, events)
+        g.debug('progress', ['5'])
+        self.assertTrue(callback_invoked > 0)
+
+        callback_invoked = 0
+        g.delete_event_callback(eh)
+        g.debug('progress', ['5'])
+        self.assertEqual(callback_invoked, 0)
+
+        g.set_event_callback(callback, events)
+        g.debug('progress', ['5'])
+        self.assertTrue(callback_invoked > 0)
+
+        g.close()
-- 
2.17.1




More information about the Libguestfs mailing list