Exemplo n.º 1
0
 def testEmptyFileSkipLines(self):  # fold>>
     f = io.FileReader(os.path.join(moduleDir(), "emptytestfile.txt"))
     self.assertEqual(f.currentPos(), -1)
     f.skipLines(10)
     self.assertEqual(f.isAtEOF(), True)
     f.skipLines(-10)
     self.assertEqual(f.isAtBOF(), True)
Exemplo n.º 2
0
 def testFindStringNotFound(self):  # fold>>
     "Findstring functionality/not found case"
     f = io.FileReader(os.path.join(moduleDir(), "testfile.txt"))
     self.assertEqual(f.findString('notfound'), '')
     self.assertEqual(f.isAtEOF(), True)
     self.assertEqual(f.findString('notfound', backward=True), '')
     self.assertEqual(f.isAtBOF(), True)
Exemplo n.º 3
0
    def testIsotopicMassesToken(self): # fold>>
        data = filesnippets.isotopicMasses()
        writeToTestFile(data)
        
        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.IsotopicMassesToken.match(reader, [])
        
        self.assertEqual(token.__class__, tokentypes.IsotopicMassesToken)
        self.assertEqual(reader.currentPos(), start_pos+8)
       
        atom_list = token.atomList()
        self.assertEqual(type(atom_list), type([]))
        self.assertEqual(len(atom_list), 4)

        self.assertEqual(atom_list[0][0], "O1")
        self.assertEqual(atom_list[0][1], "")
        self.assertEqual(atom_list[0][2].__class__, units.Quantity)
        self.assertEqual(atom_list[0][2], 15.994915 * units.dalton)

        self.assertEqual(atom_list[1][0], "H1")
        self.assertEqual(atom_list[1][1], "1")
        self.assertEqual(atom_list[1][2].__class__, units.Quantity )
        self.assertEqual(atom_list[1][2], 1.007825 * units.dalton)

        self.assertEqual(atom_list[2][0], "H1")
        self.assertEqual(atom_list[2][1], "2")
        self.assertEqual(atom_list[2][2].__class__, units.Quantity )
        self.assertEqual(atom_list[2][2], 1.007825 * units.dalton)

        self.assertEqual(atom_list[3][0], "C1")
        self.assertEqual(atom_list[3][1], "")
        self.assertEqual(atom_list[3][2].__class__, units.Quantity )
        self.assertEqual(atom_list[3][2], 12.0000 * units.dalton)
Exemplo n.º 4
0
    def testGetItem(self):  # fold>>

        f = io.FileReader(os.path.join(moduleDir(), "testfile.txt"))

        self.assertEqual(f[0], "1st line\n")
        self.assertEqual(f[1], "2nd line\n")
        self.assertEqual(f[2], "3rd line\n")
        f.close()
Exemplo n.º 5
0
 def testNormalModesEigenvaluesTokenNotMatching(self): # fold>>
     data = filesnippets.fileHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.NormalModesEigenvaluesToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 6
