def test_retrieve_message_invalid_input_image_error(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '48dj_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.failure
def test_retrieve_message_jpg_success(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: 'Test,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.success output = str(capsys.readouterr().out) assert output == 'Hello World. 你好,世界!!!\n'
def test_empty_command(mock_args, monkeypatch, capsys) -> None: """ Test if show help when command is empty """ # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.failure output = str(capsys.readouterr().out) assert output == """usage: cryptosteganography [-h] [-v] {save,retrieve} ...
def test_save_message_file_empty_error(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '7348hffbsd_33222_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.failure output = str(capsys.readouterr().out) assert output == "Failed: Message file content can't be empty\n"
def test_retrieve_message_input_image_file_not_found_error( mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '48dj_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.failure output = str(capsys.readouterr().out) assert output == 'Failed: Input file bablakjbla.png not found.\n'
def test_retrieve_message_invalid_password(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: 'Wrong Password') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.failure output = str(capsys.readouterr().out) assert output == 'No valid data found\n'
def test_save_message_empty_output_success(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '48dj_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.success output = str(capsys.readouterr().out) assert output == u'Output image output.png saved with success\n'
def test_save_message_file_success(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '7348hffbsd_33222_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.success output = str(capsys.readouterr().out) assert output == u'Output image {} saved with success\n'.format( OUTPUT_IMAGE)
def test_retrieve_message_as_file_success(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '48dj_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.success output = str(capsys.readouterr().out) assert output == '{} saved with success\n'.format(OUTPUT_MESSAGE_FILE) with open(OUTPUT_MESSAGE_FILE, 'rb') as f: message = f.read() assert message.decode('utf-8') == 'Hello World. 你好,世界!!!'
def test_retrieve_message_audio_file_success(mock_args, monkeypatch, capsys) -> None: # Pasword prompt monkeypatch.setattr('getpass.getpass', lambda prompt: '7348hffbsd_33222_你好,世界') # Call CLI with pytest.raises(SystemExit) as pytest_wrapped_e: sys.exit(cli.main()) assert pytest_wrapped_e.type == SystemExit assert pytest_wrapped_e.value.code == ExitStatus.success output = str(capsys.readouterr().out) assert output == '{} saved with success\n'.format( OUTPUT_MESSAGE_AUDIO_FILE) # Compare if original file is equal to retrieved file with open(OUTPUT_MESSAGE_AUDIO_FILE, 'rb') as audio_file: output_audio = audio_file.read() with open(INPUT_MESSAGE_AUDIO_FILE, 'rb') as original_audio_file: original_audio = original_audio_file.read() assert original_audio == output_audio
def test_argparse_input_empty(): # calling with no arguments goes to look at sys.argv, which is our arguments to py.test. with pytest.raises((SystemExit, NotImplementedError)): cli.main()