MCPcopy Create free account
hub / github.com/RustPython/RustPython / test_no_home_directory

Method test_no_home_directory

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

EnvironmentVarGuardClass · 0.90
setFunction · 0.85
unsetMethod · 0.80
assertTrueMethod · 0.80
assert_not_calledMethod · 0.80
assertFalseMethod · 0.80
startswithMethod · 0.45

Tested by

no test coverage detected