def _install_manpage(src_path, man_dir): """Install the given manual page for COT. Args: src_path (str): Path to manual page file. man_dir (str): Base directory where page should be installed. Returns: tuple: (page_previously_installed, page_updated) Raises: IOError: if installation fails under some circumstances OSError: if installation fails under other circumstances """ # Which man section does this belong in? filename = os.path.basename(src_path) section = os.path.splitext(filename)[1][1:] dest = os.path.join(man_dir, "man{0}".format(section)) Helper.mkdir(dest) previously_installed = False dest_path = os.path.join(dest, filename) if os.path.exists(dest_path): previously_installed = True if filecmp.cmp(src_path, dest_path): logger.verbose("File %s does not need to be updated", dest_path) return previously_installed, False Helper.copy_file(src_path, dest_path) return previously_installed, True
def test_need_sudo(self, mock_copy, mock_check_call): """File copy needs sudo.""" mock_copy.side_effect = OSError self.assertTrue(Helper.copy_file('/foo', '/bar')) mock_copy.assert_called_with('/foo', '/bar') mock_check_call.assert_called_with(['sudo', 'cp', '/foo', '/bar'])
def test_permission_ok(self, mock_copy, mock_check_call): """File copy succeeds with user permissions.""" self.assertTrue(Helper.copy_file('/foo', '/bar')) mock_copy.assert_called_with('/foo', '/bar') mock_check_call.assert_not_called()