diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c22f00..662f9b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,13 @@ * Minor releases (X.1.X) are new features such as added functions or small changes that don't cause major compatibility issues. * Major releases (1.X.X) are major new features or changes that break backward compatibility in a big way. -## [Latest](https://github.com/int-brain-lab/iblutil/commits/main) [1.12.0] +## [Latest](https://github.com/int-brain-lab/iblutil/commits/main) [1.12.1] + +### Modified + +- Moved get_mac() to util + +## [1.12.0] ### Added diff --git a/iblutil/__init__.py b/iblutil/__init__.py index 666b2f7..fe70fa2 100644 --- a/iblutil/__init__.py +++ b/iblutil/__init__.py @@ -1 +1 @@ -__version__ = '1.12.0' +__version__ = '1.12.1' diff --git a/iblutil/io/net/base.py b/iblutil/io/net/base.py index 69aad14..2ef1d49 100644 --- a/iblutil/io/net/base.py +++ b/iblutil/io/net/base.py @@ -2,7 +2,6 @@ import re import json import socket -import uuid import warnings import logging from asyncio import isfuture @@ -37,20 +36,6 @@ def external_ip(): return ipaddress.ip_address(urllib.request.urlopen('https://ident.me').read().decode('utf8')) -def get_mac() -> str: - """ - Fetch the machine's unique MAC address formatted according to IEEE 802 specifications. - - Returns - ------- - str - The MAC address of the device formatted in six groups of two - hexadecimal digits separated by hyphens in transmission order - (e.g., 'BA-DB-AD-C0-FF-EE'). - """ - return uuid.getnode().to_bytes(6, 'big').hex('-').upper() - - def is_valid_ip(ip_address) -> bool: """ Test whether IP address is valid. diff --git a/iblutil/util.py b/iblutil/util.py index e84c030..c18b20b 100644 --- a/iblutil/util.py +++ b/iblutil/util.py @@ -1,3 +1,4 @@ +import uuid from itertools import takewhile from os import scandir from pathlib import Path @@ -283,3 +284,17 @@ def dir_size(directory: Union[str, Path], follow_symlinks: bool = False) -> int: elif entry.is_file(): total_bytes += entry.stat().st_size return total_bytes + + +def get_mac() -> str: + """ + Fetch the machine's unique MAC address formatted according to IEEE 802 specifications. + + Returns + ------- + str + The MAC address of the device formatted in six groups of two + hexadecimal digits separated by hyphens in transmission order + (e.g., 'BA-DB-AD-C0-FF-EE'). + """ + return uuid.getnode().to_bytes(6, 'big').hex('-').upper() diff --git a/tests/test_net.py b/tests/test_net.py index 77f1c96..5c01758 100644 --- a/tests/test_net.py +++ b/tests/test_net.py @@ -1,4 +1,3 @@ -from unittest.mock import patch import sys import asyncio import logging @@ -10,7 +9,6 @@ from datetime import date from iblutil.io.net import base, app -from iblutil.io.net.base import get_mac ver = (getattr(sys.version_info, v) for v in ('major', 'minor', 'micro')) ver = Version('.'.join(map(str, ver))) @@ -51,10 +49,6 @@ def test_external_ip(self): """Test for external_ip""" self.assertFalse(ipaddress.ip_address(base.external_ip()).is_private) - def test_get_mac(self): - with patch('iblutil.io.net.base.uuid.getnode', return_value=205452675710958): - self.assertEqual(get_mac(), 'BA-DB-AD-C0-FF-EE') - def test_ExpMessage(self): """Test for ExpMessage.validate method.""" # Check identity diff --git a/tests/test_util.py b/tests/test_util.py index b58bda6..50de94f 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -3,6 +3,7 @@ from pathlib import Path import tempfile import logging +from unittest.mock import patch import numpy as np @@ -202,5 +203,12 @@ def test_dir_size(self): self.assertEqual(util.dir_size(dir1, True), expected + file1.stat().st_size) +class TestGetMac(unittest.TestCase): + + def test_get_mac(self): + with patch('iblutil.util.uuid.getnode', return_value=205452675710958): + self.assertEqual(util.get_mac(), 'BA-DB-AD-C0-FF-EE') + + if __name__ == '__main__': unittest.main(exit=False)