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

Method test_no_home_directory

Lib/test/test_site.py:351–379  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

349
350 @unittest.skipUnless(HAS_USER_SITE, 'need user site')
351 def test_no_home_directory(self):
352 # bpo-10496: getuserbase() and getusersitepackages() must not fail if
353 # the current user has no home directory (if expanduser() returns the
354 # path unchanged).
355 site.USER_SITE = None
356 site.USER_BASE = None
357
358 with EnvironmentVarGuard() as environ, \
359 mock.patch('os.path.expanduser', lambda path: path):
360 environ.unset('PYTHONUSERBASE', 'APPDATA')
361
362 user_base = site.getuserbase()
363 self.assertStartsWith(user_base, '~' + os.sep)
364
365 user_site = site.getusersitepackages()
366 self.assertStartsWith(user_site, user_base)
367
368 with mock.patch('os.path.isdir', return_value=False) as mock_isdir, \
369 mock.patch.object(site, 'addsitedir') as mock_addsitedir, \
370 support.swap_attr(site, 'ENABLE_USER_SITE', True):
371
372 # addusersitepackages() must not add user_site to sys.path
373 # if it is not an existing directory
374 known_paths = set()
375 site.addusersitepackages(known_paths)
376
377 mock_isdir.assert_called_once_with(user_site)
378 mock_addsitedir.assert_not_called()
379 self.assertFalse(known_paths)
380
381 def test_gethistoryfile(self):
382 filename = 'file'

Callers

nothing calls this directly

Calls 7

EnvironmentVarGuardClass · 0.90
setFunction · 0.85
unsetMethod · 0.80
assertStartsWithMethod · 0.80
assert_not_calledMethod · 0.80
assertFalseMethod · 0.80

Tested by

no test coverage detected