Esempio n. 1
0
 def test_strSub(self):
     newFileName = "tmp"
     tf = TextFileObj(path=self.subReadFilePath)
     newTf = tf.copy(name=newFileName, father=self.testDir)
     expectedFileContent = "Sample File\n"
     expectedFileContent += "\n"
     expectedFileContent += "For Regexp For Regexp For Regexp\n"
     expectedFileContent += "\n"
     expectedFileContent += "For Regexp\n"
     expectedFileContent += "\n"
     expectedFileContent += "MyRegexp\n"
     expectedFileContent += ""
     self.assertEqual(newTf.getStr(), expectedFileContent)
     newTf.strSub(findStr="Sample", replaceStr="Example")
     expectedFileContent = "Example File\n"
     expectedFileContent += "\n"
     expectedFileContent += "For Regexp For Regexp For Regexp\n"
     expectedFileContent += "\n"
     expectedFileContent += "For Regexp\n"
     expectedFileContent += "\n"
     expectedFileContent += "MyRegexp\n"
     expectedFileContent += ""
     self.assertEqual(newTf.getStr(), expectedFileContent)
     newTf.strSub(findStr="For Regexp", replaceStr="0")
     expectedFileContent = "Example File\n"
     expectedFileContent += "\n"
     expectedFileContent += "0 0 0\n"
     expectedFileContent += "\n"
     expectedFileContent += "0\n"
     expectedFileContent += "\n"
     expectedFileContent += "MyRegexp\n"
     expectedFileContent += ""
     self.assertEqual(newTf.getStr(), expectedFileContent)
Esempio n. 2
0
 def test_strSubDoubleFile(self):
     newFile0Name = "tmp0"
     newFile1Name = "tmp1"
     tf = TextFileObj(path=self.subReadFilePath)
     newTf0 = tf.copy(name=newFile0Name, father=self.testDir)
     newTf1 = tf.copy(name=newFile1Name, father=self.testDir)
     expectedOriginalFileContent = "Sample File\n"
     expectedOriginalFileContent += "\n"
     expectedOriginalFileContent += "For Regexp For Regexp For Regexp\n"
     expectedOriginalFileContent += "\n"
     expectedOriginalFileContent += "For Regexp\n"
     expectedOriginalFileContent += "\n"
     expectedOriginalFileContent += "MyRegexp\n"
     expectedOriginalFileContent += ""
     self.assertEqual(newTf0.getStr(), expectedOriginalFileContent)
     self.assertEqual(newTf1.getStr(), expectedOriginalFileContent)
     newTf1.strSub(findStr="Sample", replaceStr="Example")
     expectedFileContent = "Example File\n"
     expectedFileContent += "\n"
     expectedFileContent += "For Regexp For Regexp For Regexp\n"
     expectedFileContent += "\n"
     expectedFileContent += "For Regexp\n"
     expectedFileContent += "\n"
     expectedFileContent += "MyRegexp\n"
     expectedFileContent += ""
     self.assertEqual(newTf0.getStr(), expectedOriginalFileContent)
     self.assertEqual(newTf1.getStr(), expectedFileContent)
Esempio n. 3
0
 def test_constructorFather(self):
     fileName = "tmp.txt"
     tfo = TextFileObj(name=fileName, father=self.testDir)
     self.assertEqual(self.testDir.getDirList(), [])
     self.assertEqual(self.testDir.getFileList(), [fileName])
     self.assertEqual(os.listdir(self.testFolder), [])
     tfo.write()
     self.assertEqual(os.listdir(self.testFolder), [fileName])
Esempio n. 4
0
 def test_writeWithoutFolder(self):
     dir0Name = "tmp"
     dir1Name = "tmp2"
     fileName = "tmp.txt"
     dir0 = DirFileObj(name=dir0Name, father=self.testDir)
     dir1 = DirFileObj(name=dir1Name, father=dir0)
     tfo = TextFileObj(path=self.readFilePath)
     copyFile = tfo.copy(name=fileName, father=dir1)
     with self.assertRaises(RuntimeError):
         copyFile.write()
