From c9c4f19e7f0799ce7313f117b7436eb22cf27723 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 26 Feb 2008 20:15:53 +0000
Subject: [PATCH] Split GanetiUnitTest into testutils.py

Reviewed-by: iustinp
---
 test/Makefile.am              |  2 +-
 test/ganeti.utils_unittest.py | 17 +++--------------
 test/testutils.py             | 36 +++++++++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 15 deletions(-)
 create mode 100644 test/testutils.py

diff --git a/test/Makefile.am b/test/Makefile.am
index 3eed00002..f07885440 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 560c7aca7..4a01096c5 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 000000000..3eba2113a
--- /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()
-- 
GitLab