archey4/archey/test/entries/test_archey_user.py
Michael Bromilow 641dcd21ad
Entries: Use __iter__ and __next__ magic methods.
Incl. changed tests where appropriate.
2024-04-08 22:23:10 +01:00

30 lines
735 B
Python

"""Test module for Archey's session user name detection module"""
import unittest
from unittest.mock import patch
from archey.entries.user import User
class TestUserEntry(unittest.TestCase):
"""
For this entry, we'll simply mock `getpass.getuser` call.
If internals happen to fail, `ImportError` might be raised.
"""
@patch(
"archey.entries.user.getpass.getuser",
side_effect=[
"USERNAME",
ImportError("pwd", "Sure, you got a good reason..."),
],
)
def test_getenv(self, _):
"""Simple mock, simple test"""
self.assertEqual(User().value, "USERNAME")
self.assertIsNone(User().value)
if __name__ == "__main__":
unittest.main()