4 # Copyright (C) 2006, 2007, 2008 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Utilities for unit testing"""
27 from ganeti import utils
30 class GanetiTestCase(unittest.TestCase):
31 def assertFileContent(self, file_name, expected_content):
32 """Checks the content of a file is what we expect.
35 @param file_name: the file whose contents we should check
36 @type expected_content: str
37 @param expected_content: the content we expect
40 actual_content = utils.ReadFile(file_name)
41 self.assertEqual(actual_content, expected_content)
44 def _TestDataFilename(name):
45 """Returns the filename of a given test data file.
48 @param name: the 'base' of the file name, as present in
49 the test/data directory
51 @return: the full path to the filename, such that it can
52 be used in 'make distcheck' rules
55 prefix = os.environ.get("srcdir", "")
57 prefix = prefix + "/test/"
58 return "%sdata/%s" % (prefix, name)
61 def _ReadTestData(cls, name):
62 """Returns the contents of a test data file.
64 This is just a very simple wrapper over utils.ReadFile with the
65 proper test file name.
69 return utils.ReadFile(cls._TestDataFilename(name))