Esempio n. 1
0
 def test__with__1(self):
     strings = ['first line', 'second line', 'third line']
     with inputlines_.InputLines(io.StringIO('\n'.join(strings))) as lines:
         i = 0
         for line in lines:
             self.assertEqual(line, strings[i])
             self.assertEqual(line.loc().line, i + 1)
             i += 1
Esempio n. 2
0
    def test__next__1(self):
        input = io.StringIO('first line\nsecond line\nthird line')
        lines = inputlines_.InputLines(input)

        line = next(lines)
        self.assertEqual(line, 'first line')
        self.assertEqual(line.loc(), inputloc_.InputLoc(repr(input), 1))

        line = next(lines)
        self.assertEqual(line, 'second line')
        self.assertEqual(line.loc(), inputloc_.InputLoc(repr(input), 2))

        line = next(lines)
        self.assertEqual(line, 'third line')
        self.assertEqual(line.loc(), inputloc_.InputLoc(repr(input), 3))

        with self.assertRaises(StopIteration):
            next(lines)
Esempio n. 3
0
 def test__loc__1(self):
     input = io.StringIO('first line\nsecond line\nthird line')
     lines = inputlines_.InputLines(input)
     self.assertEqual(lines.loc(), inputloc_.InputLoc(repr(input), 1))
Esempio n. 4
0
 def test__line__1(self):
     input = io.StringIO('first line\nsecond line\nthird line')
     lines = inputlines_.InputLines(input)
     self.assertEqual(lines.line, 1)
Esempio n. 5
0
 def test__name__2(self):
     input = NamedStringIO('first line\nsecond line\nthird line')
     lines = inputlines_.InputLines(input)
     self.assertEqual(lines.name, input.name)
Esempio n. 6
0
 def test__init__2(self):
     msg = '%s is not an instance of %s' % (repr('foo'), repr(io.IOBase))
     with self.assertRaisesRegex(TypeError, msg):
         inputlines_.InputLines('foo')
Esempio n. 7
0
 def test__init__1(self):
     input = io.StringIO('first line\nsecond line\nthird line')
     lines = inputlines_.InputLines(input)
     self.assertEqual(lines._counter, 0)
     self.assertIs(lines._input, input)