FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SublimeLinter/tests/test_python_linter.py at master · SublimeLinter/SublimeLinter · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
SublimeLinter
/
SublimeLinter
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
270
Star
2k
Code
Issues
18
Pull requests
1
Discussions
Actions
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
SublimeLinter
/
tests
/
test_python_linter.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
156 lines (123 loc) · 4.57 KB
Breadcrumbs
SublimeLinter
/
tests
/
test_python_linter.py
Copy path
File metadata and controls
156 lines (123 loc) · 4.57 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import
os
import
shutil
from
unittesting
import
DeferrableTestCase
,
AWAIT_WORKER
from
SublimeLinter
.
tests
.
parameterized
import
parameterized
as
p
from
SublimeLinter
.
tests
.
mockito
import
(
mock
,
spy2
,
unstub
,
verify
,
when
,
)
import
sublime
from
SublimeLinter
import
lint
from
SublimeLinter
.
lint
import
elect
,
backend
,
linter
as
linter_module
,
util
def
make_fake_linter
(
view
):
class
FakeLinter
(
lint
.
PythonLinter
):
cmd
=
"mylinter"
defaults
=
{
"selector"
:
"foo"
}
settings
=
linter_module
.
get_linter_settings
(
FakeLinter
,
view
)
return
FakeLinter
(
view
,
settings
)
class
TestPythonLinters
(
DeferrableTestCase
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
view
=
sublime
.
active_window
().
new_file
()
# make sure we have a window to work with
s
=
sublime
.
load_settings
(
"Preferences.sublime-settings"
)
s
.
set
(
"close_windows_when_empty"
,
False
)
# it's just faster if we mock this out
when
(
linter_module
).
register_linter
(...).
thenReturn
(
None
)
@
classmethod
def
tearDownClass
(
cls
):
if
cls
.
view
:
cls
.
view
.
set_scratch
(
True
)
cls
.
view
.
close
()
unstub
()
def
tearDown
(
self
):
unstub
()
def
create_view
(
self
,
window
):
view
=
window
.
new_file
()
self
.
addCleanup
(
self
.
close_view
,
view
)
return
view
def
close_view
(
self
,
view
):
view
.
set_scratch
(
True
)
view
.
close
()
def
patch_home
(
self
,
home
):
previous_state
=
util
.
HOME
util
.
HOME
=
home
self
.
addCleanup
(
lambda
:
setattr
(
util
,
"HOME"
,
previous_state
))
def
test_globally_installed
(
self
):
linter
=
make_fake_linter
(
self
.
view
)
when
(
util
).
which
(...).
thenReturn
(
"fake.exe"
)
cmd
=
linter
.
get_cmd
()
self
.
assertEqual
(
cmd
, [
"fake.exe"
])
def
test_warn_if_not_globally_installed
(
self
):
linter
=
make_fake_linter
(
self
.
view
)
when
(
linter
.
logger
).
warning
(...).
thenReturn
(
None
)
cmd
=
linter
.
get_cmd
()
self
.
assertEqual
(
cmd
,
None
)
verify
(
linter
.
logger
).
warning
(...)
@
p
.
expand
([
(
"/p"
,),
(
"/p/a"
,),
(
"/p/a/b"
,),
])
def
test_locally_installed
(
self
,
ROOT_DIR
):
POSIX
=
sublime
.
platform
()
in
(
'osx'
,
'linux'
)
BIN
=
'bin'
if
POSIX
else
'Scripts'
PRESENT_BIN_PATH
=
os
.
path
.
join
(
ROOT_DIR
,
".venv"
,
BIN
)
spy2
(
os
.
path
.
isdir
)
when
(
os
.
path
).
isdir
(
PRESENT_BIN_PATH
).
thenReturn
(
True
)
when
(
self
.
view
).
file_name
().
thenReturn
(
"/p/a/b/f.js"
)
linter
=
make_fake_linter
(
self
.
view
)
when
(
shutil
).
which
(
"mylinter"
, ...).
thenReturn
(
None
)
when
(
shutil
).
which
(
"mylinter"
,
path
=
PRESENT_BIN_PATH
).
thenReturn
(
"fake.exe"
)
cmd
=
linter
.
get_cmd
()
self
.
assertEqual
(
cmd
, [
"fake.exe"
])
working_dir
=
linter
.
get_working_dir
()
self
.
assertEqual
(
working_dir
,
ROOT_DIR
)
self
.
assertEqual
(
linter
.
context
[
"project_root"
],
ROOT_DIR
)
self
.
assertEqual
(
linter
.
get_environment
().
get
(
"VIRTUAL_ENV"
),
os
.
path
.
join
(
ROOT_DIR
,
".venv"
)
)
self
.
assertTrue
(
linter
.
get_environment
().
get
(
"PATH"
).
startswith
(
PRESENT_BIN_PATH
)
)
def
test_disable_if_not_dependency
(
self
):
linter
=
make_fake_linter
(
self
.
view
)
linter
.
settings
[
'disable_if_not_dependency'
]
=
True
when
(
linter
).
notify_unassign
().
thenReturn
(
None
)
when
(
linter
.
logger
).
info
(...).
thenReturn
(
None
)
try
:
linter
.
get_cmd
()
except
linter_module
.
PermanentError
:
pass
verify
(
linter
.
logger
).
info
(
"Skipping 'fakelinter' since it is not installed locally.
\n
You "
"can change this behavior by setting 'disable_if_not_dependency' "
"to 'false'."
)
verify
(
linter
).
notify_unassign
()
def
test_disable_if_not_dependency_2
(
self
):
linter
=
make_fake_linter
(
self
.
view
)
linter
.
settings
[
'disable_if_not_dependency'
]
=
True
view_has_changed
=
lambda
:
False
sink
=
mock
()
when
(
sink
).
__call__
(...).
thenReturn
(
None
)
backend
.
form_lint_jobs_and_submit_them
(
[
elect
.
LinterInfo
(
name
=
linter
.
name
,
klass
=
linter
.
__class__
,
settings
=
linter
.
settings
,
context
=
linter
.
context
,
regions
=
[
sublime
.
Region
(
0
,
10
)],
runnable
=
True
)
],
self
.
view
,
view_has_changed
,
sink
)
yield
AWAIT_WORKER
yield
AWAIT_WORKER
verify
(
sink
).
__call__
(
linter
.
name
, [])
Back
|
FazBrowse Home
|
New Git URL