Marco Ricci commited on 2024-09-11 21:06:13
Zeige 2 geänderte Dateien mit 18 Einfügungen und 19 Löschungen.
Fix the test `test_230b_store_config_custom_error` to actually test a custom error. Also expand GitHub issue references with the full URL.
| ... | ... |
@@ -72,7 +72,7 @@ _EMPTY_SELECTION = 'Empty selection' |
| 72 | 72 |
DERIVEPASSPHRASE_PATH variable, which defaults to |
| 73 | 73 |
`~/.derivepassphrase` on UNIX-like systems and |
| 74 | 74 |
`C:\Users\<user>\AppData\Roaming\Derivepassphrase` on Windows. |
| 75 |
- """ |
|
| 75 |
+ """, |
|
| 76 | 76 |
) |
| 77 | 77 |
@click.version_option(version=dpp.__version__, prog_name=PROG_NAME) |
| 78 | 78 |
@click.argument('subcommand_args', nargs=-1, type=click.UNPROCESSED)
|
| ... | ... |
@@ -1090,14 +1090,13 @@ contents go here |
| 1090 | 1090 |
def test_230_config_directory_nonexistant( |
| 1091 | 1091 |
self, monkeypatch: pytest.MonkeyPatch |
| 1092 | 1092 |
) -> None: |
| 1093 |
- """the-13th-letter/derivepassphrase#6""" |
|
| 1093 |
+ """https://github.com/the-13th-letter/derivepassphrase/issues/6""" |
|
| 1094 | 1094 |
runner = click.testing.CliRunner(mix_stderr=False) |
| 1095 | 1095 |
with tests.isolated_config( |
| 1096 | 1096 |
monkeypatch=monkeypatch, |
| 1097 | 1097 |
runner=runner, |
| 1098 | 1098 |
): |
| 1099 |
- os.remove('.derivepassphrase/settings.json')
|
|
| 1100 |
- os.rmdir('.derivepassphrase')
|
|
| 1099 |
+ shutil.rmtree('.derivepassphrase')
|
|
| 1101 | 1100 |
os_makedirs_called = False |
| 1102 | 1101 |
real_os_makedirs = os.makedirs |
| 1103 | 1102 |
|
| ... | ... |
@@ -1129,7 +1128,7 @@ contents go here |
| 1129 | 1128 |
def test_230a_config_directory_not_a_file( |
| 1130 | 1129 |
self, monkeypatch: pytest.MonkeyPatch |
| 1131 | 1130 |
) -> None: |
| 1132 |
- """the-13th-letter/derivepassphrase#6""" |
|
| 1131 |
+ """https://github.com/the-13th-letter/derivepassphrase/issues/6""" |
|
| 1133 | 1132 |
runner = click.testing.CliRunner(mix_stderr=False) |
| 1134 | 1133 |
with tests.isolated_config( |
| 1135 | 1134 |
monkeypatch=monkeypatch, |
| ... | ... |
@@ -1167,19 +1166,13 @@ contents go here |
| 1167 | 1166 |
monkeypatch=monkeypatch, |
| 1168 | 1167 |
runner=runner, |
| 1169 | 1168 |
): |
| 1170 |
- _save_config = cli._save_config |
|
| 1169 |
+ custom_error = 'custom error message' |
|
| 1171 | 1170 |
|
| 1172 |
- def obstruct_config_saving(*args: Any, **kwargs: Any) -> Any: |
|
| 1173 |
- with contextlib.suppress(FileNotFoundError): |
|
| 1174 |
- shutil.rmtree('.derivepassphrase')
|
|
| 1175 |
- with open( |
|
| 1176 |
- '.derivepassphrase', 'w', encoding='UTF-8' |
|
| 1177 |
- ) as outfile: |
|
| 1178 |
- print('Obstruction!!', file=outfile)
|
|
| 1179 |
- monkeypatch.setattr(cli, '_save_config', _save_config) |
|
| 1180 |
- return _save_config(*args, **kwargs) |
|
| 1171 |
+ def raiser(config: Any) -> None: |
|
| 1172 |
+ del config |
|
| 1173 |
+ raise RuntimeError(custom_error) |
|
| 1181 | 1174 |
|
| 1182 |
- monkeypatch.setattr(cli, '_save_config', obstruct_config_saving) |
|
| 1175 |
+ monkeypatch.setattr(cli, '_save_config', raiser) |
|
| 1183 | 1176 |
_result = runner.invoke( |
| 1184 | 1177 |
cli.derivepassphrase_vault, |
| 1185 | 1178 |
['--config', '-p'], |
| ... | ... |
@@ -1188,7 +1181,7 @@ contents go here |
| 1188 | 1181 |
) |
| 1189 | 1182 |
result = tests.ReadableResult.parse(_result) |
| 1190 | 1183 |
assert result.error_exit( |
| 1191 |
- error='Cannot store config' |
|
| 1184 |
+ error=custom_error |
|
| 1192 | 1185 |
), 'expected error exit and known error message' |
| 1193 | 1186 |
|
| 1194 | 1187 |
@pytest.mark.parametrize( |
| ... | ... |
@@ -1636,10 +1629,13 @@ class TestCLITransition: |
| 1636 | 1629 |
) |
| 1637 | 1630 |
result = tests.ReadableResult.parse(_result) |
| 1638 | 1631 |
assert result.clean_exit(empty_stderr=False), 'expected clean exit' |
| 1639 |
- assert result.stderr == f"""\ |
|
| 1632 |
+ assert ( |
|
| 1633 |
+ result.stderr |
|
| 1634 |
+ == f"""\ |
|
| 1640 | 1635 |
{cli.PROG_NAME}: Deprecation warning: A subcommand will be required in v1.0. See --help for available subcommands.
|
| 1641 | 1636 |
{cli.PROG_NAME}: Warning: Defaulting to subcommand "vault".
|
| 1642 | 1637 |
""" # noqa: E501 |
| 1638 |
+ ) |
|
| 1643 | 1639 |
assert json.loads(result.output) == tests.VAULT_V03_CONFIG_DATA |
| 1644 | 1640 |
|
| 1645 | 1641 |
@pytest.mark.parametrize( |
| ... | ... |
@@ -1664,10 +1660,13 @@ class TestCLITransition: |
| 1664 | 1660 |
) |
| 1665 | 1661 |
result = tests.ReadableResult.parse(_result) |
| 1666 | 1662 |
assert result.clean_exit(empty_stderr=False), 'expected clean exit' |
| 1667 |
- assert result.stderr == f"""\ |
|
| 1663 |
+ assert ( |
|
| 1664 |
+ result.stderr |
|
| 1665 |
+ == f"""\ |
|
| 1668 | 1666 |
{cli.PROG_NAME}: Deprecation warning: A subcommand will be required in v1.0. See --help for available subcommands.
|
| 1669 | 1667 |
{cli.PROG_NAME}: Warning: Defaulting to subcommand "vault".
|
| 1670 | 1668 |
""" # noqa: E501 |
| 1669 |
+ ) |
|
| 1671 | 1670 |
for c in charset: |
| 1672 | 1671 |
assert ( |
| 1673 | 1672 |
c not in result.output |
| 1674 | 1673 |