summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Pudeyev <oleg@bsdpower.com>2018-06-01 23:16:43 -0400
committerOleg Pudeyev <oleg@bsdpower.com>2018-06-01 23:16:43 -0400
commitf5534065055cfb426da9cfee37917c15948dd66b (patch)
treefdb3e6622c8a4be30aa6aa19f797c10d5fa5eb69
parent2ed501d1a6bc61458795320083f88bd81c4b2b6c (diff)
downloadpycurl-f5534065055cfb426da9cfee37917c15948dd66b.tar.gz
Windows has no localhost now
-rw-r--r--examples/smtp.py3
-rw-r--r--tests/__init__.py3
-rw-r--r--tests/cadata_test.py3
-rw-r--r--tests/certinfo_test.py7
-rw-r--r--tests/close_socket_cb_test.py4
-rw-r--r--tests/debug_test.py7
-rw-r--r--tests/default_write_cb_test.py5
-rw-r--r--tests/failonerror_test.py7
-rw-r--r--tests/getinfo_test.py9
-rw-r--r--tests/header_cb_test.py3
-rw-r--r--tests/header_test.py3
-rw-r--r--tests/high_level_curl_test.py3
-rw-r--r--tests/memory_mgmt_test.py1
-rw-r--r--tests/multi_socket_select_test.py7
-rw-r--r--tests/multi_socket_test.py7
-rw-r--r--tests/multi_test.py35
-rw-r--r--tests/multi_timer_test.py7
-rw-r--r--tests/open_socket_cb_test.py7
-rw-r--r--tests/option_constants_test.py3
-rw-r--r--tests/pause_test.py3
-rw-r--r--tests/perform_test.py15
-rw-r--r--tests/post_test.py21
-rw-r--r--tests/read_cb_test.py7
-rw-r--r--tests/readdata_test.py21
-rw-r--r--tests/relative_url_test.py3
-rw-r--r--tests/reset_test.py7
-rw-r--r--tests/setopt_lifecycle_test.py3
-rw-r--r--tests/setopt_string_test.py3
-rw-r--r--tests/setopt_test.py5
-rw-r--r--tests/setopt_unicode_test.py3
-rw-r--r--tests/share_test.py3
-rw-r--r--tests/sockopt_cb_test.py3
-rw-r--r--tests/unset_range_test.py1
-rw-r--r--tests/user_agent_string_test.py3
-rw-r--r--tests/win/opensocketcrash.py3
-rw-r--r--tests/write_test.py35
-rw-r--r--tests/write_to_stringio_test.py5
-rw-r--r--tests/xferinfo_cb_test.py3
38 files changed, 154 insertions, 117 deletions
diff --git a/examples/smtp.py b/examples/smtp.py
index b5f125b..7bbd1bc 100644
--- a/examples/smtp.py
+++ b/examples/smtp.py
@@ -2,6 +2,7 @@
# https://github.com/bagder/curl/blob/master/docs/examples/smtp-mail.c
# There are other SMTP examples in that directory that you may find helpful.
+from . import localhost
import pycurl
try:
from io import BytesIO
@@ -11,7 +12,7 @@ import sys
PY3 = sys.version_info[0] > 2
-mail_server = 'smtp://localhost'
+mail_server = 'smtp://%s' % localhost
mail_from = 'sender@example.org'
mail_to = 'addressee@example.net'
diff --git a/tests/__init__.py b/tests/__init__.py
index ef8a932..663ec2f 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,3 +1,6 @@
+# On recent windowses there is no localhost entry in hosts file,
+# hence localhost resolves fail. https://github.com/c-ares/c-ares/issues/85
+# FTP tests also seem to want the numeric IP address rather than localhost.
localhost = '127.0.0.1'
def setup_package():
diff --git a/tests/cadata_test.py b/tests/cadata_test.py
index 1256ae3..9584e56 100644
--- a/tests/cadata_test.py
+++ b/tests/cadata_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import os
import pycurl
import unittest
@@ -22,7 +23,7 @@ class CaCertsTest(unittest.TestCase):
def test_request_with_verifypeer(self):
with open(os.path.join(os.path.dirname(__file__), 'certs', 'ca.crt'), 'rb') as stream:
cadata = stream.read().decode('ASCII')
- self.curl.setopt(pycurl.URL, 'https://localhost:8384/success')
+ self.curl.setopt(pycurl.URL, 'https://%s:8384/success' % localhost)
sio = util.BytesIO()
self.curl.set_ca_certs(cadata)
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
diff --git a/tests/certinfo_test.py b/tests/certinfo_test.py
index 2f417b2..a833be5 100644
--- a/tests/certinfo_test.py
+++ b/tests/certinfo_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import nose.plugins.skip
@@ -27,7 +28,7 @@ class CertinfoTest(unittest.TestCase):
@util.min_libcurl(7, 19, 1)
@util.only_ssl
def test_request_without_certinfo(self):
- self.curl.setopt(pycurl.URL, 'https://localhost:8383/success')
+ self.curl.setopt(pycurl.URL, 'https://%s:8383/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
# self signed certificate
@@ -46,7 +47,7 @@ class CertinfoTest(unittest.TestCase):
if 'openssl' not in pycurl.version.lower():
raise nose.plugins.skip.SkipTest('libcurl does not use openssl')
- self.curl.setopt(pycurl.URL, 'https://localhost:8383/success')
+ self.curl.setopt(pycurl.URL, 'https://%s:8383/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.setopt(pycurl.OPT_CERTINFO, 1)
@@ -74,7 +75,7 @@ class CertinfoTest(unittest.TestCase):
if 'openssl' not in pycurl.version.lower():
raise nose.plugins.skip.SkipTest('libcurl does not use openssl')
- self.curl.setopt(pycurl.URL, 'https://localhost:8383/success')
+ self.curl.setopt(pycurl.URL, 'https://%s:8383/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.setopt(pycurl.OPT_CERTINFO, 1)
diff --git a/tests/close_socket_cb_test.py b/tests/close_socket_cb_test.py
index f779acb..39a3802 100644
--- a/tests/close_socket_cb_test.py
+++ b/tests/close_socket_cb_test.py
@@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import socket
-import os
import unittest
import pycurl
@@ -15,7 +15,7 @@ setup_module, teardown_module = appmanager.setup(('app', 8380))
class CloseSocketCbTest(unittest.TestCase):
def setUp(self):
self.curl = util.DefaultCurl()
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost)
self.curl.setopt(pycurl.FORBID_REUSE, True)
def tearDown(self):
diff --git a/tests/debug_test.py b/tests/debug_test.py
index 70b69e3..50da3d8 100644
--- a/tests/debug_test.py
+++ b/tests/debug_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
@@ -24,7 +25,7 @@ class DebugTest(unittest.TestCase):
def test_perform_get_with_debug_function(self):
self.curl.setopt(pycurl.VERBOSE, 1)
self.curl.setopt(pycurl.DEBUGFUNCTION, self.debug_function)
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
@@ -34,7 +35,7 @@ class DebugTest(unittest.TestCase):
if util.pycurl_version_less_than(7, 24):
self.check(0, util.b('connected'))
else:
- self.check(0, util.b('Connected to localhost'))
+ self.check(0, util.b('Connected to %s' % localhost))
self.check(0, util.b('port 8380'))
# request
self.check(2, util.b('GET /success HTTP/1.1'))
@@ -48,7 +49,7 @@ class DebugTest(unittest.TestCase):
def test_debug_unicode(self):
self.curl.setopt(pycurl.VERBOSE, 1)
self.curl.setopt(pycurl.DEBUGFUNCTION, self.debug_function)
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/utf8_body')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/utf8_body' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
diff --git a/tests/default_write_cb_test.py b/tests/default_write_cb_test.py
index e2d0e95..ff6478e 100644
--- a/tests/default_write_cb_test.py
+++ b/tests/default_write_cb_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import unittest
import pycurl
import sys
@@ -38,7 +39,7 @@ class DefaultWriteCbTest(unittest.TestCase):
# test_perform_get_with_default_write_function is the test
# which exercises default curl write handler.
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
self.curl.perform()
# If this flush is not done, stdout output bleeds into the next test
# that is executed (without nose output capture)
@@ -47,7 +48,7 @@ class DefaultWriteCbTest(unittest.TestCase):
# I have a really hard time getting this to work with nose output capture
def skip_perform_get_with_default_write_function(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
f = tempfile.NamedTemporaryFile()
try:
#with open('w', 'w+') as f:
diff --git a/tests/failonerror_test.py b/tests/failonerror_test.py
index f8cd710..dc4d8cd 100644
--- a/tests/failonerror_test.py
+++ b/tests/failonerror_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
@@ -21,7 +22,7 @@ class FailonerrorTest(unittest.TestCase):
# and does not include status text, only the status code
@util.min_libcurl(7, 38, 0)
def test_failonerror(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/status/403')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/status/403' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEDATA, sio)
self.curl.setopt(pycurl.FAILONERROR, True)
@@ -41,7 +42,7 @@ class FailonerrorTest(unittest.TestCase):
# and does not include status text, only the status code
@util.min_libcurl(7, 38, 0)
def test_failonerror_status_line_invalid_utf8_python2(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/status_invalid_utf8')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/status_invalid_utf8' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEDATA, sio)
self.curl.setopt(pycurl.FAILONERROR, True)
@@ -61,7 +62,7 @@ class FailonerrorTest(unittest.TestCase):
# and does not include status text, only the status code
@util.min_libcurl(7, 38, 0)
def test_failonerror_status_line_invalid_utf8_python3(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/status_invalid_utf8')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/status_invalid_utf8' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEDATA, sio)
self.curl.setopt(pycurl.FAILONERROR, True)
diff --git a/tests/getinfo_test.py b/tests/getinfo_test.py
index e96aeaf..381aa06 100644
--- a/tests/getinfo_test.py
+++ b/tests/getinfo_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import flaky
import pycurl
import unittest
@@ -30,7 +31,7 @@ class GetinfoTest(unittest.TestCase):
assert type(self.curl.getinfo(pycurl.SPEED_DOWNLOAD)) is float
assert self.curl.getinfo(pycurl.SPEED_DOWNLOAD) > 0
self.assertEqual(7, self.curl.getinfo(pycurl.SIZE_DOWNLOAD))
- self.assertEqual('http://localhost:8380/success', self.curl.getinfo(pycurl.EFFECTIVE_URL))
+ self.assertEqual('http://%s:8380/success' % localhost, self.curl.getinfo(pycurl.EFFECTIVE_URL))
self.assertEqual('text/html; charset=utf-8', self.curl.getinfo(pycurl.CONTENT_TYPE).lower())
assert type(self.curl.getinfo(pycurl.NAMELOOKUP_TIME)) is float
assert self.curl.getinfo(pycurl.NAMELOOKUP_TIME) > 0
@@ -48,7 +49,7 @@ class GetinfoTest(unittest.TestCase):
assert type(self.curl.getinfo(pycurl.LOCAL_PORT)) is int
def make_request(self, path='/success', expected_body='success'):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380' + path)
+ self.curl.setopt(pycurl.URL, 'http://%s:8380' % localhost + path)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
@@ -60,7 +61,7 @@ class GetinfoTest(unittest.TestCase):
self.make_request('/set_cookie_invalid_utf8', 'cookie set')
self.assertEqual(200, self.curl.getinfo(pycurl.HTTP_CODE))
- expected = "localhost\tFALSE\t/\tFALSE\t0\t\xb3\xd2\xda\xcd\xd7\t%96%A6g%9Ay%B0%A5g%A7tm%7C%95%9A"
+ expected = "%s" % localhost + "\tFALSE\t/\tFALSE\t0\t\xb3\xd2\xda\xcd\xd7\t%96%A6g%9Ay%B0%A5g%A7tm%7C%95%9A"
self.assertEqual([expected], self.curl.getinfo(pycurl.INFO_COOKIELIST))
@util.only_python3
@@ -81,7 +82,7 @@ class GetinfoTest(unittest.TestCase):
self.make_request('/set_cookie_invalid_utf8', 'cookie set')
self.assertEqual(200, self.curl.getinfo(pycurl.HTTP_CODE))
- expected = util.b("localhost\tFALSE\t/\tFALSE\t0\t\xb3\xd2\xda\xcd\xd7\t%96%A6g%9Ay%B0%A5g%A7tm%7C%95%9A")
+ expected = util.b("%s" % localhost + "\tFALSE\t/\tFALSE\t0\t\xb3\xd2\xda\xcd\xd7\t%96%A6g%9Ay%B0%A5g%A7tm%7C%95%9A")
self.assertEqual([expected], self.curl.getinfo_raw(pycurl.INFO_COOKIELIST))
@util.only_python2
diff --git a/tests/header_cb_test.py b/tests/header_cb_test.py
index 4038ddd..71f7bc9 100644
--- a/tests/header_cb_test.py
+++ b/tests/header_cb_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import time as _time
@@ -23,7 +24,7 @@ class HeaderCbTest(unittest.TestCase):
self.header_lines.append(line.decode())
def test_get(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.setopt(pycurl.HEADERFUNCTION, self.header_function)
diff --git a/tests/header_test.py b/tests/header_test.py
index 495d157..e508d9e 100644
--- a/tests/header_test.py
+++ b/tests/header_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import nose.tools
@@ -46,7 +47,7 @@ class HeaderTest(unittest.TestCase):
self.do_check((send,), expected)
def do_check(self, send, expected):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/header_utf8?h=x-test-header')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/header_utf8?h=x-test-header' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.setopt(pycurl.HTTPHEADER, send)
diff --git a/tests/high_level_curl_test.py b/tests/high_level_curl_test.py
index b93c6ba..3dce1b3 100644
--- a/tests/high_level_curl_test.py
+++ b/tests/high_level_curl_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
# uses the high level interface
import curl
import unittest
@@ -12,7 +13,7 @@ setup_module, teardown_module = appmanager.setup(('app', 8380))
class RelativeUrlTest(unittest.TestCase):
def setUp(self):
- self.curl = curl.Curl('http://localhost:8380/')
+ self.curl = curl.Curl('http://%s:8380/' % localhost)
def tearDown(self):
self.curl.close()
diff --git a/tests/memory_mgmt_test.py b/tests/memory_mgmt_test.py
index e92dfbd..c33b4bf 100644
--- a/tests/memory_mgmt_test.py
+++ b/tests/memory_mgmt_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+import sys
import weakref
import pycurl
import unittest
diff --git a/tests/multi_socket_select_test.py b/tests/multi_socket_select_test.py
index 9334831..5ce7fe8 100644
--- a/tests/multi_socket_select_test.py
+++ b/tests/multi_socket_select_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import select
@@ -34,9 +35,9 @@ class MultiSocketSelectTest(unittest.TestCase):
# we need libcurl to actually wait on the handles,
# and initiate polling.
# thus use urls that sleep for a bit.
- 'http://localhost:8380/short_wait',
- 'http://localhost:8381/short_wait',
- 'http://localhost:8382/short_wait',
+ 'http://%s:8380/short_wait' % localhost,
+ 'http://%s:8381/short_wait' % localhost,
+ 'http://%s:8382/short_wait' % localhost,
]
socket_events = []
diff --git a/tests/multi_socket_test.py b/tests/multi_socket_test.py
index 9e93dba..5bee7af 100644
--- a/tests/multi_socket_test.py
+++ b/tests/multi_socket_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
@@ -28,9 +29,9 @@ class MultiSocketTest(unittest.TestCase):
# not sure why requesting /success produces no events.
# see multi_socket_select_test.py for a longer explanation
# why short wait is used there.
- 'http://localhost:8380/short_wait',
- 'http://localhost:8381/short_wait',
- 'http://localhost:8382/short_wait',
+ 'http://%s:8380/short_wait' % localhost,
+ 'http://%s:8381/short_wait' % localhost,
+ 'http://%s:8382/short_wait' % localhost,
]
socket_events = []
diff --git a/tests/multi_test.py b/tests/multi_test.py
index d0e081d..afacff8 100644
--- a/tests/multi_test.py
+++ b/tests/multi_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import nose.tools
@@ -32,9 +33,9 @@ class MultiTest(unittest.TestCase):
handles = []
c1 = util.DefaultCurl()
c2 = util.DefaultCurl()
- c1.setopt(c1.URL, 'http://localhost:8380/success')
+ c1.setopt(c1.URL, 'http://%s:8380/success' % localhost)
c1.setopt(c1.WRITEFUNCTION, io1.write)
- c2.setopt(c2.URL, 'http://localhost:8381/success')
+ c2.setopt(c2.URL, 'http://%s:8381/success' % localhost)
c2.setopt(c1.WRITEFUNCTION, io2.write)
m.add_handle(c1)
m.add_handle(c2)
@@ -62,9 +63,9 @@ class MultiTest(unittest.TestCase):
c1 = util.DefaultCurl()
c2 = util.DefaultCurl()
c3 = util.DefaultCurl()
- c1.setopt(c1.URL, "http://localhost:8380/success")
- c2.setopt(c2.URL, "http://localhost:8381/success")
- c3.setopt(c3.URL, "http://localhost:8382/success")
+ c1.setopt(c1.URL, "http://%s:8380/success" % localhost)
+ c2.setopt(c2.URL, "http://%s:8381/success" % localhost)
+ c3.setopt(c3.URL, "http://%s:8382/success" % localhost)
c1.body = util.BytesIO()
c2.body = util.BytesIO()
c3.body = util.BytesIO()
@@ -112,9 +113,9 @@ class MultiTest(unittest.TestCase):
m = pycurl.CurlMulti()
m.handles = []
urls = [
- 'http://localhost:8380/success',
- 'http://localhost:8381/status/403',
- 'http://localhost:8382/status/404',
+ 'http://%s:8380/success' % localhost,
+ 'http://%s:8381/status/403' % localhost,
+ 'http://%s:8382/status/404' % localhost,
]
for url in urls:
c = util.DefaultCurl()
@@ -163,9 +164,9 @@ class MultiTest(unittest.TestCase):
m = pycurl.CurlMulti()
m.handles = []
urls = [
- 'http://localhost:8380/success',
- 'http://localhost:8381/status/403',
- 'http://localhost:8382/status/404',
+ 'http://%s:8380/success' % localhost,
+ 'http://%s:8381/status/403' % localhost,
+ 'http://%s:8382/status/404' % localhost,
]
for url in urls:
c = util.DefaultCurl()
@@ -246,9 +247,9 @@ class MultiTest(unittest.TestCase):
c1 = util.DefaultCurl()
c2 = util.DefaultCurl()
c3 = util.DefaultCurl()
- c1.setopt(c1.URL, "http://localhost:8380/success")
- c2.setopt(c2.URL, "http://localhost:8381/success")
- c3.setopt(c3.URL, "http://localhost:8382/success")
+ c1.setopt(c1.URL, "http://%s:8380/success" % localhost)
+ c2.setopt(c2.URL, "http://%s:8381/success" % localhost)
+ c3.setopt(c3.URL, "http://%s:8382/success" % localhost)
c1.body = util.BytesIO()
c2.body = util.BytesIO()
c3.body = util.BytesIO()
@@ -297,9 +298,9 @@ class MultiTest(unittest.TestCase):
c1 = util.DefaultCurl()
c2 = util.DefaultCurl()
c3 = util.DefaultCurl()
- c1.setopt(c1.URL, "http://localhost:8380/short_wait")
- c2.setopt(c2.URL, "http://localhost:8381/short_wait")
- c3.setopt(c3.URL, "http://localhost:8382/short_wait")
+ c1.setopt(c1.URL, "http://%s:8380/short_wait" % localhost)
+ c2.setopt(c2.URL, "http://%s:8381/short_wait" % localhost)
+ c3.setopt(c3.URL, "http://%s:8382/short_wait" % localhost)
c1.body = util.BytesIO()
c2.body = util.BytesIO()
c3.body = util.BytesIO()
diff --git a/tests/multi_timer_test.py b/tests/multi_timer_test.py
index f133185..109f35e 100644
--- a/tests/multi_timer_test.py
+++ b/tests/multi_timer_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
@@ -25,9 +26,9 @@ def teardown_module(mod):
class MultiSocketTest(unittest.TestCase):
def test_multi_timer(self):
urls = [
- 'http://localhost:8380/success',
- 'http://localhost:8381/success',
- 'http://localhost:8382/success',
+ 'http://%s:8380/success' % localhost,
+ 'http://%s:8381/success' % localhost,
+ 'http://%s:8382/success' % localhost,
]
timers = []
diff --git a/tests/open_socket_cb_test.py b/tests/open_socket_cb_test.py
index 403ce15..a125ccb 100644
--- a/tests/open_socket_cb_test.py
+++ b/tests/open_socket_cb_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import socket
import pycurl
import unittest
@@ -61,7 +62,7 @@ class OpenSocketCbTest(unittest.TestCase):
def test_socket_open(self):
self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_ipv4)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
@@ -94,7 +95,7 @@ class OpenSocketCbTest(unittest.TestCase):
@util.only_unix
def test_socket_open_unix(self):
self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_unix)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost)
self.curl.setopt(self.curl.UNIX_SOCKET_PATH, '/tmp/pycurl-test-path.sock')
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
@@ -124,7 +125,7 @@ class OpenSocketCbTest(unittest.TestCase):
def test_socket_open_bad(self):
self.curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open_bad)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost)
try:
self.curl.perform()
except pycurl.error as e:
diff --git a/tests/option_constants_test.py b/tests/option_constants_test.py
index 3dc5269..e18134b 100644
--- a/tests/option_constants_test.py
+++ b/tests/option_constants_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import nose.plugins.attrib
@@ -73,7 +74,7 @@ class OptionConstantsTest(unittest.TestCase):
@util.min_libcurl(7, 19, 4)
def test_noproxy_setopt(self):
curl = pycurl.Curl()
- curl.setopt(curl.NOPROXY, 'localhost')
+ curl.setopt(curl.NOPROXY, localhost)
curl.close()
# CURLOPT_PROTOCOLS was introduced in libcurl-7.19.4
diff --git a/tests/pause_test.py b/tests/pause_test.py
index 8ed956a..bba4461 100644
--- a/tests/pause_test.py
+++ b/tests/pause_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import flaky
import pycurl
import unittest, signal
@@ -28,7 +29,7 @@ class PauseTest(unittest.TestCase):
def check_pause(self, call):
# the app sleeps for 0.5 seconds
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/pause')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/pause' % localhost)
sio = util.BytesIO()
state = dict(paused=False, resumed=False)
if call:
diff --git a/tests/perform_test.py b/tests/perform_test.py
index 17533ac..ccda941 100644
--- a/tests/perform_test.py
+++ b/tests/perform_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
try:
import unittest2 as unittest
except ImportError:
@@ -21,17 +22,17 @@ class PerformTest(unittest.TestCase):
self.curl.close()
def test_perform_rb(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
body = self.curl.perform_rb()
self.assertEqual(util.b('success'), body)
def test_perform_rs(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
body = self.curl.perform_rs()
self.assertEqual(util.u('success'), body)
def test_perform_rb_utf8(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/utf8_body')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/utf8_body' % localhost)
body = self.curl.perform_rb()
if util.py3:
self.assertEqual('Дружба народов'.encode('utf8'), body)
@@ -39,24 +40,24 @@ class PerformTest(unittest.TestCase):
self.assertEqual('Дружба народов', body)
def test_perform_rs_utf8(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/utf8_body')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/utf8_body' % localhost)
body = self.curl.perform_rs()
self.assertEqual('Дружба народов', body)
def test_perform_rb_invalid_utf8(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/invalid_utf8_body')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/invalid_utf8_body' % localhost)
body = self.curl.perform_rb()
self.assertEqual(util.b('\xb3\xd2\xda\xcd\xd7'), body)
@util.only_python2
def test_perform_rs_invalid_utf8_python2(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/invalid_utf8_body')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/invalid_utf8_body' % localhost)
body = self.curl.perform_rs()
self.assertEqual('\xb3\xd2\xda\xcd\xd7', body)
@util.only_python3
def test_perform_rs_invalid_utf8_python3(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/invalid_utf8_body')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/invalid_utf8_body' % localhost)
try:
self.curl.perform_rs()
except UnicodeDecodeError:
diff --git a/tests/post_test.py b/tests/post_test.py
index c53f9a2..0d37dae 100644
--- a/tests/post_test.py
+++ b/tests/post_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import flaky
import os.path
import pycurl
@@ -42,7 +43,7 @@ class PostTest(unittest.TestCase):
self.urlencode_and_check(pf)
def urlencode_and_check(self, pf):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/postfields' % localhost)
postfields = urllib_parse.urlencode(pf)
self.curl.setopt(pycurl.POSTFIELDS, postfields)
@@ -81,7 +82,7 @@ class PostTest(unittest.TestCase):
expect = {
'field3': 'this is wei\000rd, but null-bytes are okay',
}
- self.check_post(send, expect, 'http://localhost:8380/postfields')
+ self.check_post(send, expect, 'http://%s:8380/postfields' % localhost)
def test_post_file(self):
path = os.path.join(os.path.dirname(__file__), '..', 'README.rst')
@@ -99,7 +100,7 @@ class PostTest(unittest.TestCase):
'filename': 'README.rst',
'data': contents,
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_byte_buffer(self):
contents = util.b('hello, world!')
@@ -111,7 +112,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_unicode_buffer(self):
contents = util.u('hello, world!')
@@ -123,7 +124,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_tuple_of_tuples_of_tuples(self):
contents = util.u('hello, world!')
@@ -135,7 +136,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_tuple_of_lists_of_tuples(self):
contents = util.u('hello, world!')
@@ -147,7 +148,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_tuple_of_tuple_of_lists(self):
contents = util.u('hello, world!')
@@ -159,7 +160,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_list_of_tuple_of_tuples(self):
contents = util.u('hello, world!')
@@ -171,7 +172,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
def test_post_list_of_list_of_lists(self):
contents = util.u('hello, world!')
@@ -183,7 +184,7 @@ class PostTest(unittest.TestCase):
'filename': 'uploaded.file',
'data': 'hello, world!',
}]
- self.check_post(send, expect, 'http://localhost:8380/files')
+ self.check_post(send, expect, 'http://%s:8380/files' % localhost)
# XXX this test takes about a second to run, check keep-alives?
def check_post(self, send, expect, endpoint):
diff --git a/tests/read_cb_test.py b/tests/read_cb_test.py
index fdb648e..68d4888 100644
--- a/tests/read_cb_test.py
+++ b/tests/read_cb_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import sys
@@ -49,7 +50,7 @@ class ReadCbTest(unittest.TestCase):
def test_post_with_read_callback(self):
d = DataProvider(POSTSTRING)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, len(POSTSTRING))
self.curl.setopt(self.curl.READFUNCTION, d.read_cb)
@@ -75,7 +76,7 @@ class ReadCbTest(unittest.TestCase):
assert type(data) == util.binary_type
d = DataProvider(data)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/raw_utf8')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/raw_utf8' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.HTTPHEADER, ['Content-Type: application/octet-stream'])
# length of bytes
@@ -111,7 +112,7 @@ class ReadCbTest(unittest.TestCase):
assert type(poststring) == util.text_type
d = DataProvider(poststring)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/raw_utf8')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/raw_utf8' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.HTTPHEADER, ['Content-Type: application/octet-stream'])
self.curl.setopt(self.curl.POSTFIELDSIZE, len(poststring))
diff --git a/tests/readdata_test.py b/tests/readdata_test.py
index b4f1cde..5ce6904 100644
--- a/tests/readdata_test.py
+++ b/tests/readdata_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
try:
import unittest2 as unittest
@@ -55,7 +56,7 @@ class ReaddataTest(unittest.TestCase):
def test_readdata_object(self):
d = DataProvider(POSTSTRING)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, len(POSTSTRING))
self.curl.setopt(self.curl.READDATA, d)
@@ -80,7 +81,7 @@ class ReaddataTest(unittest.TestCase):
assert type(data) == util.binary_type
d = DataProvider(data)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/raw_utf8')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/raw_utf8' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.HTTPHEADER, ['Content-Type: application/octet-stream'])
# length of bytes
@@ -115,7 +116,7 @@ class ReaddataTest(unittest.TestCase):
assert type(poststring) == util.text_type
d = DataProvider(poststring)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/raw_utf8')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/raw_utf8' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.HTTPHEADER, ['Content-Type: application/octet-stream'])
self.curl.setopt(self.curl.POSTFIELDSIZE, len(poststring))
@@ -132,7 +133,7 @@ class ReaddataTest(unittest.TestCase):
# file opened in binary mode
f = open(FORM_SUBMISSION_PATH, 'rb')
try:
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, os.stat(FORM_SUBMISSION_PATH).st_size)
self.curl.setopt(self.curl.READDATA, f)
@@ -149,7 +150,7 @@ class ReaddataTest(unittest.TestCase):
# file opened in text mode
f = open(FORM_SUBMISSION_PATH, 'rt')
try:
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, os.stat(FORM_SUBMISSION_PATH).st_size)
self.curl.setopt(self.curl.READDATA, f)
@@ -165,7 +166,7 @@ class ReaddataTest(unittest.TestCase):
def test_readdata_file_like(self):
data = 'hello=world'
data_provider = DataProvider(data)
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, len(data))
self.curl.setopt(self.curl.READDATA, data_provider)
@@ -181,7 +182,7 @@ class ReaddataTest(unittest.TestCase):
data_provider = DataProvider(data)
# data must be the same length
function_provider = DataProvider('aaaaa=bbbbb')
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, len(data))
self.curl.setopt(self.curl.READDATA, data_provider)
@@ -198,7 +199,7 @@ class ReaddataTest(unittest.TestCase):
data_provider = DataProvider(data)
# data must be the same length
function_provider = DataProvider('aaaaa=bbbbb')
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, len(data))
self.curl.setopt(self.curl.READFUNCTION, function_provider.read)
@@ -214,7 +215,7 @@ class ReaddataTest(unittest.TestCase):
# data must be the same length
with open(FORM_SUBMISSION_PATH) as f:
function_provider = DataProvider('aaa=bbb')
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, os.stat(FORM_SUBMISSION_PATH).st_size)
self.curl.setopt(self.curl.READDATA, f)
@@ -230,7 +231,7 @@ class ReaddataTest(unittest.TestCase):
# data must be the same length
with open(FORM_SUBMISSION_PATH) as f:
function_provider = DataProvider('aaa=bbb')
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/postfields')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/postfields' % localhost)
self.curl.setopt(self.curl.POST, 1)
self.curl.setopt(self.curl.POSTFIELDSIZE, os.stat(FORM_SUBMISSION_PATH).st_size)
self.curl.setopt(self.curl.READFUNCTION, function_provider.read)
diff --git a/tests/relative_url_test.py b/tests/relative_url_test.py
index 42052ec..a267255 100644
--- a/tests/relative_url_test.py
+++ b/tests/relative_url_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
# uses the high level interface
import curl
import unittest
@@ -12,7 +13,7 @@ setup_module, teardown_module = appmanager.setup(('app', 8380))
class RelativeUrlTest(unittest.TestCase):
def setUp(self):
- self.curl = curl.Curl('http://localhost:8380/')
+ self.curl = curl.Curl('http://%s:8380/' % localhost)
def tearDown(self):
self.curl.close()
diff --git a/tests/reset_test.py b/tests/reset_test.py
index 9bef979..c9938f3 100644
--- a/tests/reset_test.py
+++ b/tests/reset_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
@@ -14,7 +15,7 @@ class ResetTest(unittest.TestCase):
def test_reset(self):
c = util.DefaultCurl()
c.setopt(pycurl.USERAGENT, 'Phony/42')
- c.setopt(pycurl.URL, 'http://localhost:8380/header?h=user-agent')
+ c.setopt(pycurl.URL, 'http://%s:8380/header?h=user-agent' % localhost)
sio = util.BytesIO()
c.setopt(pycurl.WRITEFUNCTION, sio.write)
c.perform()
@@ -22,7 +23,7 @@ class ResetTest(unittest.TestCase):
assert user_agent == 'Phony/42'
c.reset()
- c.setopt(pycurl.URL, 'http://localhost:8380/header?h=user-agent')
+ c.setopt(pycurl.URL, 'http://%s:8380/header?h=user-agent' % localhost)
sio = util.BytesIO()
c.setopt(pycurl.WRITEFUNCTION, sio.write)
c.perform()
@@ -40,7 +41,7 @@ class ResetTest(unittest.TestCase):
for x in range(1, 20):
eh.setopt(pycurl.WRITEFUNCTION, outf.write)
- eh.setopt(pycurl.URL, 'http://localhost:8380/success')
+ eh.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
cm.add_handle(eh)
while 1:
diff --git a/tests/setopt_lifecycle_test.py b/tests/setopt_lifecycle_test.py
index 3189a59..1adb70c 100644
--- a/tests/setopt_lifecycle_test.py
+++ b/tests/setopt_lifecycle_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import gc
import pycurl
import unittest
@@ -26,7 +27,7 @@ class SetoptLifecycleTest(unittest.TestCase):
# garbage collected before perform call
def do_setopt(self, curl, index):
pf = TestString('&'.join(50*['field=value%d' % (index,)]))
- curl.setopt(pycurl.URL, 'http://localhost:8380/postfields')
+ curl.setopt(pycurl.URL, 'http://%s:8380/postfields' % localhost)
curl.setopt(pycurl.POSTFIELDS, pf)
# This test takes 6+ seconds to run.
diff --git a/tests/setopt_string_test.py b/tests/setopt_string_test.py
index 7c2ffb6..4bd62e8 100644
--- a/tests/setopt_string_test.py
+++ b/tests/setopt_string_test.py
@@ -3,6 +3,7 @@
# vi:ts=4:et
import pycurl
+from . import localhost
import unittest
import nose.tools
@@ -19,7 +20,7 @@ class SetoptTest(unittest.TestCase):
self.curl.close()
def test_setopt_string(self):
- self.curl.setopt_string(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt_string(pycurl.URL, 'http://%s:8380/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
diff --git a/tests/setopt_test.py b/tests/setopt_test.py
index fc5ed7f..be76aea 100644
--- a/tests/setopt_test.py
+++ b/tests/setopt_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import nose.tools
@@ -53,7 +54,7 @@ class SetoptTest(unittest.TestCase):
def test_unset_httpheader(self):
self.curl.setopt(self.curl.HTTPHEADER, ('x-test: foo',))
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/header?h=x-test')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/header?h=x-test' % localhost)
io = util.BytesIO()
self.curl.setopt(self.curl.WRITEDATA, io)
self.curl.perform()
@@ -67,7 +68,7 @@ class SetoptTest(unittest.TestCase):
def test_set_httpheader_none(self):
self.curl.setopt(self.curl.HTTPHEADER, ('x-test: foo',))
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/header?h=x-test')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/header?h=x-test' % localhost)
io = util.BytesIO()
self.curl.setopt(self.curl.WRITEDATA, io)
self.curl.perform()
diff --git a/tests/setopt_unicode_test.py b/tests/setopt_unicode_test.py
index 32c0f79..c90ae06 100644
--- a/tests/setopt_unicode_test.py
+++ b/tests/setopt_unicode_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import nose.tools
@@ -29,7 +30,7 @@ class SetoptUnicodeTest(unittest.TestCase):
self.check(util.u('p=Москва').encode('utf8'), util.u('Москва'))
def check(self, send, expected):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/param_utf8_hack')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/param_utf8_hack' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.setopt(pycurl.POSTFIELDS, send)
diff --git a/tests/share_test.py b/tests/share_test.py
index 6015419..7953476 100644
--- a/tests/share_test.py
+++ b/tests/share_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import threading
import pycurl
import unittest
@@ -17,7 +18,7 @@ class WorkerThread(threading.Thread):
def __init__(self, share):
threading.Thread.__init__(self)
self.curl = util.DefaultCurl()
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
self.curl.setopt(pycurl.SHARE, share)
self.sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, self.sio.write)
diff --git a/tests/sockopt_cb_test.py b/tests/sockopt_cb_test.py
index a603e60..c926460 100644
--- a/tests/sockopt_cb_test.py
+++ b/tests/sockopt_cb_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import unittest
import pycurl
@@ -13,7 +14,7 @@ setup_module, teardown_module = appmanager.setup(('app', 8380))
class SockoptCbTest(unittest.TestCase):
def setUp(self):
self.curl = util.DefaultCurl()
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/success' % localhost)
def tearDown(self):
self.curl.close()
diff --git a/tests/unset_range_test.py b/tests/unset_range_test.py
index 4c1ed2a..2de5938 100644
--- a/tests/unset_range_test.py
+++ b/tests/unset_range_test.py
@@ -4,7 +4,6 @@
import os.path
import pycurl
-import sys
import unittest
class UnsetRangeTest(unittest.TestCase):
diff --git a/tests/user_agent_string_test.py b/tests/user_agent_string_test.py
index c9b23a5..e89023e 100644
--- a/tests/user_agent_string_test.py
+++ b/tests/user_agent_string_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import unittest
import pycurl
@@ -18,7 +19,7 @@ class UserAgentStringTest(unittest.TestCase):
self.curl.close()
def test_pycurl_user_agent_string(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/header?h=user-agent')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/header?h=user-agent' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
diff --git a/tests/win/opensocketcrash.py b/tests/win/opensocketcrash.py
index 1ba3dab..10bd080 100644
--- a/tests/win/opensocketcrash.py
+++ b/tests/win/opensocketcrash.py
@@ -1,3 +1,4 @@
+from . import localhost
import pycurl
from io import BytesIO
import socket
@@ -16,7 +17,7 @@ def socket_open(family, socktype, protocol, address):
curl = pycurl.Curl()
curl.setopt(pycurl.OPENSOCKETFUNCTION, socket_open)
-curl.setopt(curl.URL, 'http://localhost:8380/success')
+curl.setopt(curl.URL, 'http://%s:8380/success' % localhost)
sio = BytesIO()
curl.setopt(pycurl.WRITEFUNCTION, sio.write)
print(1)
diff --git a/tests/write_test.py b/tests/write_test.py
index a5f3684..09d3c60 100644
--- a/tests/write_test.py
+++ b/tests/write_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
try:
import unittest2 as unittest
except ImportError:
@@ -31,7 +32,7 @@ class WriteTest(unittest.TestCase):
self.curl.close()
def test_write_to_tempfile_via_function(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
f = tempfile.NamedTemporaryFile()
try:
self.curl.setopt(pycurl.WRITEFUNCTION, f.write)
@@ -43,7 +44,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('success', body.decode())
def test_write_to_tempfile_via_object(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
f = tempfile.NamedTemporaryFile()
try:
self.curl.setopt(pycurl.WRITEDATA, f)
@@ -55,7 +56,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('success', body.decode())
def test_write_to_file_via_function(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
dir = tempfile.mkdtemp()
try:
path = os.path.join(dir, 'pycurltest')
@@ -72,7 +73,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('success', body.decode())
def test_write_to_file_via_object(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
dir = tempfile.mkdtemp()
try:
path = os.path.join(dir, 'pycurltest')
@@ -89,7 +90,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('success', body.decode())
def test_write_to_file_like(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
acceptor = Acceptor()
self.curl.setopt(pycurl.WRITEDATA, acceptor)
self.curl.perform()
@@ -97,7 +98,7 @@ class WriteTest(unittest.TestCase):
@util.with_real_write_file
def test_write_to_file_like_then_real_file(self, real_f):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
acceptor = Acceptor()
self.curl.setopt(pycurl.WRITEDATA, acceptor)
self.curl.perform()
@@ -110,7 +111,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('success', body.decode())
def test_headerfunction_and_writefunction(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
header_acceptor = Acceptor()
body_acceptor = Acceptor()
self.curl.setopt(pycurl.HEADERFUNCTION, header_acceptor.write)
@@ -120,7 +121,7 @@ class WriteTest(unittest.TestCase):
self.assertIn('content-type', header_acceptor.buffer.lower())
def test_writeheader_and_writedata_file_like(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
header_acceptor = Acceptor()
body_acceptor = Acceptor()
self.curl.setopt(pycurl.WRITEHEADER, header_acceptor)
@@ -132,7 +133,7 @@ class WriteTest(unittest.TestCase):
@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://localhost:8380/success')
+ 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()
@@ -142,7 +143,7 @@ class WriteTest(unittest.TestCase):
self.assertIn('content-type', real_f_header.read().decode().lower())
def test_writedata_and_writefunction_file_like(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
data_acceptor = Acceptor()
function_acceptor = Acceptor()
self.curl.setopt(pycurl.WRITEDATA, data_acceptor)
@@ -153,7 +154,7 @@ class WriteTest(unittest.TestCase):
@util.with_real_write_file
def test_writedata_and_writefunction_real_file(self, real_f):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ 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)
@@ -163,7 +164,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('success', function_acceptor.buffer)
def test_writefunction_and_writedata_file_like(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
data_acceptor = Acceptor()
function_acceptor = Acceptor()
self.curl.setopt(pycurl.WRITEFUNCTION, function_acceptor.write)
@@ -174,7 +175,7 @@ class WriteTest(unittest.TestCase):
@util.with_real_write_file
def test_writefunction_and_writedata_real_file(self, real_f):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ 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)
@@ -184,7 +185,7 @@ class WriteTest(unittest.TestCase):
self.assertEqual('', function_acceptor.buffer)
def test_writeheader_and_headerfunction_file_like(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
data_acceptor = Acceptor()
function_acceptor = Acceptor()
body_acceptor = Acceptor()
@@ -198,7 +199,7 @@ class WriteTest(unittest.TestCase):
@util.with_real_write_file
def test_writeheader_and_headerfunction_real_file(self, real_f):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
function_acceptor = Acceptor()
body_acceptor = Acceptor()
self.curl.setopt(pycurl.WRITEHEADER, real_f)
@@ -211,7 +212,7 @@ class WriteTest(unittest.TestCase):
self.assertIn('content-type', function_acceptor.buffer.lower())
def test_headerfunction_and_writeheader_file_like(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
data_acceptor = Acceptor()
function_acceptor = Acceptor()
body_acceptor = Acceptor()
@@ -225,7 +226,7 @@ class WriteTest(unittest.TestCase):
@util.with_real_write_file
def test_headerfunction_and_writeheader_real_file(self, real_f):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
function_acceptor = Acceptor()
body_acceptor = Acceptor()
self.curl.setopt(pycurl.HEADERFUNCTION, function_acceptor.write)
diff --git a/tests/write_to_stringio_test.py b/tests/write_to_stringio_test.py
index 0ddbc20..50f3f77 100644
--- a/tests/write_to_stringio_test.py
+++ b/tests/write_to_stringio_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import pycurl
import unittest
import sys
@@ -19,7 +20,7 @@ class WriteToStringioTest(unittest.TestCase):
self.curl.close()
def test_write_to_bytesio(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
sio = util.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
self.curl.perform()
@@ -27,7 +28,7 @@ class WriteToStringioTest(unittest.TestCase):
@util.only_python3
def test_write_to_stringio(self):
- self.curl.setopt(pycurl.URL, 'http://localhost:8380/success')
+ self.curl.setopt(pycurl.URL, 'http://%s:8380/success' % localhost)
# stringio in python 3
sio = util.StringIO()
self.curl.setopt(pycurl.WRITEFUNCTION, sio.write)
diff --git a/tests/xferinfo_cb_test.py b/tests/xferinfo_cb_test.py
index 715374c..ada5e2d 100644
--- a/tests/xferinfo_cb_test.py
+++ b/tests/xferinfo_cb_test.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
# vi:ts=4:et
+from . import localhost
import unittest
import pycurl
@@ -13,7 +14,7 @@ setup_module, teardown_module = appmanager.setup(('app', 8380))
class XferinfoCbTest(unittest.TestCase):
def setUp(self):
self.curl = util.DefaultCurl()
- self.curl.setopt(self.curl.URL, 'http://localhost:8380/long_pause')
+ self.curl.setopt(self.curl.URL, 'http://%s:8380/long_pause' % localhost)
def tearDown(self):
self.curl.close()