forked from CLCK-Data-Aug2023/caesar-cipher-argearhart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
24 lines (21 loc) · 950 Bytes
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pytest
import importlib
import sys
import io
import builtins
@pytest.mark.parametrize("original_sentence,encrypted_sentence",
[['python is fun!', 'udymts nx kzs!'],
['aaa', 'fff'],
['xyz', 'cde'],
['A sentence with Capital letters.', 'f xjsyjshj bnym hfunyfq qjyyjwx.'],
['#$%^&*()', '#$%^&*()']
])
def test_cipher(original_sentence, encrypted_sentence, monkeypatch):
mocked_stdout = io.StringIO()
with monkeypatch.context() as m:
inputs = iter([original_sentence])
m.setattr(builtins, "input", lambda _: next(inputs))
m.setattr(sys, "stdout", mocked_stdout)
sys.modules.pop("cipher", None)
importlib.import_module(name="cipher", package="files")
assert mocked_stdout.getvalue().strip() == 'The encrypted sentence is: ' + encrypted_sentence