Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1445387: Set locale fact to Unknown if value cannot be determined #1605

Merged
merged 1 commit into from Apr 25, 2017

Conversation

kahowell
Copy link
Contributor

That is if the language code from getdefaultlocale1 is None, then
special case this as 'Unknown'.

@cnsnyder cnsnyder self-assigned this Apr 25, 2017
@@ -67,7 +67,10 @@ def get_all(self):
host_facts.update(firmware_info_dict)

locale_info = {}
locale_info['system.default_locale'] = ".".join(locale.getdefaultlocale())
effective_locale = 'Unknown'
if locale.getdefaultlocale()[0] is not None:
Copy link
Member

@cnsnyder cnsnyder Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not possible for locale.getdefaultlocale() to return ("Something_not_none", None)?
Perhaps the following to be safe:

if all(local_entry is not None for locale_entry in locale.getdefaultlocale()):
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmmm. Good question actually... I tried

$ LC_ALL=en_us python -c 'import locale; print locale.getdefaultlocale()'
('en_US', 'ISO8859-1')

but lemme code for that just in case...

class HostCollectorTest(unittest.TestCase):

@mock.patch('locale.getdefaultlocale')
def test_unknown_locale(self, mock_locale):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we think it's useful, I would suggest adding one more test for the case of ("Not_None", None) being returned from locale.getdefaultlocale()

That is if the language code from `getdefaultlocale`[1] is `None`, then
special case this as 'Unknown'.

If encoding is `None`, then it won't be included.

[1]: https://docs.python.org/2/library/locale.html#locale.getdefaultlocale
@kahowell
Copy link
Contributor Author

387aef3..9c43204: filter out 'None' encoding (just in case)

Copy link
Member

@cnsnyder cnsnyder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@cnsnyder cnsnyder merged commit a8999e0 into master Apr 25, 2017
@kahowell kahowell deleted the khowell/1445387 branch August 3, 2017 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants