Merge branch 'kruton-develop' into develop

Fixes 
This commit is contained in:
ZyX 2014-01-14 23:42:22 +04:00
commit 31f85800b6
2 changed files with 11 additions and 1 deletions
powerline/segments
tests

@ -591,9 +591,12 @@ username = False
_geteuid = getattr(os, 'geteuid', lambda: 1)
def user(pl, segment_info=None):
def user(pl, segment_info=None, hide_user=None):
'''Return the current user.
:param str hide_user:
Omit showing segment for users with names equal to this string.
Highlights the user with the ``superuser`` if the effective user ID is 0.
Highlight groups used: ``superuser`` or ``user``. It is recommended to define all highlight groups.
@ -604,6 +607,8 @@ def user(pl, segment_info=None):
if username is None:
pl.warn('Failed to get username')
return None
if username == hide_user:
return None
euid = _geteuid()
return [{
'contents': username,

@ -73,12 +73,17 @@ class TestCommon(TestCase):
new_psutil = new_module('psutil', Process=lambda pid: Args(username='def'))
pl = Pl()
with replace_env('USER', 'def') as segment_info:
common.username = False
with replace_attr(common, 'os', new_os):
with replace_attr(common, 'psutil', new_psutil):
with replace_attr(common, '_geteuid', lambda: 5):
self.assertEqual(common.user(pl=pl, segment_info=segment_info), [
{'contents': 'def', 'highlight_group': 'user'}
])
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='abc'), [
{'contents': 'def', 'highlight_group': 'user'}
])
self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='def'), None)
with replace_attr(common, '_geteuid', lambda: 0):
self.assertEqual(common.user(pl=pl, segment_info=segment_info), [
{'contents': 'def', 'highlight_group': ['superuser', 'user']}