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

Method testEnviron

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

Source from the content-addressed store, hash-verified

546 maxDiff = 80 * 50
547
548 def testEnviron(self):
549 os_environ = {
550 # very basic environment
551 'HOME': '/my/home',
552 'PATH': '/my/path',
553 'LANG': 'fr_FR.UTF-8',
554
555 # set some WSGI variables
556 'SCRIPT_NAME': 'test_script_name',
557 'SERVER_NAME': 'test_server_name',
558 }
559
560 with support.swap_attr(TestHandler, 'os_environ', os_environ):
561 # override X and HOME variables
562 handler = TestHandler(X="Y", HOME="/override/home")
563 handler.setup_environ()
564
565 # Check that wsgi_xxx attributes are copied to wsgi.xxx variables
566 # of handler.environ
567 for attr in ('version', 'multithread', 'multiprocess', 'run_once',
568 'file_wrapper'):
569 self.assertEqual(getattr(handler, 'wsgi_' + attr),
570 handler.environ['wsgi.' + attr])
571
572 # Test handler.environ as a dict
573 expected = {}
574 setup_testing_defaults(expected)
575 # Handler inherits os_environ variables which are not overridden
576 # by SimpleHandler.add_cgi_vars() (SimpleHandler.base_env)
577 for key, value in os_environ.items():
578 if key not in expected:
579 expected[key] = value
580 expected.update({
581 # X doesn't exist in os_environ
582 "X": "Y",
583 # HOME is overridden by TestHandler
584 'HOME': "/override/home",
585
586 # overridden by setup_testing_defaults()
587 "SCRIPT_NAME": "",
588 "SERVER_NAME": "127.0.0.1",
589
590 # set by BaseHandler.setup_environ()
591 'wsgi.input': handler.get_stdin(),
592 'wsgi.errors': handler.get_stderr(),
593 'wsgi.version': (1, 0),
594 'wsgi.run_once': False,
595 'wsgi.url_scheme': 'http',
596 'wsgi.multithread': True,
597 'wsgi.multiprocess': True,
598 'wsgi.file_wrapper': util.FileWrapper,
599 })
600 self.assertDictEqual(handler.environ, expected)
601
602 def testCGIEnviron(self):
603 h = BaseCGIHandler(None,None,None,{})

Callers

nothing calls this directly

Calls 9

setup_testing_defaultsFunction · 0.90
assertDictEqualMethod · 0.80
TestHandlerClass · 0.70
setup_environMethod · 0.45
assertEqualMethod · 0.45
itemsMethod · 0.45
updateMethod · 0.45
get_stdinMethod · 0.45
get_stderrMethod · 0.45

Tested by

no test coverage detected