Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
duarte-pompeu committed Dec 4, 2023
1 parent f5ed3e9 commit 49c34a5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ def dotenv_path(tmp_path):
path = tmp_path / '.env'
path.write_bytes(b'')
yield path


@pytest.fixture
def extra_dotenv_path(tmp_path):
path = tmp_path / '.env_extra'
path.write_bytes(b'')
yield path
32 changes: 30 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sh
from pathlib import Path
from typing import Optional
from typing import List, Optional

import pytest

Expand All @@ -25,7 +25,7 @@
("export", "x='a b c'", '''export x='a b c'\n'''),
)
)
def test_list(cli, dotenv_path, format: Optional[str], content: str, expected: str):
def test_list_single_file(cli, dotenv_path, format: Optional[str], content: str, expected: str):
dotenv_path.write_text(content + '\n')

args = ['--file', dotenv_path, 'list']
Expand All @@ -37,6 +37,34 @@ def test_list(cli, dotenv_path, format: Optional[str], content: str, expected: s
assert (result.exit_code, result.output) == (0, expected)


@pytest.mark.parametrize(
"format,contents,expected",
(
(None, ["x='a b c'", "y='a b c'"], '''x=a b c\ny=a b c\n'''),
(None, ["x='a b c'", "x='d e f'"], '''x=d e f\n'''),
(None, ["x='a b c'\ny=d e f", "x='x y z'"], '''x=x y z\ny=d e f\n'''),
)
)
def test_list_multi_file(
cli,
dotenv_path,
extra_dotenv_path,
format: Optional[str],
contents: List[str],
expected: str
):
dotenv_path.write_text(contents[0] + '\n')
extra_dotenv_path.write_text(contents[1] + '\n')

args = ['--file', dotenv_path, '--file', extra_dotenv_path, 'list']
if format is not None:
args.extend(['--format', format])

result = cli.invoke(dotenv_cli, args)

assert (result.exit_code, result.output) == (0, expected)


def test_list_non_existent_file(cli):
result = cli.invoke(dotenv_cli, ['--file', 'nx_file', 'list'])

Expand Down

0 comments on commit 49c34a5

Please sign in to comment.