MCPcopy Index your code
hub / github.com/python/cpython / testContentLength

Method testContentLength

Lib/test/test_wsgiref.py:622–670  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

620 self.assertRaises(NotImplementedError, h._write, "test")
621
622 def testContentLength(self):
623 # Demo one reason iteration is better than write()... ;)
624
625 def trivial_app1(e,s):
626 s('200 OK',[])
627 return [e['wsgi.url_scheme'].encode('iso-8859-1')]
628
629 def trivial_app2(e,s):
630 s('200 OK',[])(e['wsgi.url_scheme'].encode('iso-8859-1'))
631 return []
632
633 def trivial_app3(e,s):
634 s('200 OK',[])
635 return ['\u0442\u0435\u0441\u0442'.encode("utf-8")]
636
637 def trivial_app4(e,s):
638 # Simulate a response to a HEAD request
639 s('200 OK',[('Content-Length', '12345')])
640 return []
641
642 h = TestHandler()
643 h.run(trivial_app1)
644 self.assertEqual(h.stdout.getvalue(),
645 ("Status: 200 OK\r\n"
646 "Content-Length: 4\r\n"
647 "\r\n"
648 "http").encode("iso-8859-1"))
649
650 h = TestHandler()
651 h.run(trivial_app2)
652 self.assertEqual(h.stdout.getvalue(),
653 ("Status: 200 OK\r\n"
654 "\r\n"
655 "http").encode("iso-8859-1"))
656
657 h = TestHandler()
658 h.run(trivial_app3)
659 self.assertEqual(h.stdout.getvalue(),
660 b'Status: 200 OK\r\n'
661 b'Content-Length: 8\r\n'
662 b'\r\n'
663 b'\xd1\x82\xd0\xb5\xd1\x81\xd1\x82')
664
665 h = TestHandler()
666 h.run(trivial_app4)
667 self.assertEqual(h.stdout.getvalue(),
668 b'Status: 200 OK\r\n'
669 b'Content-Length: 12345\r\n'
670 b'\r\n')
671
672 def testBasicErrorOutput(self):
673

Callers

nothing calls this directly

Calls 5

TestHandlerClass · 0.70
runMethod · 0.45
assertEqualMethod · 0.45
getvalueMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected