Added unit tests for rename objects

This commit is contained in:
mpj
2009-11-22 19:45:59 +00:00
parent c95ba83c7d
commit f795e1a0b7
2 changed files with 92 additions and 2 deletions
+3 -2
View File
@@ -5,15 +5,16 @@ import sys
sys.path.append(".")
from sphinxtogithub.test import directoryhandler, filehandler, replacer
from sphinxtogithub.test import directoryhandler, filehandler, replacer, renamer
if __name__ == "__main__":
suites = [
filehandler.testSuite(),
replacer.testSuite(),
directoryhandler.testSuite(),
replacer.testSuite(),
renamer.testSuite(),
]
suite = unittest.TestSuite(suites)
+89
View File
@@ -0,0 +1,89 @@
import unittest
import os
import sphinxtogithub
class MockExists(object):
def __call__(self, name):
self.name = name
return True
class MockRemove(MockExists):
pass
class MockRename(object):
def __call__(self, from_, to):
self.from_ = from_
self.to = to
class MockStream(object):
def write(self, msg):
self.msg = msg
class TestRemover(unittest.TestCase):
def testCall(self):
exists = MockExists()
remove = MockRemove()
remover = sphinxtogithub.Remover(exists, remove)
filepath = "filepath"
remover(filepath)
self.assertEqual(filepath, exists.name)
self.assertEqual(filepath, remove.name)
class TestForceRename(unittest.TestCase):
def testCall(self):
rename = MockRename()
remove = MockRemove()
renamer = sphinxtogithub.ForceRename(rename, remove)
from_ = "from"
to = "to"
renamer(from_, to)
self.assertEqual(rename.from_, from_)
self.assertEqual(rename.to, to)
self.assertEqual(remove.name, to)
class TestVerboseRename(unittest.TestCase):
def testCall(self):
rename = MockRename()
stream = MockStream()
renamer = sphinxtogithub.VerboseRename(rename, stream)
from_ = os.path.join("path", "to", "from")
to = os.path.join("path", "to", "to")
renamer(from_, to)
self.assertEqual(rename.from_, from_)
self.assertEqual(rename.to, to)
self.assertEqual(
stream.msg,
"Renaming directory '%s' -> '%s'\n" % (os.path.basename(from_), os.path.basename(to))
)
def testSuite():
suite = unittest.TestSuite()
suite.addTest(TestRemover("testCall"))
suite.addTest(TestForceRename("testCall"))
suite.addTest(TestVerboseRename("testCall"))
return suite