Package moap :: Package test :: Module common
[hide private]
[frames] | no frames]

Source Code for Module moap.test.common

 1  # -*- Mode: Python -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  import os 
 5  import tempfile 
 6   
 7  # use twisted if we can so we get nice trial goodness 
 8  try: 
 9      from twisted.trial import unittest 
10  except ImportError: 
11      import unittest 
12   
13  from moap.util import log 
14  log.init() 
15   
16 -class TestCase(unittest.TestCase):
17 - def setUp(self):
18 log.debug('unittest', "%s.setUp() for %s" % ( 19 self.__class__.__name__, self._testMethodName))
20
21 - def tearDown(self):
22 log.debug('unittest', "%s.tearDown() for %s" % ( 23 self.__class__.__name__, self._testMethodName))
24
25 -class SVNTestCase(TestCase):
26 - def createRepository(self):
27 """ 28 Create a svn repository we can use for testing. 29 30 @rtype: str 31 """ 32 repodir = self.createDirectory('repo') 33 log.debug('unittest', 'creating temp repo in %s' % repodir) 34 value = os.system('svnadmin create %s' % repodir) 35 self.assertEquals(value, 0, "Could not execute svnadmin") 36 return repodir
37
38 - def createLive(self):
39 """ 40 Create a "live" area where we can store files for testing. 41 42 @rtype: str 43 """ 44 livedir = self.createDirectory('live') 45 log.debug('unittest', 'creating live area in %s' % livedir) 46 value = os.system('mkdir -p %s' % livedir) 47 48 self.assertEquals(value, 0, "Could not create %s" % livedir) 49 return livedir
50
51 - def createDirectory(self, name):
52 """ 53 Create a directory using the given name as part of the name. 54 55 @rtype: str 56 """ 57 return tempfile.mkdtemp(suffix=".%s.svn.test" % name)
58
59 - def liveWriteFile(self, livePath, data):
60 path = os.path.join(self.livedir, livePath) 61 handle = open(path, "w") 62 handle.write(data) 63 handle.close() 64 return path
65
66 - def liveCreateDirectory(self, livePath):
67 path = os.path.join(self.livedir, livePath) 68 os.mkdir(path) 69 return path
70
71 -class FakeStdOut:
72 - def write(self, what):
73 pass
74