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 # In twisted 1.3 Tester sets caseMethodName on the testCase instance 19 log.debug('unittest', "%s.setUp() for %s" % ( 20 self.__class__.__name__, 21 getattr(self, '_testMethodName', getattr( 22 self, 'caseMethodName', "[unknown method]"))))
23
24 - def tearDown(self):
25 log.debug('unittest', "%s.tearDown() for %s" % ( 26 self.__class__.__name__, 27 getattr(self, '_testMethodName', getattr( 28 self, 'caseMethodName', "[unknown method]"))))
29
30 -class SVNTestCase(TestCase):
31 - def createRepository(self):
32 """ 33 Create a svn repository we can use for testing. 34 35 @rtype: str 36 """ 37 repodir = self.createDirectory('repo') 38 log.debug('unittest', 'creating temp repo in %s' % repodir) 39 value = os.system('svnadmin create %s' % repodir) 40 self.assertEquals(value, 0, "Could not execute svnadmin") 41 return repodir
42
43 - def createLive(self):
44 """ 45 Create a "live" area where we can store files for testing. 46 47 @rtype: str 48 """ 49 livedir = self.createDirectory('live') 50 log.debug('unittest', 'creating live area in %s' % livedir) 51 value = os.system('mkdir -p %s' % livedir) 52 53 self.assertEquals(value, 0, "Could not create %s" % livedir) 54 return livedir
55
56 - def createDirectory(self, name):
57 """ 58 Create a directory using the given name as part of the name. 59 60 @rtype: str 61 """ 62 return tempfile.mkdtemp(suffix=".%s.svn.test" % name)
63
64 - def liveWriteFile(self, livePath, data):
65 path = os.path.join(self.livedir, livePath) 66 handle = open(path, "w") 67 handle.write(data) 68 handle.close() 69 return path
70
71 - def liveCreateDirectory(self, livePath):
72 path = os.path.join(self.livedir, livePath) 73 os.mkdir(path) 74 return path
75
76 -class FakeStdOut:
77 - def write(self, what):
78 pass
79