Skip to content

Commit 3fb3f2c

Browse files
author
Saurabh Kumar
committed
improve test coverage
1 parent d4583b2 commit 3fb3f2c

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .fixtures import * # noqa

tests/fixtures.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from click.testing import CliRunner
3+
4+
5+
@pytest.fixture()
6+
def cli():
7+
return CliRunner()

tests/test_cli.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,32 @@ def test_unset():
3333
assert success is None
3434

3535

36-
def test_console_script():
37-
sh.touch(dotenv_path)
38-
sh.dotenv('-f', dotenv_path, 'set', 'HELLO', 'WORLD')
39-
output = sh.dotenv('-f', dotenv_path, 'get', 'HELLO', )
40-
assert output == 'HELLO="WORLD"\n'
41-
sh.rm(dotenv_path)
36+
def test_console_script(cli):
37+
with cli.isolated_filesystem():
38+
sh.touch(dotenv_path)
39+
sh.dotenv('-f', dotenv_path, 'set', 'HELLO', 'WORLD')
40+
output = sh.dotenv('-f', dotenv_path, 'get', 'HELLO', )
41+
assert output == 'HELLO="WORLD"\n'
42+
sh.rm(dotenv_path)
4243

44+
# should fail for not existing file
45+
result = cli.invoke(dotenv.set, ['my_key', 'my_value'])
46+
assert result.exit_code != 0
4347

44-
def test_default_path():
45-
sh.touch(dotenv_path)
46-
sh.cd(here)
47-
sh.dotenv('set', 'HELLO', 'WORLD')
48-
output = sh.dotenv('get', 'HELLO')
49-
assert output == 'HELLO="WORLD"\n'
50-
sh.rm(dotenv_path)
48+
# should fail for not existing file
49+
result = cli.invoke(dotenv.get, ['my_key'])
50+
assert result.exit_code != 0
51+
52+
# should fail for not existing file
53+
result = cli.invoke(dotenv.list, [])
54+
assert result.exit_code != 0
55+
56+
57+
def test_default_path(cli):
58+
with cli.isolated_filesystem():
59+
sh.touch(dotenv_path)
60+
sh.cd(here)
61+
sh.dotenv('set', 'HELLO', 'WORLD')
62+
output = sh.dotenv('get', 'HELLO')
63+
assert output == 'HELLO="WORLD"\n'
64+
sh.rm(dotenv_path)

0 commit comments

Comments
 (0)