mirror of
https://github.com/HorlogeSkynet/archey4
synced 2024-12-29 16:00:17 +01:00
39 lines
963 B
Python
39 lines
963 B
Python
"""Test module for Archey's device host-name detection module"""
|
|
|
|
import unittest
|
|
from unittest.mock import mock_open, patch
|
|
|
|
from archey.entries.hostname import Hostname
|
|
|
|
|
|
class TestHostnameEntry(unittest.TestCase):
|
|
"""Test cases mocking for `/etc/hostname` file and `platform.node` call"""
|
|
|
|
@patch(
|
|
"archey.entries.hostname.open",
|
|
mock_open(
|
|
read_data="""\
|
|
MY-COOL-LAPTOP
|
|
"""
|
|
),
|
|
)
|
|
def test_etc_hostname(self):
|
|
"""Mock reading from `/etc/hostname`"""
|
|
self.assertEqual(Hostname().value, "MY-COOL-LAPTOP")
|
|
|
|
@patch(
|
|
"archey.entries.hostname.open",
|
|
side_effect=FileNotFoundError(),
|
|
)
|
|
@patch(
|
|
"archey.entries.hostname.platform.node",
|
|
return_value="MY-COOL-LAPTOP",
|
|
)
|
|
def test_hostname(self, _, __):
|
|
"""Mock call to `hostname`"""
|
|
self.assertEqual(Hostname().value, "MY-COOL-LAPTOP")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|