Debian Codegraph @

test/test_functional.py

raw symbols SCIP
1 #!/usr/bin/env python
2
3 # These tests access the network. python test.py runs a local test server and
4 # doesn't try to fetch anything over the internet, since the few tests here
5 # that do that are disabled by default since they have test tag "internet".
6
7 # thanks Moof (aka Giles Antonio Radford) for some of these
8
9 import copy
10 import errno
11 import os
12 import socket
13 import subprocess
14 import sys
15 import unittest
16
17 import mechanize
18 from mechanize import (
19 CookieJar, HTTPCookieProcessor, HTTPRefreshProcessor,
20 HTTPEquivProcessor, HTTPRedirectHandler)
21 from mechanize._rfc3986 import urljoin
22 from mechanize._util import read_file, write_file
23 import mechanize._opener
24 import mechanize._rfc3986
25 import mechanize._sockettimeout
26 import mechanize._testcase
27 from mechanize.polyglot import (
28 install_opener, build_opener, ProxyHandler, pathname2url, quote_plus,
29 urlopen
30 )
31
32
33 # from cookielib import CookieJar
34 # from urllib2 import build_opener, install_opener, urlopen
35 # from urllib2 import HTTPCookieProcessor, HTTPHandler
36
37 # from mechanize import CreateBSDDBCookieJar
38
39 # import logging
40 # logger = logging.getLogger("mechanize")
41 # logger.addHandler(logging.StreamHandler(sys.stdout))
42 # logger.setLevel(logging.DEBUG)
43 # logger.setLevel(logging.INFO)
44
45
46 class TestCase(mechanize._testcase.TestCase):
47
48 # testprogram sets self.no_proxies on each TestCase to request explicitly
49 # setting proxies so that http*_proxy environment variables are ignored
50
51 def _configure_user_agent(self, ua):
52 if self.no_proxies:
53 ua.set_proxies({})
54
55 def make_browser(self):
56 browser = mechanize.Browser()
57 self._configure_user_agent(browser)
58 return browser
59
60 def make_user_agent(self):
61 ua = mechanize.UserAgent()
62 self._configure_user_agent(ua)
63 return ua
64
65 def build_opener(self, handlers=(), build_opener=None):
66 handlers += (mechanize.ProxyHandler(proxies={}),)
67 if build_opener is None:
68 build_opener = mechanize.build_opener
69 return build_opener(*handlers)
70
71 def setUp(self):
72 mechanize._testcase.TestCase.setUp(self)
73 self.test_uri = urljoin(self.uri, "test_fixtures")
74 self.server = self.get_cached_fixture("server")
75 if self.no_proxies:
76 old_opener_m = mechanize._opener._opener
77 mechanize.install_opener(mechanize.build_opener(
78 mechanize.ProxyHandler(proxies={})))
79 install_opener(build_opener(
80 ProxyHandler(proxies={})))
81
82 def revert_install():
83 mechanize.install_opener(old_opener_m)
84 install_opener(None)
85 self.add_teardown(revert_install)
86
87
88 def sanepathname2url(path):
89 urlpath = pathname2url(path)
90 if os.name == "nt" and urlpath.startswith("///"):
91 urlpath = urlpath[2:]
92 # XXX don't ask me about the mac...
93 return urlpath
94
95
96 class FtpTestCase(TestCase):
97
98 def test_ftp(self):
99 server = self.get_cached_fixture("ftp_server")
100 browser = self.make_browser()
101 path = self.make_temp_dir(dir_=server.root_path)
102 file_path = os.path.join(path, "stuff")
103 data = b"data\nmore data"
104 write_file(file_path, data)
105 relative_path = os.path.join(os.path.basename(path), "stuff")
106 r = browser.open("ftp://anon@localhost:%s/%s" %
107 (server.port, relative_path.replace(os.sep, '/')))
108 self.assertEqual(r.read(), data)
109
110
111 class SocketTimeoutTest(TestCase):
112
113 # the timeout tests in this module aren't full functional tests: in order
114 # to speed things up, don't actually call .settimeout on the socket. XXX
115 # allow running the tests against a slow server with a real timeout
116
117 def _monkey_patch_socket(self):
118 class Delegator(object):
119
120 def __init__(self, delegate):
121 self._delegate = delegate
122
123 def __getattr__(self, name):
124 return getattr(self._delegate, name)
125
126 assertEquals = self.assertEqual
127
128 class TimeoutLog(object):
129 AnyValue = object()
130
131 def __init__(self):
132 self._nr_sockets = 0
133 self._timeouts = []
134 self.start()
135
136 def start(self):
137 self._monitoring = True
138
139 def stop(self):
140 self._monitoring = False
141
142 def socket_created(self):
143 if self._monitoring:
144 self._nr_sockets += 1
145
146 def settimeout_called(self, timeout):
147 if self._monitoring:
148 self._timeouts.append(timeout)
149
150 def verify(self, value=AnyValue):
151 if sys.version_info[:2] < (2, 6):
152 # per-connection timeout not supported in Python 2.5
153 self.verify_default()
154 else:
155 assertEquals(len(self._timeouts), self._nr_sockets)
156 if value is not self.AnyValue:
157 for timeout in self._timeouts:
158 assertEquals(timeout, value)
159
160 def verify_default(self):
161 assertEquals(len(self._timeouts), 0)
162
163 log = TimeoutLog()
164
165 def settimeout(timeout):
166 log.settimeout_called(timeout)
167 orig_socket = socket.socket
168
169 def make_socket(*args, **kwds):
170 sock = Delegator(orig_socket(*args, **kwds))
171 log.socket_created()
172 sock.settimeout = settimeout
173 return sock
174 self.monkey_patch(socket, "socket", make_socket)
175 return log
176
177
178 class SimpleTests(SocketTimeoutTest):
179 # thanks Moof (aka Giles Antonio Radford)
180
181 def setUp(self):
182 super(SimpleTests, self).setUp()
183 self.browser = self.make_browser()
184
185 def tearDown(self):
186 super(SimpleTests, self).tearDown()
187 self.browser.close()
188 del self.browser
189
190 def test_simple(self):
191 self.browser.open(self.test_uri)
192 self.assertEqual(self.browser.title(), 'Python bits')
193 # relative URL
194 self.browser.open('/mechanize/').close()
195 self.assertEqual(self.browser.title(), 'mechanize')
196
197 def test_basic_auth(self):
198 uri = urljoin(self.uri, "basic_auth")
199 self.assertRaises(mechanize.URLError, self.browser.open, uri)
200 self.browser.add_password(uri, "john", "john")
201 self.browser.open(uri)
202 self.assertEqual(self.browser.title(), 'Basic Auth Protected Area')
203
204 def test_digest_auth(self):
205 uri = urljoin(self.uri, "digest_auth")
206 self.assertRaises(mechanize.URLError, self.browser.open, uri)
207 self.browser.add_password(uri, "digestuser", "digestuser")
208 self.browser.open(uri)
209 self.assertEqual(self.browser.title(), 'Digest Auth Protected Area')
210
211 def test_open_with_default_timeout(self):
212 timeout_log = self._monkey_patch_socket()
213 self.browser.open(self.test_uri)
214 self.assertEqual(self.browser.title(), 'Python bits')
215 timeout_log.verify_default()
216
217 def test_open_with_timeout(self):
218 timeout_log = self._monkey_patch_socket()
219 timeout = 10.
220 self.browser.open(self.test_uri, timeout=timeout)
221 self.assertEqual(self.browser.title(), 'Python bits')
222 timeout_log.verify(timeout)
223
224 def test_urlopen_with_default_timeout(self):
225 timeout_log = self._monkey_patch_socket()
226 response = mechanize.urlopen(self.test_uri)
227 self.assert_contains(response.read(), b"Python bits")
228 timeout_log.verify_default()
229
230 def test_urlopen_with_timeout(self):
231 timeout_log = self._monkey_patch_socket()
232 timeout = 10.
233 response = mechanize.urlopen(self.test_uri, timeout=timeout)
234 self.assert_contains(response.read(), b"Python bits")
235 timeout_log.verify(timeout)
236
237 def test_redirect_with_timeout(self):
238 timeout_log = self._monkey_patch_socket()
239 timeout = 10.
240 # 301 redirect due to missing final '/'
241 req = mechanize.Request(urljoin(self.test_uri, "test_fixtures"),
242 timeout=timeout)
243 r = self.browser.open(req)
244 self.assertIn(b"GeneralFAQ.html", r.read(2048))
245 timeout_log.verify(timeout)
246
247 def test_302_and_404(self):
248 # the combination of 302 and 404 (/redirected is configured to redirect
249 # to a non-existent URL /nonexistent) has caused problems in the past
250 # due to accidental double-wrapping of the error response
251 self.assertRaises(
252 mechanize.HTTPError,
253 self.browser.open, urljoin(self.uri, "/redirected"),
254 )
255
256 def test_reread(self):
257 # closing response shouldn't stop methods working (this happens also to
258 # be true for e.g. mechanize.OpenerDirector when mechanize's own
259 # handlers are in use, but is guaranteed to be true for
260 # mechanize.Browser)
261 r = self.browser.open(self.uri)
262 data = r.read()
263 r.close()
264 r.seek(0)
265 self.assertEqual(r.read(), data)
266 self.assertEqual(self.browser.response().read(), data)
267
268 def test_error_recovery(self):
269 self.assertRaises(mechanize.URLError, self.browser.open,
270 'file:///c|thisnoexistyiufheiurgbueirgbue')
271 self.browser.open(self.test_uri)
272 self.assertEqual(self.browser.title(), 'Python bits')
273
274 def test_redirect(self):
275 # 301 redirect due to missing final '/'
276
277 class ObservingHandler(mechanize.BaseHandler):
278
279 def __init__(self):
280 self.codes = []
281
282 def http_response(self, request, response):
283 self.codes.append(response.code)
284 return response
285
286 self.browser.add_handler(ObservingHandler())
287 for br in self.browser, copy.copy(self.browser):
288 r = br.open(urljoin(self.uri, "redirected_good"))
289 self.assertEqual(r.code, 200)
290 self.assertTrue(b"GeneralFAQ.html" in r.read(2048))
291 self.assertEqual([
292 [c for c in h.codes if c == 302]
293 for h in br.handlers_by_class(ObservingHandler)], [[302]])
294
295 def test_refresh(self):
296 def refresh_request(seconds):
297 uri = urljoin(self.uri, "/dynamic")
298 val = quote_plus('%d; url="%s"' % (seconds, self.uri))
299 return uri + ("?refresh=%s" % val)
300 self.browser.set_handle_refresh(True, honor_time=False)
301 r = self.browser.open(refresh_request(5))
302 self.assertEqual(r.geturl(), self.uri)
303 # Set a maximum refresh time of 30 seconds (these long refreshes tend
304 # to be there only because the website owner wants you to see the
305 # latest news, or whatever -- they're not essential to the operation of
306 # the site, and not really useful or appropriate when scraping).
307 refresh_uri = refresh_request(60)
308 self.browser.set_handle_refresh(True, max_time=30., honor_time=True)
309 r = self.browser.open(refresh_uri)
310 self.assertEqual(r.geturl(), refresh_uri)
311 # allow long refreshes (but don't actually wait 60 seconds)
312 self.browser.set_handle_refresh(True, max_time=None, honor_time=False)
313 r = self.browser.open(refresh_request(60))
314 self.assertEqual(r.geturl(), self.uri)
315
316 def test_file_url(self):
317 url = "file://%s" % sanepathname2url(os.path.abspath(__file__))
318 r = self.browser.open(url)
319 self.assertIn(b"this string appears in this file ;-)", r.read())
320
321 def test_open_local_file(self):
322 # Since the file: URL scheme is not well standardised, Browser has a
323 # special method to open files by name, for convenience:
324 path = os.path.abspath(__file__)
325 response = self.browser.open_local_file(path)
326 self.assertIn(b"this string appears in this file ;-)",
327 response.get_data())
328
329 def test_open_novisit(self):
330 def test_state(br):
331 self.assertTrue(br.request is None)
332 self.assertTrue(br.response() is None)
333 self.assertRaises(mechanize.BrowserStateError, br.back)
334 test_state(self.browser)
335 uri = urljoin(self.uri, "test_fixtures")
336 # note this involves a redirect, which should itself be non-visiting
337 r = self.browser.open_novisit(uri)
338 test_state(self.browser)
339 self.assertIn(b"GeneralFAQ.html", r.read(2048))
340
341 # Request argument instead of URL
342 r = self.browser.open_novisit(mechanize.Request(uri))
343 test_state(self.browser)
344 self.assertIn(b"GeneralFAQ.html", r.read(2048))
345
346 def test_non_seekable(self):
347 # check everything still works without response_seek_wrapper and
348 # the .seek() method on response objects
349 ua = self.make_user_agent()
350 ua.set_seekable_responses(False)
351 ua.set_handle_equiv(False)
352 response = ua.open(self.test_uri)
353 self.assertFalse(hasattr(response, "seek"))
354 data = response.read()
355 self.assertIn(b"Python bits", data)
356
357 def test_gzip(self):
358 self.browser.set_handle_gzip(True)
359 data = self.browser.open(self.uri + '/gzip').read()
360 self.assertIn(b'twisted-localserver.py', data)
361
362
363 class ResponseTests(TestCase):
364
365 def test_seek(self):
366 br = self.make_browser()
367 r = br.open(self.uri)
368 html = r.read()
369 r.seek(0)
370 self.assertEqual(r.read(), html)
371
372 def test_seekable_response_opener(self):
373 build_opener = mechanize.OpenerFactory(
374 mechanize.SeekableResponseOpener).build_opener
375 opener = self.build_opener(build_opener=build_opener)
376 r = opener.open(urljoin(self.uri, "test_fixtures/cctest2.txt"))
377 r.read()
378 r.seek(0)
379 self.assertEqual(r.read(),
380 r.get_data(),
381 "Hello ClientCookie functional test suite.\n")
382
383 def test_seek_wrapper_class_name(self):
384 opener = self.make_user_agent()
385 opener.set_seekable_responses(True)
386 rexec = ''
387 try:
388 opener.open(urljoin(self.uri, "nonexistent"))
389 except mechanize.HTTPError as exc:
390 rexec = repr(exc)
391 self.assertIn("HTTPError instance", rexec)
392
393 def test_no_seek(self):
394 # should be possible to turn off UserAgent's .seek() functionality
395 def check_no_seek(opener):
396 r = opener.open(urljoin(self.uri, "test_fixtures/cctest2.txt"))
397 self.assertTrue(not hasattr(r, "seek"))
398 try:
399 opener.open(urljoin(self.uri, "nonexistent"))
400 except mechanize.HTTPError as exc:
401 self.assertTrue(not hasattr(exc, "seek"))
402
403 # mechanize.UserAgent
404 opener = self.make_user_agent()
405 opener.set_handle_equiv(False)
406 opener.set_seekable_responses(False)
407 opener.set_debug_http(False)
408 check_no_seek(opener)
409
410 # mechanize.OpenerDirector
411 opener = self.build_opener()
412 check_no_seek(opener)
413
414 def test_consistent_seek(self):
415 # if we explicitly request that returned response objects have the
416 # .seek() method, then raised HTTPError exceptions should also have the
417 # .seek() method
418 def check(opener, excs_also):
419 r = opener.open(urljoin(self.uri, "test_fixtures/cctest2.txt"))
420 data = r.read()
421 r.seek(0)
422 self.assertEqual(data, r.read(), r.get_data())
423 try:
424 opener.open(urljoin(self.uri, "nonexistent"))
425 except mechanize.HTTPError as exc:
426 data = exc.read()
427 if excs_also:
428 exc.seek(0)
429 self.assertEqual(data, exc.read(), exc.get_data())
430 else:
431 self.assertTrue(False)
432
433 opener = self.make_user_agent()
434 opener.set_debug_http(False)
435
436 # Here, only the .set_handle_equiv() causes .seek() to be present, so
437 # exceptions don't necessarily support the .seek() method (and do not,
438 # at present).
439 opener.set_handle_equiv(True)
440 opener.set_seekable_responses(False)
441 check(opener, excs_also=False)
442
443 # Here, (only) the explicit .set_seekable_responses() causes .seek() to
444 # be present (different mechanism from .set_handle_equiv()). Since
445 # there's an explicit request, ALL responses are seekable, even
446 # exception responses (HTTPError instances).
447 opener.set_handle_equiv(False)
448 opener.set_seekable_responses(True)
449 check(opener, excs_also=True)
450
451 def test_set_response(self):
452 br = self.make_browser()
453 r = br.open(self.test_uri)
454 html = r.read()
455 self.assertEqual(br.title(), "Python bits")
456
457 newhtml = b"""<html><body><a href="spam">click me</a></body></html>"""
458
459 r.set_data(newhtml)
460 self.assertEqual(r.read(), newhtml)
461 self.assertEqual(br.response().read(), html)
462 br.response().set_data(newhtml)
463 self.assertEqual(br.response().read(), html)
464 self.assertEqual(list(br.links())[0].url, "http://sourceforge.net/")
465
466 br.set_response(r)
467 self.assertEqual(br.response().read(), newhtml)
468 self.assertEqual(list(br.links())[0].url, "spam")
469
470 def test_new_response(self):
471 br = self.make_browser()
472 data = (b"<html><head><title>Test</title></head>"
473 b"<body><p>Hello.</p></body></html>")
474 response = mechanize.make_response(
475 data,
476 [("Content-type", "text/html")],
477 "http://example.com/",
478 200,
479 "OK")
480 br.set_response(response)
481 self.assertEqual(br.response().get_data(), data)
482
483
484 class FunctionalTests(SocketTimeoutTest):
485
486 def test_404(self):
487 br = self.make_browser()
488 self.assertRaises(
489 mechanize.HTTPError,
490 br.open, urljoin(self.uri, "/does-not-exist"),
491 )
492
493 def test_referer(self):
494 br = self.make_browser()
495 br.set_handle_refresh(True, honor_time=False)
496 referer = urljoin(self.uri, "test_fixtures/referertest.html")
497 info = urljoin(self.uri, "/dynamic")
498 r = br.open(info)
499 self.assertNotIn(referer.encode('ascii'), r.get_data())
500
501 br.open(referer)
502 r = br.follow_link(text="Here")
503 self.assertIn(referer.encode('ascii'), r.get_data())
504
505 def test_cookies(self):
506 # this test page depends on cookies, and an http-equiv refresh
507 # cj = CreateBSDDBCookieJar("/home/john/db.db")
508 cj = CookieJar()
509 handlers = [
510 HTTPCookieProcessor(cj),
511 HTTPRefreshProcessor(max_time=None, honor_time=False),
512 HTTPEquivProcessor(),
513
514 HTTPRedirectHandler(), # needed for Refresh handling in 2.4.0
515 # HTTPHandler(True),
516 # HTTPRedirectDebugProcessor(),
517 # HTTPResponseDebugProcessor(),
518 ]
519
520 opener = self.build_opener(handlers)
521 r = opener.open(urljoin(self.uri, "/dynamic"))
522 data = r.read()
523 self.assertIn(b"Your browser supports cookies!", data)
524 self.assertEqual(len(cj), 2)
525
526 # test response.seek() (added by HTTPEquivProcessor)
527 r.seek(0)
528 samedata = r.read()
529 r.close()
530 self.assertEqual(samedata, data)
531
532 def test_robots(self):
533 plain_opener = self.build_opener(
534 [mechanize.HTTPRobotRulesProcessor])
535 browser = self.make_browser()
536 for opener in plain_opener, browser:
537 opener.open(urljoin(self.uri, "robots"))
538 self.assertRaises(
539 mechanize.RobotExclusionError,
540 opener.open, urljoin(self.uri, "norobots"))
541
542 def _check_retrieve(self, url, filename, headers):
543 self.assertEqual(headers.get('Content-Type'), 'text/html')
544 if self.no_proxies:
545 proxies = {}
546 else:
547 proxies = None
548 self.assertEqual(read_file(filename),
549 urlopen(url, proxies=proxies).read())
550
551 def test_retrieve_to_named_file(self):
552 url = urljoin(self.uri, "/mechanize/")
553 test_filename = os.path.join(self.make_temp_dir(), "python.html")
554 opener = self.build_opener()
555 verif = CallbackVerifier(self)
556 filename, headers = opener.retrieve(url, test_filename, verif.callback)
557 self.assertEqual(filename, test_filename)
558 self._check_retrieve(url, filename, headers)
559 self.assertTrue(os.path.isfile(filename))
560
561 def test_retrieve(self):
562 # not passing an explicit filename downloads to a temporary file
563 # using a Request object instead of a URL works
564 url = urljoin(self.uri, "/mechanize/")
565 opener = self.build_opener()
566 verif = CallbackVerifier(self)
567 request = mechanize.Request(url)
568 filename, headers = opener.retrieve(request, reporthook=verif.callback)
569 self.assertEqual(request.visit, False)
570 self._check_retrieve(url, filename, headers)
571 opener.close()
572 # closing the opener removed the temporary file
573 self.assertFalse(os.path.isfile(filename))
574
575 def test_urlretrieve(self):
576 timeout_log = self._monkey_patch_socket()
577 timeout = 10.
578 url = urljoin(self.uri, "/mechanize/")
579 verif = CallbackVerifier(self)
580 filename, headers = mechanize.urlretrieve(url,
581 reporthook=verif.callback,
582 timeout=timeout)
583 timeout_log.stop()
584 self._check_retrieve(url, filename, headers)
585 timeout_log.verify(timeout)
586
587 def test_reload_read_incomplete(self):
588 browser = self.make_browser()
589 r1 = browser.open(urljoin(self.uri,
590 "test_fixtures/mechanize_reload_test.html"))
591 # if we don't do anything and go straight to another page, most of the
592 # last page's response won't be .read()...
593 browser.open(urljoin(self.uri, "mechanize"))
594 # we only .read() a little bit
595 self.assertLessEqual(len(r1.get_data()), 4096)
596 # ...so if we then go back, .follow_link() for a link near the end (a
597 # few kb in, past the point that always gets read in HTML files because
598 # of HEAD parsing) will only work if it causes a .reload()...
599 r3 = browser.back()
600 browser.follow_link(text="near the end")
601 # ... good, no LinkNotFoundError, so we did reload.
602 # we have .read() the whole file
603 self.assertEqual(len(r3._seek_wrapper__cache.getvalue()), 4202)
604
605 # def test_cacheftp(self):
606 # from mechanize import CacheFTPHandler, build_opener
607 # o = build_opener(CacheFTPHandler())
608 # r = o.open("ftp://ftp.python.org/pub/www.python.org/robots.txt")
609 # data1 = r.read()
610 # r.close()
611 # r = o.open(
612 # "ftp://ftp.python.org/pub/www.python.org/2.3.2/announce.txt")
613 # data2 = r.read()
614 # r.close()
615 # self.assert_(data1 != data2)
616
617
618 class CommandFailedError(Exception):
619
620 def __init__(self, message, rc):
621 Exception.__init__(self, message)
622 self.rc = rc
623
624
625 def get_cmd_stdout(args, **kwargs):
626 process = subprocess.Popen(args, stdout=subprocess.PIPE, **kwargs)
627 stdout, stderr = process.communicate()
628 rc = process.returncode
629 if rc != 0:
630 raise CommandFailedError(
631 "Command failed with return code %i: %s:\n%s" %
632 (rc, args, stderr), rc)
633 else:
634 return stdout
635
636
637 def add_to_path(env, name, value):
638 old = env.get(name)
639 if old is not None and old != "":
640 value = old + ":" + value
641 env[name] = value
642
643
644 class CookieJarTests(TestCase):
645
646 def _test_cookiejar(self, make_cookiejar, commit):
647 cookiejar = make_cookiejar()
648 br = self.make_browser()
649 # br.set_debug_http(True)
650 br.set_cookiejar(cookiejar)
651 br.set_handle_refresh(False)
652 url = urljoin(self.uri, "/dynamic")
653 # no cookie was set on the first request
654 html = br.open(url).read()
655 self.assertNotIn(b"Your browser supports cookies!", html)
656 self.assertEqual(len(cookiejar), 2)
657 # ... but now we have the cookie
658 html = br.open(url).read()
659 self.assertIn(b"Your browser supports cookies!", html)
660 self.assertIn(b"Received session cookie", html)
661 commit(cookiejar)
662
663 # should still have the cookie when we load afresh
664 cookiejar = make_cookiejar()
665 br.set_cookiejar(cookiejar)
666 html = br.open(url).read()
667 self.assertIn(b"Your browser supports cookies!", html)
668 self.assertNotIn(b"Received session cookie", html)
669
670 def test_mozilla_cookiejar(self):
671 filename = os.path.join(self.make_temp_dir(), "cookies.txt")
672
673 def make_cookiejar():
674 cj = mechanize.MozillaCookieJar(filename=filename)
675 try:
676 cj.revert()
677 except IOError as exc:
678 if exc.errno != errno.ENOENT:
679 raise
680 return cj
681
682 def commit(cj):
683 cj.save()
684 self._test_cookiejar(make_cookiejar, commit)
685
686
687 class CallbackVerifier:
688 # for .test_urlretrieve()
689
690 def __init__(self, testcase):
691 self._count = 0
692 self._testcase = testcase
693
694 def callback(self, block_nr, block_size, total_size):
695 self._testcase.assertEqual(block_nr, self._count)
696 self._count = self._count + 1
697
698
699 if __name__ == "__main__":
700 unittest.main()