0
 def testMomentsOfInertiaTokenNotMatching(self): # fold>>
     data = filesnippets.momentsOfInertia()
     writeToTestFile("\n"+data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.MomentsOfInertiaToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 7
0
 def testDipoleMomentComponentsTokenNotMatching(self): # fold>>
     data = filesnippets.optimizationNextGeometry()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.DipoleMomentComponentsToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 8
0
 def testFindStringCounted(self):  # fold>>
     "Findstring functionality/counted search"
     f = io.FileReader(os.path.join(moduleDir(), "testfile.txt"))
     self.assertEqual(f.findString("line", 2), "2nd line\n")
     self.assertEqual(f.currentLine(), "2nd line\n")
     f.toEOF()
     self.assertEqual(f.findString("line", 2, backward=True), "2nd line\n")
     self.assertEqual(f.currentLine(), "2nd line\n")
Exemplo n.º 9
0
 def testCartesianCoordinatesTokenNotMatching(self): # fold>>
     data = filesnippets.fileHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.CartesianCoordinatesToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 10
0
 def testSecondHyperpolarizabilityTokenNotMatching(self): # fold>>
     data = filesnippets.optimizationNextGeometry()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.SecondHyperpolarizabilityToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 11
0
 def testOptimizationInfoTokenNotMatching(self): # fold>>
     data = filesnippets.fileHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.OptimizationInfoToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 12
0
 def testRegexpCurlineNeverEvaluated(self):  # fold>>
     f = io.FileReader(os.path.join(moduleDir(), "testfile.txt"))
     f.toPos(0)
     self.assertEqual(f.findRegexp('line'), ("2nd line\n", ))
     self.assertEqual(f.currentLine(), "2nd line\n")
     f.toPos(2)
     self.assertEqual(f.findRegexp('line', backward=True), ("2nd line\n", ))
     self.assertEqual(f.currentLine(), "2nd line\n")
Exemplo n.º 13
0
 def testAtomsAndBasisSetsTokenNotMatching(self): # fold>>
     data = filesnippets.fileHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.AtomsAndBasisSetsToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 14
0
 def testFinalGeometryEnergyTokenNotMatching(self): # fold>>
     data = filesnippets.fileHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.FinalGeometryEnergyToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 15
0
 def testRegexpBasic(self):  # fold>>
     "Findregexp functionality/basic search"
     f = io.FileReader(os.path.join(moduleDir(), "testfile.txt"))
     self.assertEqual(f.findRegexp("3rd"), ("3rd line\n", ))
     self.assertEqual(f.currentLine(), "3rd line\n")
     f.toEOF()
     self.assertEqual(f.findRegexp("1st", backward=True), ("1st line\n", ))
     self.assertEqual(f.currentLine(), "1st line\n")
Exemplo n.º 16
0
 def testTotalMassTokenNotMatching(self): # fold>>
     data = filesnippets.totalMass()
     writeToTestFile("\n"+data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.TotalMassToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 17
0
 def testGeometryConvergenceNumIterationsTokenNotMatching(self): # fold>>
     data = filesnippets.fileHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     token = tokentypes.GeometryConvergenceNumIterationsToken.match(reader, [])
     
     self.assertEqual(token, None)
Exemplo n.º 18
0
    def testBackwardIRCHeaderToken(self):
        data = filesnippets.backwardIRCHeader()
        writeToTestFile(data)

        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.BackwardIRCHeaderToken.match(reader, [])
        self.assertEqual(token.__class__, tokentypes.BackwardIRCHeaderToken)
        self.assertEqual(reader.currentPos(), start_pos + 1)
Exemplo n.º 19
0
 def testFindStringCurlineNeverEvaluated(self):  # fold>>
     "Findstring functionality/curline never evaluated"
     f = io.FileReader(os.path.join(moduleDir(), "testfile.txt"))
     f.toPos(0)
     self.assertEqual(f.findString('line'), "2nd line\n")
     self.assertEqual(f.currentLine(), "2nd line\n")
     f.toPos(2)
     self.assertEqual(f.findString('line', backward=True), "2nd line\n")
     self.assertEqual(f.currentLine(), "2nd line\n")
Exemplo n.º 20
0
    def testDCReachedToken(self):
        data = filesnippets.DCReached()
        writeToTestFile(data)

        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.DCReachedToken.match(reader, [])
        self.assertEqual(token.__class__, tokentypes.DCReachedToken)
        self.assertEqual(reader.currentPos(), start_pos + 8)
Exemplo n.º 21
0
 def testAtomsAndBasisSetsToken3(self): # fold>>
     data = filesnippets.atomsAndBasisSetsTable3()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     start_pos = reader.currentPos()
     token = tokentypes.AtomsAndBasisSetsToken.match(reader, [])
     
     self.assertEqual(token.__class__, tokentypes.AtomsAndBasisSetsToken)
Exemplo n.º 22
0
    def testNormalModesTSToken(self):
        data = filesnippets.normalModesTS()
        writeToTestFile(data)

        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.NormalModesTSToken.match(reader, [])
        self.assertEqual(token.__class__, tokentypes.NormalModesTSToken)
        self.assertEqual(reader.currentPos(), start_pos + 3)
        self.assertEqual(len(token.eigenvalues()), 6)
Exemplo n.º 23
0
    def testMinimumPointFoundHeaderToken(self):
        data = filesnippets.minimumPointFoundHeader()
        writeToTestFile(data)

        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.MinimumPointFoundHeaderToken.match(reader, [])
        self.assertEqual(token.__class__,
                         tokentypes.MinimumPointFoundHeaderToken)
        self.assertEqual(reader.currentPos(), start_pos + 1)
Exemplo n.º 24
0
 def testEmptyFileSeeks(self):  # fold>>
     f = io.FileReader(os.path.join(moduleDir(), "emptytestfile.txt"))
     self.assertEqual(f.currentPos(), -1)
     self.assertEqual(f.isAtBOF(), True)
     f.toEOF()
     self.assertEqual(f.currentPos(), 0)
     self.assertEqual(f.isAtEOF(), True)
     f.toBOF()
     self.assertEqual(f.currentPos(), -1)
     self.assertEqual(f.isAtBOF(), True)
Exemplo n.º 25
0
    def testResponseHeaderToken(self): # fold>>
        data = filesnippets.responseHeader()

        writeToTestFile(data)
        
        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.ResponseHeaderToken.match(reader, [])
        self.assertEqual(token.__class__, tokentypes.ResponseHeaderToken)
        self.assertEqual(reader.currentPos(), start_pos+2)
Exemplo n.º 26
0
 def testEndOfOptimizationHeaderToken(self): # fold>>
     data = filesnippets.endOfOptimizationHeader()
     writeToTestFile(data)
     
     reader = io.FileReader(testFilePath())
     start_pos = reader.currentPos()
     token = tokentypes.EndOfOptimizationHeaderToken.match(reader, [])
     
     self.assertEqual(token.__class__, tokentypes.EndOfOptimizationHeaderToken)
     self.assertEqual(reader.currentPos(), start_pos+1)
Exemplo n.º 27
0
    def testHeaderEquilibriumToken(self):
        data = filesnippets.headerEquilibrium()
        writeToTestFile(data)

        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.HeaderEquilibriumToken.match(reader, [])

        self.assertEqual(token.__class__, tokentypes.HeaderEquilibriumToken)
        self.assertEqual(reader.currentPos(), start_pos + 1)
Exemplo n.º 28
0
    def testOptimizationFinalStructureToken(self):
        data = filesnippets.optimizationFinalStructure()
        writeToTestFile(data)

        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.OptimizationFinalStructureToken.match(reader, [])
        self.assertEqual(token.__class__,
                         tokentypes.OptimizationFinalStructureToken)
        self.assertEqual(reader.currentPos(), start_pos + 8)
Exemplo n.º 29
0
 def tokenize(self, filename):
     reader = io.FileReader(filename)
     token_list = []
     while not reader.isAtEOF():
         token = self._tryResolveToken(reader, token_list)
         if token is None:
             reader.readline()
         else:
             token_list.append(token)
             yield token
     raise StopIteration
Exemplo n.º 30
0
    def testSevereErrorToken(self): # fold>>
        data = filesnippets.severeError()

        writeToTestFile(data)
        
        reader = io.FileReader(testFilePath())
        start_pos = reader.currentPos()
        token = tokentypes.SevereErrorToken.match(reader, [])
        self.assertEqual(token.__class__, tokentypes.SevereErrorToken)
        self.assertEqual(reader.currentPos(), start_pos+5)
        self.assertEqual(token.reason(), "*** FNDGEO *** No acceptable step found.")