| Server IP : 112.74.42.100 / Your IP : 216.73.216.142 Web Server : nginx/1.20.2 System : Linux iZwz96lx4pjqiy84w4hni7Z 5.10.134-17.3.al8.x86_64 #1 SMP Thu Oct 31 14:29:57 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.0.26 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/python3-pycurl/tests/ |
Upload File : |
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vi:ts=4:et
import pycurl
import sys
import unittest
class ErrorTest(unittest.TestCase):
def setUp(self):
self.curl = pycurl.Curl()
def tearDown(self):
self.curl.close()
# error originating in libcurl
def test_pycurl_error_libcurl(self):
try:
# perform without a url
self.curl.perform()
except pycurl.error:
exc_type, exc = sys.exc_info()[:2]
assert exc_type == pycurl.error
# pycurl.error's arguments are libcurl errno and message
self.assertEqual(2, len(exc.args))
self.assertEqual(int, type(exc.args[0]))
self.assertEqual(str, type(exc.args[1]))
# unpack
err, msg = exc.args
self.assertEqual(pycurl.E_URL_MALFORMAT, err)
# possibly fragile
self.assertEqual('No URL set!', msg)
else:
self.fail('Expected pycurl.error to be raised')
def test_pycurl_errstr_initially_empty(self):
self.assertEqual('', self.curl.errstr())
def test_pycurl_errstr_type(self):
self.assertEqual('', self.curl.errstr())
try:
# perform without a url
self.curl.perform()
except pycurl.error:
# might be fragile
self.assertEqual('No URL set!', self.curl.errstr())
# repeated checks do not clear value
self.assertEqual('No URL set!', self.curl.errstr())
# check the type - on all python versions
self.assertEqual(str, type(self.curl.errstr()))
else:
self.fail('no exception')
# pycurl raises standard library exceptions in some cases
def test_pycurl_error_stdlib(self):
try:
# set an option of the wrong type
self.curl.setopt(pycurl.WRITEFUNCTION, True)
except TypeError:
exc_type, exc = sys.exc_info()[:2]
else:
self.fail('Expected TypeError to be raised')
# error originating in pycurl
# looks like currently there are none
def xtest_pycurl_error_pycurl(self):
try:
# invalid option combination
self.curl.setopt(pycurl.WRITEFUNCTION, lambda x: x)
f = open(__file__)
try:
self.curl.setopt(pycurl.WRITEHEADER, f)
finally:
f.close()
except pycurl.error:
exc_type, exc = sys.exc_info()[:2]
assert exc_type == pycurl.error
# for non-libcurl errors, arguments are just the error string
self.assertEqual(1, len(exc.args))
self.assertEqual(str, type(exc.args[0]))
self.assertEqual('cannot combine WRITEHEADER with WRITEFUNCTION.', exc.args[0])
else:
self.fail('Expected pycurl.error to be raised')