forked from theskumar/python-dotenv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ipython.py
More file actions
50 lines (34 loc) · 1.25 KB
/
test_ipython.py
File metadata and controls
50 lines (34 loc) · 1.25 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
import os
import mock
@mock.patch.dict(os.environ, {}, clear=True)
def test_ipython_existing_variable_no_override(tmp_path):
from IPython.terminal.embed import InteractiveShellEmbed
dotenv_file = tmp_path / ".env"
dotenv_file.write_text("a=b\n")
os.chdir(str(tmp_path))
os.environ["a"] = "c"
ipshell = InteractiveShellEmbed()
ipshell.magic("load_ext dotenv")
ipshell.magic("dotenv")
assert os.environ == {"a": "c"}
@mock.patch.dict(os.environ, {}, clear=True)
def test_ipython_existing_variable_override(tmp_path):
from IPython.terminal.embed import InteractiveShellEmbed
dotenv_file = tmp_path / ".env"
dotenv_file.write_text("a=b\n")
os.chdir(str(tmp_path))
os.environ["a"] = "c"
ipshell = InteractiveShellEmbed()
ipshell.magic("load_ext dotenv")
ipshell.magic("dotenv -o")
assert os.environ == {"a": "b"}
@mock.patch.dict(os.environ, {}, clear=True)
def test_ipython_new_variable(tmp_path):
from IPython.terminal.embed import InteractiveShellEmbed
dotenv_file = tmp_path / ".env"
dotenv_file.write_text("a=b\n")
os.chdir(str(tmp_path))
ipshell = InteractiveShellEmbed()
ipshell.magic("load_ext dotenv")
ipshell.magic("dotenv")
assert os.environ == {"a": "b"}