mock no_args tests

This commit is contained in:
scito 2022-12-28 23:37:21 +01:00
parent 9f0872c2d0
commit 95e7d73173
3 changed files with 30 additions and 13 deletions

View File

@ -2,3 +2,4 @@ wheel
pytest
flake8
pylint
pytest-mock

View File

@ -1,3 +1,3 @@
#!/bin/sh
cd /extract
pip install -U pytest && pytest "$@"
pip install -U pytest pytest-mock && pytest "$@"

View File

@ -433,8 +433,24 @@ def test_extract_help(capsys):
assert e.type == SystemExit
assert e.value.code == 0
@pytest.mark.skipif(qreader_available, reason="Cannot test interactive mode")
def test_extract_no_arguments(capsys):
def test_extract_no_arguments(capsys, mocker):
if qreader_available:
# Arrange
otps = read_json('example_output.json')
mocker.patch('extract_otp_secret_keys.extract_otps_from_camera', return_value=otps)
# Act
extract_otp_secret_keys.main(['-c', '-'])
# Assert
captured = capsys.readouterr()
expected_csv = read_csv('example_output.csv')
actual_csv = read_csv_str(captured.out)
assert actual_csv == expected_csv
assert captured.err == ''
else:
# Act
with pytest.raises(SystemExit) as e:
extract_otp_secret_keys.main([])