def test_remove(self, os_unlink, os_path_exists, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('clingon.py -r -p /usr/local/bin') self.assertEqual(out.getvalue(), "Script '/usr/local/bin/clingon' removed\n") os_unlink.assert_called_with('/usr/local/bin/clingon') os_path_exists.assert_called_with('/usr/local/bin/clingon') sys_exit.assert_called_with(0)
def test_user_and_path(self, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('clingon.py -u -p /usr/local/bin') self.assertEqual(out.getvalue(), '') self.assertEqual(err.getvalue(), 'usage: clingon.py python_script [options] [--help | -?]\n' 'You cannot specify --path and --user at the same time\n') sys_exit.assert_called_with(clingon.SYSTEM_EXIT_ERROR_CODE)
def test_no_parameter(self, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('') self.assertEqual(out.getvalue(), "") self.assertEqual(err.getvalue(), "usage: clingon.py python_script [options] [--help | -?]\n" "Too few parameters (1 required)\n") sys_exit.assert_called_with(clingon.SYSTEM_EXIT_ERROR_CODE)
def test_no_source(self, os_path_exists, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('toto.py') self.assertIn('Could not find source', err.getvalue()) self.assertIn("toto.py', aborting", err.getvalue()) self.assertEqual(out.getvalue(), "") path = err.getvalue().split()[4][1:-2] os_path_exists.assert_called_with(path) sys_exit.assert_called_with(clingon.SYSTEM_EXIT_ERROR_CODE)
def test_symlink_target(self, os_unlink, os_path_isdir, os_symlink, os_stat, os_chmod, os_environ, sys_exit): with mock.patch('os.path.exists'): with mock.patch('os.path.samefile', return_value=False): with mock.patch('os.path.islink'): with captured_output() as (out, err): clingon.clingon_script()('clingon/clingon.py -f -l -p /usr/local/bin ' '--no-check-path --no-check-shebang') self.assertEqual(err.getvalue(), "") self.assertIn("has been symlinked to /usr/local/bin/clingon", out.getvalue()) os_path_isdir.assert_called_with('/usr/local/bin') os_unlink.assert_called_with('/usr/local/bin/clingon') os_chmod.assert_called_with('/usr/local/bin/clingon', 72) sys_exit.assert_called_with(0)
def test_copy_target(self, os_unlink, os_path_isdir, shutil_copyfile, os_stat, os_chmod, os_environ, sys_exit): with mock.patch('os.path.exists'): with mock.patch('os.path.samefile'): with mock.patch('os.path.islink'): with captured_output() as (out, err): clingon.clingon_script()('clingon/clingon.py -f -p /usr/local/bin --no-check-shebang') self.assertEqual(err.getvalue(), "") self.assertIn("has been copied to /usr/local/bin/clingon", out.getvalue()) self.assertIn("Please add your local bin path [/usr/local/bin] to your environment PATH", out.getvalue()) os_path_isdir.assert_called_with('/usr/local/bin') os_unlink.assert_called_with('/usr/local/bin/clingon') os_chmod.assert_called_with('/usr/local/bin/clingon', 72) sys_exit.assert_called_with(0)
def test_target_created_aborting(self, os_path_exists, os_path_samefile, os_path_islink, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('clingon.py -l -p /usr/local/bin') self.assertEqual(out.getvalue(), "Target '/usr/local/bin/clingon' already created, nothing to do\n") sys_exit.assert_called_with(0)
def test_target_exists_no_force(self, os_path_exists, os_path_samefile, os_path_islink, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('clingon.py -p /usr/local/bin') self.assertEqual(out.getvalue(), "") self.assertEqual(err.getvalue(), "Target '/usr/local/bin/clingon' already exists, aborting\n") sys_exit.assert_called_with(clingon.SYSTEM_EXIT_ERROR_CODE)
def test_remove_no_target(self, os_path_exists, sys_exit): with captured_output() as (out, err): clingon.clingon_script()('clingon.py -r -p /usr/local/bin') self.assertEqual(out.getvalue(), "Script '/usr/local/bin/clingon' not found, nothing to do\n") os_path_exists.assert_called_with('/usr/local/bin/clingon') sys_exit.assert_called_with(0)