/usr/share/doc/python3-pycurl/tests
NameSizeModeActions
certs/-0755rm
ext/-0755rm
fake-curl/-0755rm
fixtures/-0755rm
matrix/-0755rm
tmp/-0755rm
__pycache__/-0755rm
app.py40880644editdlrm
appmanager.py13800644editdlrm
cadata_test.py14520644editdlrm
certinfo_test.py34680644editdlrm
close_socket_cb_test.py21680644editdlrm
curl_object_test.py48830644editdlrm
debug_test.py22750644editdlrm
default_write_cb_test.py30390644editdlrm
error_constants_test.py6620644editdlrm
error_test.py29010644editdlrm
failonerror_test.py35090644editdlrm
ftp_test.py15370644editdlrm
global_init_test.py10630644editdlrm
header_cb_test.py15600644editdlrm
header_test.py18480644editdlrm
high_level_curl_test.py6320644editdlrm
info_constants_test.py3870644editdlrm
internals_test.py66740644editdlrm
matrix.py68160644editdlrm
multi_option_constants_test.py25030644editdlrm
multi_socket_test.py30490644editdlrm
multi_test.py123130644editdlrm
multi_timer_test.py26950644editdlrm
open_socket_cb_test.py47610644editdlrm
option_constants_test.py163710644editdlrm
perform_test.py21790644editdlrm
procmgr.py27310644editdlrm
protocol_constants_test.py16790644editdlrm
readdata_test.py96230644editdlrm
read_cb_test.py43400644editdlrm
relative_url_test.py5510644editdlrm
reload_test.py4300644editdlrm
reset_test.py26990644editdlrm
resolve_test.py7800644editdlrm
run-quickstart.sh7680755editdlrm
run.sh6900755editdlrm
runwsgi.py37330644editdlrm
seek_cb_constants_test.py8330644editdlrm
setopt_lifecycle_test.py17970644editdlrm
setopt_string_test.py8160644editdlrm
setopt_test.py37730644editdlrm
setopt_unicode_test.py10920644editdlrm
setup_test.py100350644editdlrm
share_test.py17260644editdlrm
sockopt_cb_test.py24530644editdlrm
unset_range_test.py14820644editdlrm
user_agent_string_test.py8200644editdlrm
util.py82910644editdlrm
version_comparison_test.py5140644editdlrm
version_constants_test.py20560644editdlrm
version_test.py3130644editdlrm
vsftpd.conf2940644editdlrm
weakref_test.py4430644editdlrm
write_abort_test.py11940644editdlrm
write_cb_bogus_test.py13810644editdlrm
write_test.py100480644editdlrm
write_to_stringio_test.py12280644editdlrm
xferinfo_cb_test.py21470644editdlrm
__init__.py5350644editdlrm
Edit: /usr/share/doc/python3-pycurl/tests/write_test.py (10048B)
#! /usr/bin/env python # -*- coding: utf-8 -*- # vi:ts=4:et from . import localhost try: import unittest2 as unittest except ImportError: import unittest import pycurl import tempfile import shutil import os.path from . import appmanager from . import util setup_module, teardown_module = appmanager.setup(('app', 8380)) class Acceptor(object): def __init__(self): self.buffer = '' def write(self, chunk): self.buffer += chunk.decode() class WriteTest(unittest.TestCase): def setUp(self): self.curl = util.DefaultCurl() def tearDown(self): self.curl.close() def test_write_to_tempfile_via_function(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) f = tempfile.NamedTemporaryFile() try: self.curl.setopt(pycurl.WRITEFUNCTION, f.write) self.curl.perform() f.seek(0) body = f.read() finally: f.close() self.assertEqual('success', body.decode()) def test_write_to_tempfile_via_object(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) f = tempfile.NamedTemporaryFile() try: self.curl.setopt(pycurl.WRITEDATA, f) self.curl.perform() f.seek(0) body = f.read() finally: f.close() self.assertEqual('success', body.decode()) def test_write_to_file_via_function(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) dir = tempfile.mkdtemp() try: path = os.path.join(dir, 'pycurltest') f = open(path, 'wb+') try: self.curl.setopt(pycurl.WRITEFUNCTION, f.write) self.curl.perform() f.seek(0) body = f.read() finally: f.close() finally: shutil.rmtree(dir) self.assertEqual('success', body.decode()) def test_write_to_file_via_object(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) dir = tempfile.mkdtemp() try: path = os.path.join(dir, 'pycurltest') f = open(path, 'wb+') try: self.curl.setopt(pycurl.WRITEDATA, f) self.curl.perform() f.seek(0) body = f.read() finally: f.close() finally: shutil.rmtree(dir) self.assertEqual('success', body.decode()) def test_write_to_file_like(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) acceptor = Acceptor() self.curl.setopt(pycurl.WRITEDATA, acceptor) self.curl.perform() self.assertEqual('success', acceptor.buffer) @util.with_real_write_file def test_write_to_file_like_then_real_file(self, real_f): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) acceptor = Acceptor() self.curl.setopt(pycurl.WRITEDATA, acceptor) self.curl.perform() self.assertEqual('success', acceptor.buffer) self.curl.setopt(pycurl.WRITEDATA, real_f) self.curl.perform() real_f.seek(0) body = real_f.read() self.assertEqual('success', body.decode()) def test_headerfunction_and_writefunction(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) header_acceptor = Acceptor() body_acceptor = Acceptor() self.curl.setopt(pycurl.HEADERFUNCTION, header_acceptor.write) self.curl.setopt(pycurl.WRITEFUNCTION, body_acceptor.write) self.curl.perform() self.assertEqual('success', body_acceptor.buffer) self.assertIn('content-type', header_acceptor.buffer.lower()) def test_writeheader_and_writedata_file_like(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) header_acceptor = Acceptor() body_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEHEADER, header_acceptor) self.curl.setopt(pycurl.WRITEDATA, body_acceptor) self.curl.perform() self.assertEqual('success', body_acceptor.buffer) self.assertIn('content-type', header_acceptor.buffer.lower()) @util.with_real_write_file @util.with_real_write_file def test_writeheader_and_writedata_real_file(self, real_f_header, real_f_data): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) self.curl.setopt(pycurl.WRITEHEADER, real_f_header) self.curl.setopt(pycurl.WRITEDATA, real_f_data) self.curl.perform() real_f_header.seek(0) real_f_data.seek(0) self.assertEqual('success', real_f_data.read().decode()) self.assertIn('content-type', real_f_header.read().decode().lower()) def test_writedata_and_writefunction_file_like(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) data_acceptor = Acceptor() function_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEDATA, data_acceptor) self.curl.setopt(pycurl.WRITEFUNCTION, function_acceptor.write) self.curl.perform() self.assertEqual('', data_acceptor.buffer) self.assertEqual('success', function_acceptor.buffer) @util.with_real_write_file def test_writedata_and_writefunction_real_file(self, real_f): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) function_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEDATA, real_f) self.curl.setopt(pycurl.WRITEFUNCTION, function_acceptor.write) self.curl.perform() real_f.seek(0) self.assertEqual('', real_f.read().decode().lower()) self.assertEqual('success', function_acceptor.buffer) def test_writefunction_and_writedata_file_like(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) data_acceptor = Acceptor() function_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEFUNCTION, function_acceptor.write) self.curl.setopt(pycurl.WRITEDATA, data_acceptor) self.curl.perform() self.assertEqual('success', data_acceptor.buffer) self.assertEqual('', function_acceptor.buffer) @util.with_real_write_file def test_writefunction_and_writedata_real_file(self, real_f): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) function_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEFUNCTION, function_acceptor.write) self.curl.setopt(pycurl.WRITEDATA, real_f) self.curl.perform() real_f.seek(0) self.assertEqual('success', real_f.read().decode().lower()) self.assertEqual('', function_acceptor.buffer) def test_writeheader_and_headerfunction_file_like(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) data_acceptor = Acceptor() function_acceptor = Acceptor() body_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEHEADER, data_acceptor) self.curl.setopt(pycurl.HEADERFUNCTION, function_acceptor.write) # silence output self.curl.setopt(pycurl.WRITEDATA, body_acceptor) self.curl.perform() self.assertEqual('', data_acceptor.buffer) self.assertIn('content-type', function_acceptor.buffer.lower()) @util.with_real_write_file def test_writeheader_and_headerfunction_real_file(self, real_f): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) function_acceptor = Acceptor() body_acceptor = Acceptor() self.curl.setopt(pycurl.WRITEHEADER, real_f) self.curl.setopt(pycurl.HEADERFUNCTION, function_acceptor.write) # silence output self.curl.setopt(pycurl.WRITEDATA, body_acceptor) self.curl.perform() real_f.seek(0) self.assertEqual('', real_f.read().decode().lower()) self.assertIn('content-type', function_acceptor.buffer.lower()) def test_headerfunction_and_writeheader_file_like(self): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) data_acceptor = Acceptor() function_acceptor = Acceptor() body_acceptor = Acceptor() self.curl.setopt(pycurl.HEADERFUNCTION, function_acceptor.write) self.curl.setopt(pycurl.WRITEHEADER, data_acceptor) # silence output self.curl.setopt(pycurl.WRITEDATA, body_acceptor) self.curl.perform() self.assertIn('content-type', data_acceptor.buffer.lower()) self.assertEqual('', function_acceptor.buffer) @util.with_real_write_file def test_headerfunction_and_writeheader_real_file(self, real_f): self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost) function_acceptor = Acceptor() body_acceptor = Acceptor() self.curl.setopt(pycurl.HEADERFUNCTION, function_acceptor.write) self.curl.setopt(pycurl.WRITEHEADER, real_f) # silence output self.curl.setopt(pycurl.WRITEDATA, body_acceptor) self.curl.perform() real_f.seek(0) self.assertIn('content-type', real_f.read().decode().lower()) self.assertEqual('', function_acceptor.buffer) def test_writedata_not_file_like(self): not_file_like = object() try: self.curl.setopt(self.curl.WRITEDATA, not_file_like) except TypeError as exc: self.assertIn('object given without a write method', str(exc)) else: self.fail('TypeError not raised') def test_writeheader_not_file_like(self): not_file_like = object() try: self.curl.setopt(self.curl.WRITEHEADER, not_file_like) except TypeError as exc: self.assertIn('object given without a write method', str(exc)) else: self.fail('TypeError not raised')