forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtest_shell_integration.py
More file actions
83 lines (60 loc) · 2.18 KB
/
test_shell_integration.py
File metadata and controls
83 lines (60 loc) · 2.18 KB
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
import importlib
import platform
import sys
from unittest.mock import Mock
import pythonrc
is_wsl = "microsoft-standard-WSL" in platform.release()
def test_decoration_success():
importlib.reload(pythonrc)
ps1 = pythonrc.PS1()
ps1.hooks.failure_flag = False
result = str(ps1)
if sys.platform != "win32" and (not is_wsl):
assert (
result
== "\x01\x1b]633;C\x07\x1b]633;E;None\x07\x1b]633;D;0\x07\x1b]633;A\x07\x02>>> \x01\x1b]633;B\x07\x02"
)
else:
pass
def test_decoration_failure():
importlib.reload(pythonrc)
ps1 = pythonrc.PS1()
ps1.hooks.failure_flag = True
result = str(ps1)
if sys.platform != "win32" and (not is_wsl):
assert (
result
== "\x01\x1b]633;C\x07\x1b]633;E;None\x07\x1b]633;D;1\x07\x1b]633;A\x07\x02>>> \x01\x1b]633;B\x07\x02"
)
else:
pass
def test_displayhook_call():
importlib.reload(pythonrc)
pythonrc.PS1()
mock_displayhook = Mock()
hooks = pythonrc.REPLHooks()
hooks.original_displayhook = mock_displayhook
hooks.my_displayhook("mock_value")
mock_displayhook.assert_called_once_with("mock_value")
def test_excepthook_call():
importlib.reload(pythonrc)
pythonrc.PS1()
mock_excepthook = Mock()
hooks = pythonrc.REPLHooks()
hooks.original_excepthook = mock_excepthook
hooks.my_excepthook("mock_type", "mock_value", "mock_traceback")
mock_excepthook.assert_called_once_with("mock_type", "mock_value", "mock_traceback")
if sys.platform == "darwin":
def test_print_statement_darwin(monkeypatch):
importlib.reload(pythonrc)
with monkeypatch.context() as m:
m.setattr("builtins.print", Mock())
importlib.reload(sys.modules["pythonrc"])
print.assert_any_call("Cmd click to launch VS Code Native REPL")
if sys.platform == "win32":
def test_print_statement_non_darwin(monkeypatch):
importlib.reload(pythonrc)
with monkeypatch.context() as m:
m.setattr("builtins.print", Mock())
importlib.reload(sys.modules["pythonrc"])
print.assert_any_call("Ctrl click to launch VS Code Native REPL")