Revision c9c4f19e

b/test/Makefile.am
12 12
do-pre-check:
13 13
	$(MAKE) -C $(top_builddir) pre-check
14 14

  
15
EXTRA_DIST = $(TESTS) mocks.py $(wildcard data/*.txt)
15
EXTRA_DIST = $(TESTS) testutils.py mocks.py $(wildcard data/*.txt)
16 16
CLEANFILES = *.py[co]
b/test/ganeti.utils_unittest.py
33 33
import re
34 34

  
35 35
import ganeti
36
import testutils
36 37
from ganeti import constants
37 38
from ganeti import utils
38 39
from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \
......
43 44
from ganeti.errors import LockError, UnitParseError
44 45

  
45 46

  
46
class GanetiTestCase(unittest.TestCase):
47
  def assertFileContent(self, file_name, content):
48
    """Checks the content of a file.
49

  
50
    """
51
    handle = open(file_name, 'r')
52
    try:
53
      self.assertEqual(handle.read(), content)
54
    finally:
55
      handle.close()
56

  
57

  
58 47
class TestIsProcessAlive(unittest.TestCase):
59 48
  """Testing case for IsProcessAlive"""
60 49
  def setUp(self):
......
362 351
      self.assertRaises(UnitParseError, ParseUnit, '1,3' + suffix)
363 352

  
364 353

  
365
class TestSshKeys(GanetiTestCase):
354
class TestSshKeys(testutils.GanetiTestCase):
366 355
  """Test case for the AddAuthorizedKey function"""
367 356

  
368 357
  KEY_A = 'ssh-dss AAAAB3NzaC1w5256closdj32mZaQU root@key-a'
......
432 421
      " ssh-dss AAAAB3NzaC1w520smc01ms0jfJs22 root@key-b\n")
433 422

  
434 423

  
435
class TestEtcHosts(GanetiTestCase):
424
class TestEtcHosts(testutils.GanetiTestCase):
436 425
  """Test functions modifying /etc/hosts"""
437 426

  
438 427
  def setUp(self):
b/test/testutils.py
1
#
2
#
3

  
4
# Copyright (C) 2006, 2007, 2008 Google Inc.
5
#
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.
10
#
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.
15
#
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
19
# 02110-1301, USA.
20

  
21

  
22
"""Utilities for unit testing"""
23

  
24
import unittest
25

  
26

  
27
class GanetiTestCase(unittest.TestCase):
28
  def assertFileContent(self, file_name, content):
29
    """Checks the content of a file.
30

  
31
    """
32
    handle = open(file_name, 'r')
33
    try:
34
      self.assertEqual(handle.read(), content)
35
    finally:
36
      handle.close()

Also available in: Unified diff