debian-koji/tests/test_cli/test_running_in_bg.py
Yuming Zhu ca05418fb5 unittest: use unittest.mock instead of mock
because the absence of unittest.mock on python2.7, we still fallback to
mock
2024-10-23 16:35:30 +00:00

46 lines
1.4 KiB
Python

from __future__ import absolute_import
try:
from unittest import mock
except ImportError:
import mock
import unittest
from koji_cli.lib import _running_in_bg
class TestRunningInBg(unittest.TestCase):
@mock.patch('koji_cli.lib.os')
def test_running_in_bg(self, os_mock):
os_mock.isatty.return_value = False
self.assertTrue(_running_in_bg())
os_mock.isatty.return_value = True
os_mock.getpgrp.return_value = 0
os_mock.tcgetpgrp.return_value = 1
self.assertTrue(_running_in_bg())
os_mock.tcgetpgrp.return_value = 0
self.assertFalse(_running_in_bg())
os_mock.reset_mock()
os_mock.tcgetpgrp.side_effect = OSError
self.assertTrue(_running_in_bg())
os_mock.isatty.assert_called()
os_mock.getpgrp.assert_called()
os_mock.tcgetpgrp.assert_called()
os_mock.reset_mock()
os_mock.getpgrp.side_effect = OSError
self.assertTrue(_running_in_bg())
os_mock.isatty.assert_called()
os_mock.getpgrp.assert_called()
os_mock.tcgetpgrp.assert_not_called()
os_mock.reset_mock()
os_mock.isatty.side_effect = OSError
self.assertTrue(_running_in_bg())
os_mock.isatty.assert_called()
os_mock.getpgrp.assert_not_called()
os_mock.tcgetpgrp.assert_not_called()
if __name__ == '__main__':
unittest.main()