|
6 | 6 | import sh |
7 | 7 |
|
8 | 8 | from dotenv import load_dotenv, find_dotenv, set_key |
| 9 | +from IPython.terminal.embed import InteractiveShellEmbed |
9 | 10 |
|
10 | 11 |
|
11 | 12 | def test_warns_if_file_does_not_exist(): |
@@ -84,3 +85,28 @@ def test_load_dotenv_override(cli): |
84 | 85 | assert key_name in os.environ |
85 | 86 | assert os.environ[key_name] == 'WORKS' |
86 | 87 | 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