FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bpython/bpython/test/test_preprocess.py at master · allgo27/bpython · GitHub
allgo27
/
bpython
Public
forked from
bpython/bpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bpython
/
bpython
/
test
/
test_preprocess.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (87 loc) · 3.34 KB
Breadcrumbs
bpython
/
bpython
/
test
/
test_preprocess.py
Copy path
File metadata and controls
108 lines (87 loc) · 3.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# encoding: utf-8
from
code
import
compile_command
as
compiler
from
functools
import
partial
import
difflib
import
inspect
import
re
from
bpython
.
curtsiesfrontend
.
interpreter
import
code_finished_will_parse
from
bpython
.
curtsiesfrontend
.
preprocess
import
preprocess
from
bpython
.
test
import
unittest
from
bpython
.
test
.
fodder
import
original
,
processed
skip
=
unittest
.
skip
preproc
=
partial
(
preprocess
,
compiler
=
compiler
)
def
get_fodder_source
(
test_name
):
pattern
=
r"#StartTest-%s\n(.*?)#EndTest"
%
(
test_name
,)
orig
,
xformed
=
[
re
.
search
(
pattern
,
inspect
.
getsource
(
module
),
re
.
DOTALL
)
for
module
in
[
original
,
processed
]
]
if
not
orig
:
raise
ValueError
(
"Can't locate test %s in original fodder file"
%
(
test_name
,)
)
if
not
xformed
:
raise
ValueError
(
"Can't locate test %s in processed fodder file"
%
(
test_name
,)
)
return
orig
.
group
(
1
),
xformed
.
group
(
1
)
class
TestPreprocessing
(
unittest
.
TestCase
):
def
assertCompiles
(
self
,
source
):
finished
,
parsable
=
code_finished_will_parse
(
source
,
compiler
)
return
finished
and
parsable
def
test_indent_empty_lines_nops
(
self
):
self
.
assertEqual
(
preproc
(
"hello"
),
"hello"
)
self
.
assertEqual
(
preproc
(
"hello
\n
goodbye"
),
"hello
\n
goodbye"
)
self
.
assertEqual
(
preproc
(
"a
\n
b
\n
c
\n
"
),
"a
\n
b
\n
c
\n
"
)
def
assertShowWhitespaceEqual
(
self
,
a
,
b
):
self
.
assertEqual
(
a
,
b
,
""
.
join
(
difflib
.
context_diff
(
a
.
replace
(
" "
,
"~"
).
splitlines
(
True
),
b
.
replace
(
" "
,
"~"
).
splitlines
(
True
),
fromfile
=
"actual"
,
tofile
=
"expected"
,
n
=
5
,
)
),
)
def
assertDefinitionIndented
(
self
,
obj
):
name
=
obj
.
__name__
obj2
=
getattr
(
processed
,
name
)
orig
=
inspect
.
getsource
(
obj
)
xformed
=
inspect
.
getsource
(
obj2
)
self
.
assertShowWhitespaceEqual
(
preproc
(
orig
),
xformed
)
self
.
assertCompiles
(
xformed
)
def
assertLinesIndented
(
self
,
test_name
):
orig
,
xformed
=
get_fodder_source
(
test_name
)
self
.
assertShowWhitespaceEqual
(
preproc
(
orig
),
xformed
)
self
.
assertCompiles
(
xformed
)
def
assertIndented
(
self
,
obj_or_name
):
if
isinstance
(
obj_or_name
,
str
):
self
.
assertLinesIndented
(
obj_or_name
)
else
:
self
.
assertDefinitionIndented
(
obj_or_name
)
def
test_empty_line_between_methods
(
self
):
self
.
assertIndented
(
original
.
BlankLineBetweenMethods
)
def
test_empty_line_within_class
(
self
):
self
.
assertIndented
(
original
.
BlankLineInFunction
)
def
test_blank_lines_in_for_loop
(
self
):
self
.
assertIndented
(
"blank_lines_in_for_loop"
)
@
skip
(
"More advanced technique required: need to try compiling and "
"backtracking"
)
def
test_blank_line_in_try_catch
(
self
):
self
.
assertIndented
(
"blank_line_in_try_catch"
)
@
skip
(
"More advanced technique required: need to try compiling and "
"backtracking"
)
def
test_blank_line_in_try_catch_else
(
self
):
self
.
assertIndented
(
"blank_line_in_try_catch_else"
)
def
test_blank_trailing_line
(
self
):
self
.
assertIndented
(
"blank_trailing_line"
)
def
test_tabs
(
self
):
self
.
assertIndented
(
original
.
tabs
)
Back
|
FazBrowse Home
|
New Git URL