예제 #1
0
 def testUTF(self):
     f = TextReader(PREFIX + "/test/test_doctest4.txt", "utf-8")
     f.cue("u'f")
     self.assertEqual(f.read(5),
                       "u'f\u00f6\u00f6") 
     f.cue("u'b")
     self.assertEqual(f.read(5),
                       "u'b\u0105r")
예제 #2
0
class Basic(unittest.TestCase):
    def setUp(self):
        self.f = TextReader(PREFIX + "/LICENSE.txt", linesep=TextReader.UNIX)

    def testReadline(self):
        self.assertEqual(self.f.readline(),
                         'A. HISTORY OF THE SOFTWARE')

        self.assertEqual(self.f.readline(),
                         '==========================')
        self.f.seek(0)

    def testIterateFile(self):
        self.assertEqual(self.f.bof(), True)
        self.assertEqual(self.f.eof(), False)
        for line in self.f:
            pass
        self.assertEqual(self.f.bof(), False)
        self.assertEqual(self.f.eof(), True)
        self.f.seek(0)
        
    def testReadparagraph(self):
        l = self.f.readparagraph()
        self.assertEqual(l, 'A. HISTORY OF THE SOFTWARE'+self.f.linesep+'==========================')
        l = self.f.readparagraph()
        self.assertEqual(l, 'Python was created in the early 1990s by Guido van Rossum at Stichting'+self.f.linesep+
                         'Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands'+self.f.linesep+
                         'as a successor of a language called ABC.  Guido remains Python\'s'+self.f.linesep+
                         'principal author, although it includes many contributions from others.')
        self.f.cuepast("to make these releases possible.") # next paragraph is separated by three newlines
        t = self.f.readparagraph()[:23]
        self.assertEqual(t,"B. TERMS AND CONDITIONS")
        self.f.seek(0)

    def testReadChunk(self):
        l = self.f.readchunk('(')
        l = self.f.readchunk(')')
        self.assertEqual(l,'CWI, see http://www.cwi.nl')
        self.f.seek(0)

    def testPeekLine(self):
        l = self.f.peekline()
        self.assertEqual(l, 'A. HISTORY OF THE SOFTWARE')
        l = self.f.peekline(4)
        self.assertEqual(l, 'Python was created in the early 1990s by Guido van Rossum at Stichting')
        self.f.seek(0)
        
    def testPeekParagraph(self):
        l = self.f.peekparagraph()
        self.assertEqual(l, 'A. HISTORY OF THE SOFTWARE'+self.f.linesep+'==========================')
        l = self.f.peekparagraph(2)
        self.assertEqual(l, 'Python was created in the early 1990s by Guido van Rossum at Stichting'+self.f.linesep+
                         'Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands'+self.f.linesep+
                         'as a successor of a language called ABC.  Guido remains Python\'s'+self.f.linesep+
                         'principal author, although it includes many contributions from others.')
        self.f.seek(0)

    

    def testPrevLine(self):
        self.f.readparagraph()
        self.f.readparagraph()
        self.assertEqual(self.f.prevline(3), # first two newlines, then the actual previous line (does this make sense?)
                         'principal author, although it includes many contributions from others.')
        self.assertEqual(self.f.prevline(6),
                         'Python was created in the early 1990s by Guido van Rossum at Stichting')
        self.f.seek(0)

    def testCue(self):
        self.f.cue("Guido")
        self.assertEqual(self.f.readline(),
                          'Guido van Rossum at Stichting')
        self.f.seek(0)

    def testCuePast(self):
        self.f.cuepast("Guido")
        self.assertEqual(self.f.readline(),
                          ' van Rossum at Stichting')
        self.f.seek(0)

    def testReadTo(self):
        self.assertEqual(self.f.readto("SOFTWARE"),
                          'A. HISTORY OF THE ')
예제 #3
0
 def testKOI8(self):
     f = TextReader(PREFIX + "/test/test_pep263.py", "koi8-r")
     f.cue('u"')
     self.assertEqual(f.read(7),
                       'u"\u041f\u0438\u0442\u043e\u043d')
예제 #4
0
 def testISO(self):
     f = TextReader(PREFIX + "/test/test_shlex.py", "iso-8859-1")
     f.cue(';|-|)|')
     f.readline()
     self.assertEqual(f.read(5),
                       "\u00e1\u00e9\u00ed\u00f3\u00fa")
