From 64e0ca26f195fb6bb2d5bda79fc402f3ac2ce9e3 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 23 Jul 2017 20:29:42 +1000 Subject: [PATCH] tests: Added test for msg() --- tests/test_util.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_util.py b/tests/test_util.py index 01d1c9c..3a3ecdb 100755 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,5 +1,7 @@ """Test util functions.""" import unittest +import unittest.mock +import io import os import pathlib import time @@ -95,6 +97,14 @@ class TestUtil(unittest.TestCase): self.assertTrue(result) os.remove(test_file) + def test_msg(self): + """> Test displaying a message.""" + # Since this function just prints a message we redirect + # it's output so that we can read it. + with unittest.mock.patch('sys.stdout', new=io.StringIO()) as fake_out: + util.msg("test", True) + self.assertEqual(fake_out.getvalue().strip(), "test") + if __name__ == "__main__": unittest.main()