|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | import sh |
5 | | - |
| 5 | +from typing import Optional |
6 | 6 | import dotenv |
7 | 7 | from dotenv.cli import cli as dotenv_cli |
8 | 8 | from dotenv.version import __version__ |
9 | 9 |
|
10 | 10 |
|
11 | | -def test_list(cli, dotenv_file): |
| 11 | +@pytest.mark.parametrize( |
| 12 | + "format,content,expected", |
| 13 | + ( |
| 14 | + (None, "x='a b c'", '''x=a b c\n'''), |
| 15 | + ("simple", "x='a b c'", '''x=a b c\n'''), |
| 16 | + ("simple", """x='"a b c"'""", '''x="a b c"\n'''), |
| 17 | + ("simple", '''x="'a b c'"''', '''x='a b c'\n'''), |
| 18 | + ("json", "x='a b c'", '''{\n "x": "a b c"\n}\n'''), |
| 19 | + ("shell", "x='a b c'", "x='a b c'\n"), |
| 20 | + ("shell", """x='"a b c"'""", '''x='"a b c"'\n'''), |
| 21 | + ("shell", '''x="'a b c'"''', '''x=''"'"'a b c'"'"''\n'''), |
| 22 | + ("shell", "x='a\nb\nc'", "x='a\nb\nc'\n"), |
| 23 | + ("export", "x='a b c'", '''export x='a b c'\n'''), |
| 24 | + ) |
| 25 | +) |
| 26 | +def test_list(cli, dotenv_file, format: Optional[str], content: str, expected: str): |
12 | 27 | with open(dotenv_file, "w") as f: |
13 | | - f.write("a=b") |
| 28 | + f.write(content + '\n') |
| 29 | + |
| 30 | + args = ['--file', dotenv_file, 'list'] |
| 31 | + if format is not None: |
| 32 | + args.extend(['--format', format]) |
14 | 33 |
|
15 | | - result = cli.invoke(dotenv_cli, ['--file', dotenv_file, 'list']) |
| 34 | + result = cli.invoke(dotenv_cli, args) |
16 | 35 |
|
17 | | - assert (result.exit_code, result.output) == (0, result.output) |
| 36 | + assert (result.exit_code, result.output) == (0, expected) |
18 | 37 |
|
19 | 38 |
|
20 | 39 | def test_list_non_existent_file(cli): |
|
0 commit comments