[libvirt] [PATCH python 0/2] Add unit test framework

The bug fix of Michal's to handling of typed parameters demonstrated a clear need for a unit test framework for python bindings. By using the test:///default driver we can easily test a great many python APIs. Once the test driver has full API coverage, we can in fact unit test all the python bindings. The first patch does the bare minimum to plumb the unit test framework into 'python setup test.py' (requires python-nose RPM to be present) and does a test for the virConnectListAllDomains API. The second patch tests Michal's previous bug fix - this test will fail on current GIT and Michal's patch makes it pass. A nice project for someone wanting to learn more about libvirt and the python binding is to flesh out this test suite to cover as many APIs as possible. We should aim to have an addition to this test suite for any bugs we find in the bindings henceforth. Daniel P. Berrange (2): Add support for running unit tests with nose Add test for setting scheduler parameters setup.py | 5 +++++ tests/test_conn.py | 16 ++++++++++++++++ tests/test_domain.py | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/test_conn.py create mode 100644 tests/test_domain.py -- 1.8.5.3

Make the 'python setup.py test' able to run unit tests found under tests/ through the 'nosetests' command Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- setup.py | 5 +++++ tests/test_conn.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/test_conn.py diff --git a/setup.py b/setup.py index 773cef3..cfbbe2c 100755 --- a/setup.py +++ b/setup.py @@ -267,7 +267,12 @@ class my_test(Command): apis = get_api_xml_files() + if "PYTHONPATH" in os.environ: + os.environ["PYTHONPATH"] = self.build_platlib + ":" + os.environ["PYTHONPATH"] + else: + os.environ["PYTHONPATH"] = self.build_platlib self.spawn([sys.executable, "sanitytest.py", self.build_platlib, apis[0]]) + self.spawn(["nosetests"]) class my_clean(clean): diff --git a/tests/test_conn.py b/tests/test_conn.py new file mode 100644 index 0000000..9fee099 --- /dev/null +++ b/tests/test_conn.py @@ -0,0 +1,16 @@ + +import unittest +import libvirt + +class TestLibvirtConn(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + + def tearDown(self): + self.conn = None + + def testConnDomainList(self): + doms = self.conn.listAllDomains() + self.assertEquals(len(doms), 1) + self.assertEquals(type(doms[0]), libvirt.virDomain) + self.assertEquals(doms[0].name(), "test") -- 1.8.5.3

Add a test setting scheduler parameters to validate the previous bugfix to strncpy of field names. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> --- tests/test_domain.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/test_domain.py diff --git a/tests/test_domain.py b/tests/test_domain.py new file mode 100644 index 0000000..b3fe255 --- /dev/null +++ b/tests/test_domain.py @@ -0,0 +1,19 @@ + +import unittest +import libvirt + +class TestLibvirtDomain(unittest.TestCase): + def setUp(self): + self.conn = libvirt.open("test:///default") + self.dom = self.conn.lookupByName("test") + + def tearDown(self): + self.dom = None + self.conn = None + + def testDomainSchedParams(self): + params = self.dom.schedulerParameters() + self.assertEquals(len(params), 1) + self.assertTrue("weight" in params) + params["weight"] = 100 + self.dom.setSchedulerParameters(params) -- 1.8.5.3

On 18.03.2014 12:27, Daniel P. Berrange wrote:
The bug fix of Michal's to handling of typed parameters demonstrated a clear need for a unit test framework for python bindings. By using the test:///default driver we can easily test a great many python APIs. Once the test driver has full API coverage, we can in fact unit test all the python bindings.
The first patch does the bare minimum to plumb the unit test framework into 'python setup test.py' (requires python-nose RPM to be present) and does a test for the virConnectListAllDomains API.
The second patch tests Michal's previous bug fix - this test will fail on current GIT and Michal's patch makes it pass.
A nice project for someone wanting to learn more about libvirt and the python binding is to flesh out this test suite to cover as many APIs as possible. We should aim to have an addition to this test suite for any bugs we find in the bindings henceforth.
Daniel P. Berrange (2): Add support for running unit tests with nose Add test for setting scheduler parameters
setup.py | 5 +++++ tests/test_conn.py | 16 ++++++++++++++++ tests/test_domain.py | 19 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/test_conn.py create mode 100644 tests/test_domain.py
ACK to both patches. Michal
participants (2)
-
Daniel P. Berrange
-
Michal Privoznik