diff --git a/test/Makefile.am b/test/Makefile.am index 3eed000025dca37b1a935d1fc9609cf45bf92086..f078854409e4ca31dbe9de58f5b79d07a47c6c3b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -12,5 +12,5 @@ check-am: do-pre-check do-pre-check: $(MAKE) -C $(top_builddir) pre-check -EXTRA_DIST = $(TESTS) mocks.py $(wildcard data/*.txt) +EXTRA_DIST = $(TESTS) testutils.py mocks.py $(wildcard data/*.txt) CLEANFILES = *.py[co] diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index 560c7aca7b78bcf89bcdfbae9d31131cd3701336..4a01096c59697a501f99d37aae01d9951c8c4e72 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -33,6 +33,7 @@ import shutil import re import ganeti +import testutils from ganeti import constants from ganeti import utils from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \ @@ -43,18 +44,6 @@ from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \ from ganeti.errors import LockError, UnitParseError -class GanetiTestCase(unittest.TestCase): - def assertFileContent(self, file_name, content): - """Checks the content of a file. - - """ - handle = open(file_name, 'r') - try: - self.assertEqual(handle.read(), content) - finally: - handle.close() - - class TestIsProcessAlive(unittest.TestCase): """Testing case for IsProcessAlive""" def setUp(self): @@ -362,7 +351,7 @@ class TestParseUnit(unittest.TestCase): self.assertRaises(UnitParseError, ParseUnit, '1,3' + suffix) -class TestSshKeys(GanetiTestCase): +class TestSshKeys(testutils.GanetiTestCase): """Test case for the AddAuthorizedKey function""" KEY_A = 'ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a' @@ -432,7 +421,7 @@ class TestSshKeys(GanetiTestCase): " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n") -class TestEtcHosts(GanetiTestCase): +class TestEtcHosts(testutils.GanetiTestCase): """Test functions modifying /etc/hosts""" def setUp(self): diff --git a/test/testutils.py b/test/testutils.py new file mode 100644 index 0000000000000000000000000000000000000000..3eba2113abd841d9d9ece292ebccfb926e90f100 --- /dev/null +++ b/test/testutils.py @@ -0,0 +1,36 @@ +# +# + +# Copyright (C) 2006, 2007, 2008 Google 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. + + +"""Utilities for unit testing""" + +import unittest + + +class GanetiTestCase(unittest.TestCase): + def assertFileContent(self, file_name, content): + """Checks the content of a file. + + """ + handle = open(file_name, 'r') + try: + self.assertEqual(handle.read(), content) + finally: + handle.close()