Skip to content

Commit b161093

Browse files
committed
Add tests
1 parent 51ef166 commit b161093

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/test_exec.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from custom_components.python_script import execute_script
2+
3+
hass = type("", (), {})
4+
logger = type("", (), {})
5+
6+
7+
def test_issue6():
8+
# https://github.com/AlexxIT/PythonScriptsPro/issues/6
9+
source = """def foobar():
10+
pass
11+
foobar()
12+
(lambda: foobar())()
13+
out = 123
14+
"""
15+
code = compile(source, "<string>", "exec")
16+
result = execute_script(hass, {}, logger, code)
17+
assert result == {"out": 123}
18+
19+
20+
def test_issue18():
21+
# https://github.com/AlexxIT/PythonScriptsPro/issues/18
22+
source = """import requests
23+
def foobar():
24+
from requests import session
25+
out = 123
26+
"""
27+
code = compile(source, "<string>", "exec")
28+
result = execute_script(hass, {}, logger, code)
29+
assert result == {"out": 123}
30+
31+
32+
def test_issue23():
33+
# https://github.com/AlexxIT/PythonScriptsPro/issues/23
34+
source = """from .secrets import get_secret
35+
out = 123
36+
"""
37+
code = compile(source, "<string>", "exec")
38+
result = execute_script(hass, {}, logger, code)
39+
assert result == {
40+
"error": "No module named 'custom_components.python_script.secrets'"
41+
}

0 commit comments

Comments
 (0)