3 from Cython
import StringIOTree
as stringtree
21 print 'or coffee?' # line 16
24 linemap
= dict(enumerate(code
.splitlines()))
26 class TestStringIOTree(unittest
.TestCase
):
29 self
.tree
= stringtree
.StringIOTree()
31 def test_markers(self
):
32 assert not self
.tree
.allmarkers()
34 def test_insertion(self
):
35 self
.write_lines((1, 2, 3))
36 line_4_to_6_insertion_point
= self
.tree
.insertion_point()
37 self
.write_lines((7, 8))
38 line_9_to_13_insertion_point
= self
.tree
.insertion_point()
39 self
.write_lines((14, 15, 16))
41 line_4_insertion_point
= line_4_to_6_insertion_point
.insertion_point()
42 self
.write_lines((5, 6), tree
=line_4_to_6_insertion_point
)
44 line_9_to_12_insertion_point
= (
45 line_9_to_13_insertion_point
.insertion_point())
46 self
.write_line(13, tree
=line_9_to_13_insertion_point
)
48 self
.write_line(4, tree
=line_4_insertion_point
)
49 self
.write_line(9, tree
=line_9_to_12_insertion_point
)
50 line_10_insertion_point
= line_9_to_12_insertion_point
.insertion_point()
51 self
.write_line(11, tree
=line_9_to_12_insertion_point
)
52 self
.write_line(10, tree
=line_10_insertion_point
)
53 self
.write_line(12, tree
=line_9_to_12_insertion_point
)
55 self
.assertEqual(self
.tree
.allmarkers(), range(1, 17))
56 self
.assertEqual(code
.strip(), self
.tree
.getvalue().strip())
59 def write_lines(self
, linenos
, tree
=None):
60 for lineno
in linenos
:
61 self
.write_line(lineno
, tree
=tree
)
63 def write_line(self
, lineno
, tree
=None):
66 tree
.markers
.append(lineno
)
67 tree
.write(linemap
[lineno
] + '\n')