Esempio n. 5
0
 def test_constructorPath(self):
     tfo = TextFileObj(path=self.readFilePath)
     self.assertEqual(tfo.path, self.readFilePath)
     self.assertEqual(tfo.name, "file0.txt")
     self.assertEqual(tfo.father, tfo)
     expectedFileContent = "Sample File\n"
     expectedFileContent += "\n"
     expectedFileContent += "With\n"
     expectedFileContent += "\n"
     expectedFileContent += "5 lines of text\n"
     expectedFileContent += ""
     self.assertEqual(tfo.getStr(), expectedFileContent)
Esempio n. 6
0
 def test_copyFile(self):
     expectedFileContent = "Sample File\n"
     expectedFileContent += "\n"
     expectedFileContent += "With\n"
     expectedFileContent += "\n"
     expectedFileContent += "5 lines of text\n"
     expectedFileContent += ""
     dir0Name = "tmp"
     dir1Name = "tmp2"
     fileName = "tmp.txt"
     dir0 = DirFileObj(name=dir0Name, father=self.testDir)
     dir1 = DirFileObj(name=dir1Name, father=dir0)
     tfo = TextFileObj(path=self.readFilePath)
     self.assertEqual(dir1.getFileList(), [])
     tfo.copy(name=fileName, father=dir1)
     self.assertEqual(dir1.getFileList(), [fileName])
     self.assertEqual(dir1.getFile(fileName).getStr(), expectedFileContent)
     self.assertEqual(sorted(os.listdir(self.testFolder)), [])
     self.testDir.write()
     self.assertEqual(sorted(os.listdir(self.testFolder)), [dir0Name])
     self.assertEqual(sorted(os.listdir(self.testFolder + "/" + dir0Name)),
                      [dir1Name])
     self.assertEqual(
         sorted(
             os.listdir(self.testFolder + "/" + dir0Name + "/" + dir1Name)),
         [fileName])
     tfo = TextFileObj(path=self.testFolder + "/" + dir0Name + "/" +
                       dir1Name + "/" + fileName)
     self.assertEqual(tfo.getStr(), expectedFileContent)
Esempio n. 7
0
 def test_constructorSameFatherTwice(self):
     fileName = "tmp.txt"
     TextFileObj(name=fileName, father=self.testDir)
     with self.assertRaises(RuntimeError):
         TextFileObj(name=fileName, father=self.testDir)
Esempio n. 8
0
 def test_constructorFatherFileFatherSelf(self):
     tfo = TextFileObj(path=self.readFilePath)
     fileName = "tmp.txt"
     with self.assertRaises(RuntimeError):
         TextFileObj(name=fileName, father=tfo)
Esempio n. 9
0
 def test_constructorFatherFatherTypeError(self):
     fileName = "tmp.txt"
     with self.assertRaises(TypeError):
         TextFileObj(name=fileName, father=0)
Esempio n. 10
0
 def test_constructorFatherNameTypeError(self):
     with self.assertRaises(TypeError):
         TextFileObj(name=0, father=self.testDir)
Esempio n. 11
0
 def test_copyTwice(self):
     tfo = TextFileObj(path=self.readFilePath)
     tfo.copy(name="tmp", father=self.testDir)
     with self.assertRaises(RuntimeError):
         tfo.copy(name="tmp", father=self.testDir)
Esempio n. 12
0
 def test_emptyConstructor(self):
     with self.assertRaises(RuntimeError):
         TextFileObj()
Esempio n. 13
0
 def test_strSubReplaceStrTypeError(self):
     tf = TextFileObj(path=self.subReadFilePath)
     with self.assertRaises(TypeError):
         tf.strSub(findStr="Sample", replaceStr=0)
Esempio n. 14
0
 def test_copyMissingName(self):
     tfo = TextFileObj(path=self.readFilePath)
     with self.assertRaises(TypeError):
         tfo.copy(father=self.testDir)
Esempio n. 15
0
 def test_constructorPathTypeError(self):
     with self.assertRaises(TypeError):
         TextFileObj(path=0)
Esempio n. 16
0
 def test_copyMissingFather(self):
     tfo = TextFileObj(path=self.readFilePath)
     with self.assertRaises(TypeError):
         tfo.copy(name="tmp")
Esempio n. 17
0
 def test_copyNameTypeError(self):
     tfo = TextFileObj(path=self.readFilePath)
     with self.assertRaises(TypeError):
         tfo.copy(name=0, father=self.testDir)