예제 #5
0
class Basic(unittest.TestCase):
    def setUp(self):
        self.f = TextReader(PREFIX + "/LICENSE.txt", linesep=TextReader.UNIX)

    def testReadline(self):
        self.assertEqual(self.f.readline(), 'A. HISTORY OF THE SOFTWARE')

        self.assertEqual(self.f.readline(), '==========================')
        self.f.seek(0)

    def testIterateFile(self):
        self.assertEqual(self.f.bof(), True)
        self.assertEqual(self.f.eof(), False)
        for line in self.f:
            pass
        self.assertEqual(self.f.bof(), False)
        self.assertEqual(self.f.eof(), True)
        self.f.seek(0)

    def testReadparagraph(self):
        l = self.f.readparagraph()
        self.assertEqual(
            l, 'A. HISTORY OF THE SOFTWARE' + self.f.linesep +
            '==========================')
        l = self.f.readparagraph()
        self.assertEqual(
            l,
            'Python was created in the early 1990s by Guido van Rossum at Stichting'
            + self.f.linesep +
            'Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands'
            + self.f.linesep +
            'as a successor of a language called ABC.  Guido remains Python\'s'
            + self.f.linesep +
            'principal author, although it includes many contributions from others.'
        )
        self.f.cuepast("to make these releases possible."
                       )  # next paragraph is separated by three newlines
        t = self.f.readparagraph()[:23]
        self.assertEqual(t, "B. TERMS AND CONDITIONS")
        self.f.seek(0)

    def testReadChunk(self):
        l = self.f.readchunk('(')
        l = self.f.readchunk(')')
        self.assertEqual(l, 'CWI, see http://www.cwi.nl')
        self.f.seek(0)

    def testPeekLine(self):
        l = self.f.peekline()
        self.assertEqual(l, 'A. HISTORY OF THE SOFTWARE')
        l = self.f.peekline(4)
        self.assertEqual(
            l,
            'Python was created in the early 1990s by Guido van Rossum at Stichting'
        )
        self.f.seek(0)

    def testPeekParagraph(self):
        l = self.f.peekparagraph()
        self.assertEqual(
            l, 'A. HISTORY OF THE SOFTWARE' + self.f.linesep +
            '==========================')
        l = self.f.peekparagraph(2)
        self.assertEqual(
            l,
            'Python was created in the early 1990s by Guido van Rossum at Stichting'
            + self.f.linesep +
            'Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands'
            + self.f.linesep +
            'as a successor of a language called ABC.  Guido remains Python\'s'
            + self.f.linesep +
            'principal author, although it includes many contributions from others.'
        )
        self.f.seek(0)

    def testPrevLine(self):
        self.f.readparagraph()
        self.f.readparagraph()
        self.assertEqual(
            self.f.prevline(
                3
            ),  # first two newlines, then the actual previous line (does this make sense?)
            'principal author, although it includes many contributions from others.'
        )
        self.assertEqual(
            self.f.prevline(6),
            'Python was created in the early 1990s by Guido van Rossum at Stichting'
        )
        self.f.seek(0)

    def testCue(self):
        self.f.cue("Guido")
        self.assertEqual(self.f.readline(), 'Guido van Rossum at Stichting')
        self.f.seek(0)

    def testCuePast(self):
        self.f.cuepast("Guido")
        self.assertEqual(self.f.readline(), ' van Rossum at Stichting')
        self.f.seek(0)

    def testReadTo(self):
        self.assertEqual(self.f.readto("SOFTWARE"), 'A. HISTORY OF THE ')
예제 #6
0
 def testKOI8(self):
     f = TextReader(PREFIX + "/test/test_pep263.py", "koi8-r")
     f.cue('u"')
     self.assertEqual(f.read(7), 'u"\u041f\u0438\u0442\u043e\u043d')
예제 #7
0
 def testISO(self):
     f = TextReader(PREFIX + "/test/test_shlex.py", "iso-8859-1")
     f.cue(';|-|)|')
     f.readline()
     self.assertEqual(f.read(5), "\u00e1\u00e9\u00ed\u00f3\u00fa")
예제 #8
0
 def testUTF(self):
     f = TextReader(PREFIX + "/test/test_doctest4.txt", "utf-8")
     f.cue("u'f")
     self.assertEqual(f.read(5), "u'f\u00f6\u00f6")
     f.cue("u'b")
     self.assertEqual(f.read(5), "u'b\u0105r")