def setUpProject(self, project, testFolderPath=_BaseTestFolder): """ Create a Subversion repository containing a few files and a work copy with its current contents checked out. """ self.setUpEmptyProject(project, testFolderPath) # Create a few files in the project root folder. helloPyPath = self.scmWork.absolutePath("test file path", "hello.py") self.writeTextFile(helloPyPath, ["# A classic.", "print 'hello world!'"]) readmeTxtPath = self.scmWork.absolutePath("test file path", "ReadMe.txt") self.writeTextFile(readmeTxtPath, ["Just a dummy project with some test file."]) # Create a folder "loops" with a couple of Python source codes. loopsFolderPath = self.scmWork.absolutePath("test folder path", "loops") _tools.makeFolder(loopsFolderPath) forRangePyPath = os.path.join(loopsFolderPath, "forRange.py") whilePyPath = os.path.join(loopsFolderPath, "while.py") self.writeTextFile(forRangePyPath, ["for i in range(5):", " print i"]) self.writeTextFile(whilePyPath, ["i = 0", "while i < 5:", " print i", " i += 1"]) # Create a folder "media" with a couple of files." mediaFolderPath = self.scmWork.absolutePath("test folder path", "media") _tools.makeFolder(mediaFolderPath) speechHtmlPath = os.path.join(loopsFolderPath, "speech.html") self.writeTextFile(speechHtmlPath, ["<html><head><title>A great speech</title></head><body>", "<h1>A great speech</h1>", "<p>Uhm...</p>", "</body></html>"]) # TODO: Add binary PNG test file. self.scmWork.addUnversioned("") self.scmWork.commit("", "Added test files")
def testCanPunchThreeNestedFoldersWithoutFiles(self): self.setUpEmptyProject("punchThreeNestedFoldersWithoutFiles") scmWork = self.scmWork testPunchWithPatternPath = self.createTestFolder("testPunchThreeNestedFoldersWithoutFiles") scmWork.exportTo(testPunchWithPatternPath, clear=True) level1FolderPath = os.path.join(testPunchWithPatternPath, "level1") level2FolderPath = os.path.join(level1FolderPath, "level2") level3FolderPath = os.path.join(level2FolderPath, "level3") _tools.makeFolder(level3FolderPath) innerFilePath = os.path.join(level3FolderPath, "test.txt") self.writeTextFile(innerFilePath, ["test"]) outerPuncher = scunch.ScmPuncher(scmWork) outerPuncher.punch(testPunchWithPatternPath)
def testCanMessWithFolders(self): testFolderPath = tempfile.mkdtemp(prefix="scunch_test_") _tools.removeFolder(testFolderPath) self.assertFalse(os.path.exists(testFolderPath)) _tools.makeFolder(testFolderPath) self.assertTrue(os.path.exists(testFolderPath)) _tools.makeFolder(testFolderPath) _tools.removeFolder(testFolderPath) _tools.makeEmptyFolder(testFolderPath) _tools.makeEmptyFolder(testFolderPath) # Clean up. _tools.removeFolder(testFolderPath)
def _testTextOptions(self, textOptions=None, expectedTextFileContents={}): scmWork = self.scmWork # Create a folder with a couple of messed up text files. _tools.makeFolder(self.textsFolderPath) self.writeBinaryFile(self.dosNewLineTxtPath, "1\r\n2\r\n") self.writeBinaryFile(self.unixNewLineTxtPath, "1\n2\n") self.writeBinaryFile(self.mixedNewLineTxtPath, "1\r\n2\n3\r") self.writeBinaryFile(self.mixedNewLineTxtPath, "1\r\n2\n3\r\n4\n") self.writeBinaryFile(self.noNewLineTxtPath, "1") self.writeBinaryFile(self.tabAndTrailingSpaceTxtPath, ".\t1 \n") self.writeBinaryFile(self.emptyTxtPath, "") scunch.scunch(self.testPunchTextPath, scmWork, textOptions=textOptions) for filePathToTest, expectedContent in expectedTextFileContents.items(): self._assertWorkTextFileEquals(filePathToTest, expectedContent) scmWork.addUnversioned("") self.assertNonNormalStatus({scunch.ScmStatus.Added: 1 + len(expectedTextFileContents)}) self._testAfterPunch(self.testPunchTextPath, textOptions)