@@ -208,7 +208,7 @@ def tokenize_template(template_text):
208
208
... %% first line
209
209
... %% second line
210
210
... '''):
211
- ... print ( kind, text.strip().split('\n',1)[0])
211
+ ... print(( kind, text.strip().split('\n',1)[0]) )
212
212
('literal', 'This is $some$ literal stuff containing a')
213
213
('substitutionOpen', '${')
214
214
('literal', 'followed by a %{...} block:')
@@ -361,7 +361,7 @@ def code_starts_with_dedent_keyword(source_lines):
361
361
>>> code_starts_with_dedent_keyword(split_lines('except ifSomethingElse:'))
362
362
True
363
363
>>> code_starts_with_dedent_keyword(
364
- split_lines('\n# comment\nelse: # yes'))
364
+ ... split_lines('\n# comment\nelse: # yes'))
365
365
True
366
366
"""
367
367
token_text = None
@@ -417,7 +417,7 @@ def token_generator(self, base_tokens):
417
417
... literally
418
418
... ''')
419
419
>>> while ctx.token_kind:
420
- ... print ( ctx.token_kind, ctx.code_text or ctx.token_text)
420
+ ... print(( ctx.token_kind, ctx.code_text or ctx.token_text) )
421
421
... ignored = ctx.next_token()
422
422
('literal', '\n')
423
423
('gybLinesOpen', 'for x in y:\n')
@@ -435,7 +435,7 @@ def token_generator(self, base_tokens):
435
435
... THIS SHOULD NOT APPEAR IN THE OUTPUT
436
436
... ''')
437
437
>>> while ctx.token_kind:
438
- ... print ( ctx.token_kind, ctx.code_text or ctx.token_text)
438
+ ... print(( ctx.token_kind, ctx.code_text or ctx.token_text) )
439
439
... ignored = ctx.next_token()
440
440
('literal', 'Nothing\n')
441
441
('gybLinesOpen', 'if x:\n')
@@ -450,20 +450,20 @@ def token_generator(self, base_tokens):
450
450
... '''% for x in [1, 2, 3]:
451
451
... % if x == 1:
452
452
... literal1
453
- ... % elif x > 1: # add an output line after this line to fix bug
453
+ ... % elif x > 1: # add output line here to fix bug
454
454
... % if x == 2:
455
455
... literal2
456
456
... % end
457
457
... % end
458
458
... % end
459
459
... ''')
460
460
>>> while ctx.token_kind:
461
- ... print ( ctx.token_kind, ctx.code_text or ctx.token_text)
461
+ ... print(( ctx.token_kind, ctx.code_text or ctx.token_text) )
462
462
... ignored = ctx.next_token()
463
463
('gybLinesOpen', 'for x in [1, 2, 3]:\n')
464
464
('gybLinesOpen', ' if x == 1:\n')
465
465
('literal', 'literal1\n')
466
- ('gybLinesOpen', 'elif x > 1: # add output line here to fix bug\n')
466
+ ('gybLinesOpen', 'elif x > 1: # add output line here to fix bug\n')
467
467
('gybLinesOpen', ' if x == 2:\n')
468
468
('literal', 'literal2\n')
469
469
('gybLinesClose', '% end')
@@ -730,17 +730,17 @@ def parse_template(filename, text=None):
730
730
If text is supplied, it is assumed to be the contents of the file,
731
731
as a string.
732
732
733
- >>> print parse_template('dummy.file', text=
733
+ >>> print( parse_template('dummy.file', text=
734
734
... '''% for x in [1, 2, 3]:
735
735
... % if x == 1:
736
736
... literal1
737
- ... % elif x > 1: # add an output line after this line to fix the bug
737
+ ... % elif x > 1: # add output line after this line to fix bug
738
738
... % if x == 2:
739
739
... literal2
740
740
... % end
741
741
... % end
742
742
... % end
743
- ... ''')
743
+ ... '''))
744
744
Block:
745
745
[
746
746
Code:
@@ -755,7 +755,7 @@ def parse_template(filename, text=None):
755
755
{
756
756
if x == 1:
757
757
__children__[0].execute(__context__)
758
- elif x > 1: # add output line after this line to fix bug
758
+ elif x > 1: # add output line after this line to fix bug
759
759
__children__[1].execute(__context__)
760
760
}
761
761
[
@@ -784,8 +784,9 @@ def parse_template(filename, text=None):
784
784
]
785
785
]
786
786
787
- >>> print parse_template(
788
- >>> 'dummy.file', text='%for x in range(10):\n% print x\n%end\njuicebox')
787
+ >>> print(parse_template(
788
+ ... 'dummy.file',
789
+ ... text='%for x in range(10):\n% print(x)\n%end\njuicebox'))
789
790
Block:
790
791
[
791
792
Code:
@@ -796,22 +797,22 @@ def parse_template(filename, text=None):
796
797
[
797
798
Block:
798
799
[
799
- Code: {print x } []
800
+ Code: {print(x) } []
800
801
]
801
802
]
802
803
Literal:
803
804
juicebox
804
805
]
805
806
806
- >>> print parse_template('/dummy.file', text=
807
+ >>> print( parse_template('/dummy.file', text=
807
808
... '''Nothing
808
809
... % if x:
809
810
... % for i in range(3):
810
811
... ${i}
811
812
... % end
812
813
... % else:
813
814
... THIS SHOULD NOT APPEAR IN THE OUTPUT
814
- ... ''')
815
+ ... '''))
815
816
Block:
816
817
[
817
818
Literal:
@@ -848,10 +849,10 @@ def parse_template(filename, text=None):
848
849
]
849
850
]
850
851
851
- >>> print parse_template('dummy.file', text='''%
852
+ >>> print( parse_template('dummy.file', text='''%
852
853
... %for x in y:
853
- ... % print y
854
- ... ''')
854
+ ... % print(y)
855
+ ... '''))
855
856
Block:
856
857
[
857
858
Code:
@@ -862,18 +863,18 @@ def parse_template(filename, text=None):
862
863
[
863
864
Block:
864
865
[
865
- Code: {print y } []
866
+ Code: {print(y) } []
866
867
]
867
868
]
868
869
]
869
870
870
- >>> print parse_template('dummy.file', text='''%
871
+ >>> print( parse_template('dummy.file', text='''%
871
872
... %if x:
872
- ... % print y
873
+ ... % print(y)
873
874
... AAAA
874
875
... %else:
875
876
... BBBB
876
- ... ''')
877
+ ... '''))
877
878
Block:
878
879
[
879
880
Code:
@@ -886,7 +887,7 @@ def parse_template(filename, text=None):
886
887
[
887
888
Block:
888
889
[
889
- Code: {print y } []
890
+ Code: {print(y) } []
890
891
Literal:
891
892
AAAA
892
893
]
@@ -898,14 +899,14 @@ def parse_template(filename, text=None):
898
899
]
899
900
]
900
901
901
- >>> print parse_template('dummy.file', text='''%
902
+ >>> print( parse_template('dummy.file', text='''%
902
903
... %if x:
903
- ... % print y
904
+ ... % print(y)
904
905
... AAAA
905
906
... %# This is a comment
906
907
... %else:
907
908
... BBBB
908
- ... ''')
909
+ ... '''))
909
910
Block:
910
911
[
911
912
Code:
@@ -919,7 +920,7 @@ def parse_template(filename, text=None):
919
920
[
920
921
Block:
921
922
[
922
- Code: {print y } []
923
+ Code: {print(y) } []
923
924
Literal:
924
925
AAAA
925
926
]
@@ -931,14 +932,14 @@ def parse_template(filename, text=None):
931
932
]
932
933
]
933
934
934
- >>> print parse_template('dummy.file', text='''\
935
+ >>> print( parse_template('dummy.file', text='''\
935
936
... %for x in y:
936
937
... AAAA
937
938
... %if x:
938
939
... BBBB
939
940
... %end
940
941
... CCCC
941
- ... ''')
942
+ ... '''))
942
943
Block:
943
944
[
944
945
Code:
@@ -986,7 +987,8 @@ def execute_template(ast, line_directive='', **local_bindings):
986
987
... % else:
987
988
... THIS SHOULD NOT APPEAR IN THE OUTPUT
988
989
... ''')
989
- >>> print execute_template(ast, line_directive='//#sourceLocation', x=1),
990
+ >>> out = execute_template(ast, line_directive='//#sourceLocation', x=1)
991
+ >>> print(out, end="")
990
992
//#sourceLocation(file: "/dummy.file", line: 1)
991
993
Nothing
992
994
//#sourceLocation(file: "/dummy.file", line: 4)
@@ -1004,7 +1006,8 @@ def execute_template(ast, line_directive='', **local_bindings):
1004
1006
... % end
1005
1007
... ${a}
1006
1008
... ''')
1007
- >>> print execute_template(ast, line_directive='//#sourceLocation', x=1),
1009
+ >>> out = execute_template(ast, line_directive='//#sourceLocation', x=1)
1010
+ >>> print(out, end="")
1008
1011
//#sourceLocation(file: "/dummy.file", line: 1)
1009
1012
Nothing
1010
1013
//#sourceLocation(file: "/dummy.file", line: 6)
@@ -1112,7 +1115,8 @@ def succ(a):
1112
1115
1113
1116
if args .test or args .verbose_test :
1114
1117
import doctest
1115
- if doctest .testmod (verbose = args .verbose_test ).failed :
1118
+ selfmod = sys .modules [__name__ ]
1119
+ if doctest .testmod (selfmod , verbose = args .verbose_test ).failed :
1116
1120
sys .exit (1 )
1117
1121
1118
1122
bindings = dict (x .split ('=' , 1 ) for x in args .defines )
0 commit comments