forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
file-transfer: writing tests and ensuring that all is going well (The…
…Algorithms#2413) * file-transfer: writing tests and ensuring that all is going well * def send_file(filename: str = "mytext.txt", testing: bool = False) -> None: * send_file(filename="mytext.txt", testing=True) * Update send_file.py * requirements.txt: lxml Co-authored-by: Christian Clauss <[email protected]>
- Loading branch information
Showing
3 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from unittest.mock import patch, Mock | ||
|
||
|
||
from file_transfer.send_file import send_file | ||
|
||
|
||
@patch("socket.socket") | ||
@patch("builtins.open") | ||
def test_send_file_running_as_expected(file, sock): | ||
# ===== initialization ===== | ||
conn = Mock() | ||
sock.return_value.accept.return_value = conn, Mock() | ||
f = iter([1, None]) | ||
file.return_value.__enter__.return_value.read.side_effect = lambda _: next(f) | ||
|
||
# ===== invoke ===== | ||
send_file(filename="mytext.txt", testing=True) | ||
|
||
# ===== ensurance ===== | ||
sock.assert_called_once() | ||
sock.return_value.bind.assert_called_once() | ||
sock.return_value.listen.assert_called_once() | ||
sock.return_value.accept.assert_called_once() | ||
conn.recv.assert_called_once() | ||
|
||
file.return_value.__enter__.assert_called_once() | ||
file.return_value.__enter__.return_value.read.assert_called() | ||
|
||
conn.send.assert_called_once() | ||
conn.close.assert_called_once() | ||
sock.return_value.shutdown.assert_called_once() | ||
sock.return_value.close.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ black | |
fake_useragent | ||
flake8 | ||
keras | ||
lxml | ||
matplotlib | ||
mypy | ||
numpy | ||
|