From 7772cfc77186dfba076b1cf471866222df3c2f0e Mon Sep 17 00:00:00 2001 From: Hiroyuki Katsura Date: Wed, 3 Apr 2019 15:55:52 +0000 Subject: [PATCH] Add missing python bindings tests Signed-off-by: Hiroyuki Katsura --- python/t/test020Create.py | 23 +++++++++++++ python/t/test030CreateFlags.py | 25 +++++++++++++++ python/t/test040CreateMultiple.py | 29 +++++++++++++++++ python/t/test050HandleProperties.py | 47 +++++++++++++++++++++++++++ python/t/test430ProgressMessages.py | 50 +++++++++++++++++++++++++++++ 5 files changed, 174 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..16e19ec76 --- /dev/null +++ b/python/t/test020Create.py @@ -0,0 +1,23 @@ +# 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..b69e488b3 --- /dev/null +++ b/python/t/test030CreateFlags.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 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..190ef256b --- /dev/null +++ b/python/t/test040CreateMultiple.py @@ -0,0 +1,29 @@ +# 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..e2b12f1dc --- /dev/null +++ b/python/t/test050HandleProperties.py @@ -0,0 +1,47 @@ +# 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..cbc404cd0 --- /dev/null +++ b/python/t/test430ProgressMessages.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 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()