예제 #1
0
class TestIoread(unittest.TestCase):
    logger = logging.getLogger("Asrt.TestIoread")
    testFile = scriptsDir + "/resources/ioread_utf8.txt"
    testFileCSV = scriptsDir + "/resources/ioread_utf8.csv"

    testsString = [
        """Utf-8 test\nLatin characters é à ä\nNon latin characters 镕\n""",
        """Non latin characters 镕"""
    ]

    testList = [[
        'Utf-8 test', 'Latin characters é à ä', 'Non latin characters 镕'
    ]]

    def setUp(self):
        self.ioread = Ioread()

    ############
    # Tests
    #
    def testOpenFile(self):
        try:
            fd = self.ioread.openFile(self.testFile)
            self.ioread.closeFile(fd)
        except Exception:
            self.fail("testOpenFile raised ExceptionType unexpectedled")

    def testReadFileContent(self):
        strContent = self.ioread.readFileContent(self.testFile)
        self.assertEquals(self.testsString[0], strContent)

    def testReadFileContentList(self):
        strContentList = self.ioread.readFileContentList(self.testFile)
        self.assertEquals(3, len(strContentList))
        self.assertEquals(self.testsString[1], strContentList[2])

    def testReadCSV(self):
        strContentList = self.ioread.readCSV(self.testFileCSV)
        self.assertEquals(1, len(strContentList))
        self.assertEquals(strContentList, self.testList)

    def testWriteFileContent(self):
        strContent = self.testsString[0]
        self.ioread.writeFileContent(TEMPDIRUNITTEST + "/test.txt", strContent)

        readStrContent = self.ioread.readFileContent(self.testFile)
        self.assertEquals(strContent, readStrContent)
예제 #2
0
    def loadFromFile(regexFile):
        """Load regular expressions from a csv file.

           The file is assumed to be in CSV file format
           with tabs as fields separators and no quotes
           around fields.

           File format is:
                matching pattern, substitution pattern, 
                    regex type (substitution = 0, deletion = 1), comments

           param regexFile: a csv file
           return a compiled regular expression list with their
                  matching patterns 
        """
        RegexList.logger.info("Load regular expression from %s" % regexFile)

        io = Ioread()
        regexList = io.readCSV(regexFile, '\t')
        substitutionPatternList = RegexList.removeComments(regexList[1:])
        RegexList.logger.info("Done loading regular expressions")

        return substitutionPatternList
    def loadFromFile(regexFile):
        """Load regular expressions from a csv file.

           The file is assumed to be in CSV file format
           with tabs as fields separators and no quotes
           around fields.

           File format is:
                matching pattern, substitution pattern, 
                    regex type (substitution = 0, deletion = 1), comments

           param regexFile: a csv file
           return a compiled regular expression list with their
                  matching patterns 
        """
        RegexList.logger.info("Load regular expression from %s" % regexFile)
        
        io = Ioread()
        regexList = io.readCSV(regexFile,'\t')
        substitutionPatternList = RegexList.removeComments(regexList[1:])
        RegexList.logger.info("Done loading regular expressions")

        return substitutionPatternList
 def getTestList(self, strFileName):
     """Get CSV content of 'strFileName'.
     """
     io = Ioread()
     return io.readCSV(strFileName, delim='\t')
 def getTestList(self, strFileName):
     """Get CSV content of 'strFileName'.
     """
     io = Ioread()
     return io.readCSV(strFileName, delim='\t')