1 # test.misc - tests for miscellaneous functions
3 # Part of WiFi Radar: A utility for managing WiFi profiles on GNU/Linux.
5 # Copyright (C) 2014 Sean Robinson <robinson@tuxfamily.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License in LICENSE.GPL for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to:
18 # Free Software Foundation, Inc.
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 from subprocess
import CalledProcessError
28 import wifiradar
.misc
as misc
31 class TestFunctions(unittest
.TestCase
):
33 @mock.patch
.dict('wifiradar.misc.os.environ', clear
=True)
34 @mock.patch('wifiradar.misc.check_call')
35 def test_shellcmd(self
, mock_call
):
36 """ Test shellcmd function. """
37 # Test successful return and custom environment.
38 mock_call
.return_value
= 0
39 self
.assertEqual(0, misc
.shellcmd('return0', {'WRv': '2.0'}))
40 mock_call
.assert_called_with('return0', shell
=True,
42 # Test for check_call failure.
43 mock_call
.side_effect
= CalledProcessError(2, 'return2')
44 with self
.assertRaises(CalledProcessError
) as cm
:
45 misc
.shellcmd('return2', {})
46 self
.assertEqual(2, cm
.exception
.returncode
)
47 self
.assertEqual('return2', cm
.exception
.cmd
)