python中base属性_Python install.USER_BASE属性代码示例

# 需要导入模块: from distutils.command import install [as 别名]

# 或者: from distutils.command.install import USER_BASE [as 别名]

def test_user_site(self):

# site.USER_SITE was introduced in 2.6

if sys.version < '2.6':

return

# preparing the environment for the test

self.old_user_base = site.USER_BASE

self.old_user_site = site.USER_SITE

self.tmpdir = self.mkdtemp()

self.user_base = os.path.join(self.tmpdir, 'B')

self.user_site = os.path.join(self.tmpdir, 'S')

site.USER_BASE = self.user_base

site.USER_SITE = self.user_site

install_module.USER_BASE = self.user_base

install_module.USER_SITE = self.user_site

def _expanduser(path):

return self.tmpdir

self.old_expand = os.path.expanduser

os.path.expanduser = _expanduser

def cleanup():

site.USER_BASE = self.old_user_base

site.USER_SITE = self.old_user_site

install_module.USER_BASE = self.old_user_base

install_module.USER_SITE = self.old_user_site

os.path.expanduser = self.old_expand

self.addCleanup(cleanup)

for key in ('nt_user', 'unix_user', 'os2_home'):

self.assertIn(key, INSTALL_SCHEMES)

dist = Distribution({'name': 'xx'})

cmd = install(dist)

# making sure the user option is there

options = [name for name, short, lable in

cmd.user_options]

self.assertIn('user', options)

# setting a value

cmd.user = 1

# user base and site shouldn't be created yet

self.assertFalse(os.path.exists(self.user_base))

self.assertFalse(os.path.exists(self.user_site))

# let's run finalize

cmd.ensure_finalized()

# now they should

self.assertTrue(os.path.exists(self.user_base))

self.assertTrue(os.path.exists(self.user_site))

self.assertIn('userbase', cmd.config_vars)

self.assertIn('usersite', cmd.config_vars)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值