@@ -781,29 +781,14 @@ class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
781
781
class BaseTestInternals :
782
782
_uuid = py_uuid
783
783
784
- def check_parse_mac (self , aix ):
785
- if not aix :
786
- patch = mock .patch .multiple (self .uuid ,
787
- _MAC_DELIM = b':' ,
788
- _MAC_OMITS_LEADING_ZEROES = False )
789
- else :
790
- patch = mock .patch .multiple (self .uuid ,
791
- _MAC_DELIM = b'.' ,
792
- _MAC_OMITS_LEADING_ZEROES = True )
784
+ def check_parse_mac (self , valid_macs , delim = b':' , omits_leading_zeros = False ):
785
+ patch = mock .patch .multiple (self .uuid ,
786
+ _MAC_DELIM = delim ,
787
+ _MAC_OMITS_LEADING_ZEROES = omits_leading_zeros )
793
788
794
789
with patch :
795
790
# Valid MAC addresses
796
- if not aix :
797
- tests = (
798
- (b'52:54:00:9d:0e:67' , 0x5254009d0e67 ),
799
- (b'12:34:56:78:90:ab' , 0x1234567890ab ),
800
- )
801
- else :
802
- # AIX format
803
- tests = (
804
- (b'fe.ad.c.1.23.4' , 0xfead0c012304 ),
805
- )
806
- for mac , expected in tests :
791
+ for mac , expected in valid_macs :
807
792
self .assertEqual (self .uuid ._parse_mac (mac ), expected )
808
793
809
794
# Invalid MAC addresses
@@ -822,16 +807,38 @@ def check_parse_mac(self, aix):
822
807
# dash separator
823
808
b'52-54-00-9d-0e-67' ,
824
809
):
825
- if aix :
826
- mac = mac .replace (b':' , b'.' )
810
+ if delim != b':' :
811
+ mac = mac .replace (b':' , delim )
827
812
with self .subTest (mac = mac ):
828
813
self .assertIsNone (self .uuid ._parse_mac (mac ))
829
814
830
815
def test_parse_mac (self ):
831
- self .check_parse_mac (False )
816
+ self .check_parse_mac (
817
+ valid_macs = (
818
+ (b'52:54:00:9d:0e:67' , 0x5254009d0e67 ),
819
+ (b'12:34:56:78:90:ab' , 0x1234567890ab ),
820
+ ),
821
+ delim = b':' ,
822
+ omits_leading_zeros = False ,
823
+ )
832
824
833
825
def test_parse_mac_aix (self ):
834
- self .check_parse_mac (True )
826
+ self .check_parse_mac (
827
+ valid_macs = (
828
+ (b'fe.ad.c.1.23.4' , 0xfead0c012304 ),
829
+ ),
830
+ delim = b'.' ,
831
+ omits_leading_zeros = True ,
832
+ )
833
+
834
+ def test_parse_mac_macos (self ):
835
+ self .check_parse_mac (
836
+ valid_macs = (
837
+ (b'1:0:5e:0:c:fb' , 0x01005e000cfb ),
838
+ ),
839
+ delim = b':' ,
840
+ omits_leading_zeros = True ,
841
+ )
835
842
836
843
def test_find_under_heading (self ):
837
844
data = '''\
@@ -917,6 +924,25 @@ def test_find_mac_near_keyword(self):
917
924
918
925
self .assertEqual (mac , 0x1234567890ab )
919
926
927
+ def test_find_mac_near_keyword_macos (self ):
928
+ data = '''
929
+ ? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
930
+ '''
931
+
932
+ with mock .patch .multiple (self .uuid ,
933
+ _MAC_DELIM = b':' ,
934
+ _MAC_OMITS_LEADING_ZEROES = True ,
935
+ _get_command_stdout = mock_get_command_stdout (data )):
936
+
937
+ mac = self .uuid ._find_mac_near_keyword (
938
+ command = 'arp' ,
939
+ args = '-an' ,
940
+ keywords = [os .fsencode ('(%s)' % '224.0.0.251' )],
941
+ get_word_index = lambda x : x + 2 ,
942
+ )
943
+
944
+ self .assertEqual (mac , 0x01005e0000fb )
945
+
920
946
def check_node (self , node , requires = None ):
921
947
if requires and node is None :
922
948
self .skipTest ('requires ' + requires )
0 commit comments