Skip to content

Commit 249cbdd

Browse files
author
Nimrod Milo
committed
Added a test for the IPython part. Both with and without override
1 parent d4f3243 commit 249cbdd

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎tests/test_core.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sh
77

88
from dotenv import load_dotenv, find_dotenv, set_key
9+
from IPython.terminal.embed import InteractiveShellEmbed
910

1011

1112
def test_warns_if_file_does_not_exist():
@@ -84,3 +85,28 @@ def test_load_dotenv_override(cli):
8485
assert key_name in os.environ
8586
assert os.environ[key_name] == 'WORKS'
8687
sh.rm(dotenv_path)
88+
89+
90+
def test_ipython():
91+
tmpdir = os.path.realpath(tempfile.mkdtemp())
92+
os.chdir(tmpdir)
93+
filename = os.path.join(tmpdir, '.env')
94+
with open(filename, 'w') as f:
95+
f.write("MYNEWVALUE=q1w2e3\n")
96+
ipshell = InteractiveShellEmbed()
97+
ipshell.magic("load_ext dotenv")
98+
ipshell.magic("dotenv")
99+
assert os.environ["MYNEWVALUE"] == 'q1w2e3'
100+
101+
102+
def test_ipython_override():
103+
tmpdir = os.path.realpath(tempfile.mkdtemp())
104+
os.chdir(tmpdir)
105+
filename = os.path.join(tmpdir, '.env')
106+
os.environ["MYNEWVALUE"] = "OVERRIDE"
107+
with open(filename, 'w') as f:
108+
f.write("MYNEWVALUE=q1w2e3\n")
109+
ipshell = InteractiveShellEmbed()
110+
ipshell.magic("load_ext dotenv")
111+
ipshell.magic("dotenv -o")
112+
assert os.environ["MYNEWVALUE"] == 'q1w2e3'

0 commit comments

Comments
 (0)