From 6b951e0fe356ef170da063e9a51d63b498db013c Mon Sep 17 00:00:00 2001 From: belono Date: Sun, 22 Oct 2023 13:44:04 +0200 Subject: [PATCH] Include a close_on_reopen test --- test/test_printers/test_printer_file.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_printers/test_printer_file.py b/test/test_printers/test_printer_file.py index 1df032c..3558231 100644 --- a/test/test_printers/test_printer_file.py +++ b/test/test_printers/test_printer_file.py @@ -64,6 +64,22 @@ def test_open(fileprinter, caplog, mocker): assert fileprinter.device +def test_close_on_reopen(fileprinter, mocker): + """ + GIVEN a file printer object and a mocked connection + WHEN a valid connection to a device is reopened before close + THEN check the close method is called if _device + """ + mocker.patch("builtins.open") + spy = mocker.spy(fileprinter, "close") + + fileprinter.open() + assert fileprinter._device + + fileprinter.open() + spy.assert_called_once_with() + + def test_flush(fileprinter, mocker): """ GIVEN a file printer object and a mocked connection