Skip to content

Commit

Permalink
chore: Replace usage of .format() for f-strings in title.py to impr…
Browse files Browse the repository at this point in the history
…ove readability

PiperOrigin-RevId: 386271258
  • Loading branch information
TsekNet authored and copybara-github committed Jul 22, 2021
1 parent 748a094 commit 4952391
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions glazier/lib/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def set_title(string: Optional[str] = None) -> str:
"""
title = _build_title(string)
try:
os.system('title {}'.format(title))
os.system(f'title {title}')
logging.debug('Set console title: %s', title)
return title
except OSError as e:
raise Error('Failed to set console title: {}'.format(str(e)))
raise Error(f'Failed to set console title: {str(e)}')
35 changes: 14 additions & 21 deletions glazier/lib/title_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def test_base_title_all(self, wpe, stage, release, ii):
title.constants.FLAGS.config_root_path = '/some/directory'
self.assertEqual(
title._base_title(),
'WinPE - some/directory - Stage: {} - {} - {}'.format(
_STAGE, _RELEASE, _TEST_ID))
f'WinPE - some/directory - Stage: {_STAGE} - {_RELEASE} - {_TEST_ID}')

@mock.patch.object(title.buildinfo.BuildInfo, 'ImageID', autospec=True)
@mock.patch.object(title.buildinfo.BuildInfo, 'Release', autospec=True)
Expand Down Expand Up @@ -94,21 +93,18 @@ def test_build_title_prefix(self, bt):
@mock.patch.object(title, '_base_title', autospec=True)
def test_build_title_string(self, bt):
bt.return_value = ''
self.assertEqual(
title._build_title(_STRING), '{0} [{1}]'.format(_PREFIX, _STRING))
self.assertEqual(title._build_title(_STRING), f'{_PREFIX} [{_STRING}]')

@mock.patch.object(title, '_base_title', autospec=True)
def test_build_title_string_base(self, bt):
bt.return_value = _TEST_ID
self.assertEqual(
title._build_title(_STRING),
'{0} [{1} - {2}]'.format(_PREFIX, _STRING, _TEST_ID))
title._build_title(_STRING), f'{_PREFIX} [{_STRING} - {_TEST_ID}]')

@mock.patch.object(title, '_base_title', autospec=True)
def test_build_title_base(self, bt):
bt.return_value = _TEST_ID
self.assertEqual(title._build_title(),
'{0} [{1}]'.format(_PREFIX, _TEST_ID))
self.assertEqual(title._build_title(), f'{_PREFIX} [{_TEST_ID}]')

@mock.patch.object(title.os, 'system', autospec=True)
@mock.patch.object(title.buildinfo.BuildInfo, 'ImageID', autospec=True)
Expand All @@ -119,10 +115,8 @@ def test_set_title_string(self, wpe, release, ii, sys):
ii.return_value = _TEST_ID
release.return_value = None
self.assertEqual(
title.set_title(_STRING),
'{0} [{1} - {2}]'.format(_PREFIX, _STRING, _TEST_ID))
sys.assert_called_with('title {0} [{1} - {2}]'.format(
_PREFIX, _STRING, _TEST_ID))
title.set_title(_STRING), f'{_PREFIX} [{_STRING} - {_TEST_ID}]')
sys.assert_called_with(f'title {_PREFIX} [{_STRING} - {_TEST_ID}]')

@mock.patch.object(title.os, 'system', autospec=True)
@mock.patch.object(title.buildinfo.BuildInfo, 'ImageID', autospec=True)
Expand All @@ -134,9 +128,8 @@ def test_set_title_stage(self, wpe, stage, release, ii, sys):
ii.return_value = None
stage.return_value = _STAGE
release.return_value = None
self.assertEqual(title.set_title(),
'{0} [Stage: {1}]'.format(_PREFIX, _STAGE))
sys.assert_called_with('title {0} [Stage: {1}]'.format(_PREFIX, _STAGE))
self.assertEqual(title.set_title(), f'{_PREFIX} [Stage: {_STAGE}]')
sys.assert_called_with(f'title {_PREFIX} [Stage: {_STAGE}]')

@mock.patch.object(title.os, 'system', autospec=True)
@mock.patch.object(title.buildinfo.BuildInfo, 'ImageID', autospec=True)
Expand All @@ -146,22 +139,22 @@ def test_set_title_release(self, wpe, release, ii, sys):
wpe.return_value = False
ii.return_value = None
release.return_value = _RELEASE
self.assertEqual(title.set_title(), '{0} [{1}]'.format(_PREFIX, _RELEASE))
sys.assert_called_with('title {0} [{1}]'.format(_PREFIX, _RELEASE))
self.assertEqual(title.set_title(), f'{_PREFIX} [{_RELEASE}]')
sys.assert_called_with(f'title {_PREFIX} [{_RELEASE}]')

@mock.patch.object(title.os, 'system', autospec=True)
@mock.patch.object(title, '_build_title', autospec=True)
def test_set_title_base(self, bt, sys):
bt.return_value = '{0} [{1}]'.format(_PREFIX, _TEST_ID)
self.assertEqual(title.set_title(), '{0} [{1}]'.format(_PREFIX, _TEST_ID))
sys.assert_called_with('title {0} [{1}]'.format(_PREFIX, _TEST_ID))
bt.return_value = f'{_PREFIX} [{_TEST_ID}]'
self.assertEqual(title.set_title(), f'{_PREFIX} [{_TEST_ID}]')
sys.assert_called_with(f'title {_PREFIX} [{_TEST_ID}]')

@mock.patch.object(title.os, 'system', autospec=True)
@mock.patch.object(title, '_build_title', autospec=True)
def test_set_title_prefix(self, bt, sys):
bt.return_value = _PREFIX
self.assertEqual(title.set_title(), _PREFIX)
sys.assert_called_with('title {}'.format(_PREFIX))
sys.assert_called_with(f'title {_PREFIX}')

@mock.patch.object(title.os, 'system', autospec=True)
@mock.patch.object(title, '_build_title', autospec=True)
Expand Down

0 comments on commit 4952391

Please sign in to comment.