MCPcopy Index your code
hub / github.com/RustPython/RustPython / testEnviron

Method testEnviron

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

setup_testing_defaultsFunction · 0.90
getattrFunction · 0.85
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