Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
0e32ea10
Kaydet (Commit)
0e32ea10
authored
Ara 15, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #23015: Improved testing of the uuid module.
üst
7bb7793b
79b81738
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
110 deletions
+98
-110
test_uuid.py
Lib/test/test_uuid.py
+98
-110
No files found.
Lib/test/test_uuid.py
Dosyayı görüntüle @
0e32ea10
...
...
@@ -15,9 +15,6 @@ def importable(name):
return
False
class
TestUUID
(
unittest
.
TestCase
):
last_node
=
None
source2node
=
{}
def
test_UUID
(
self
):
equal
=
self
.
assertEqual
ascending
=
[]
...
...
@@ -295,118 +292,13 @@ class TestUUID(unittest.TestCase):
badtype
(
lambda
:
setattr
(
u
,
'clock_seq_low'
,
0
))
badtype
(
lambda
:
setattr
(
u
,
'node'
,
0
))
def
check_node
(
self
,
node
,
source
):
message
=
"
%012
x is not an RFC 4122 node ID"
%
node
self
.
assertTrue
(
0
<
node
,
message
)
self
.
assertTrue
(
node
<
(
1
<<
48
),
message
)
TestUUID
.
source2node
[
source
]
=
node
if
TestUUID
.
last_node
:
if
TestUUID
.
last_node
!=
node
:
msg
=
"different sources disagree on node:
\n
"
for
s
,
n
in
TestUUID
.
source2node
.
items
():
msg
+=
" from source
%
r, node was
%012
x
\n
"
%
(
s
,
n
)
# There's actually no reason to expect the MAC addresses
# to agree across various methods -- e.g., a box may have
# multiple network interfaces, and different ways of getting
# a MAC address may favor different HW.
##self.fail(msg)
else
:
TestUUID
.
last_node
=
node
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_ifconfig_getnode
(
self
):
node
=
uuid
.
_ifconfig_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'ifconfig'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_ip_getnode
(
self
):
node
=
uuid
.
_ip_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'ip'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_arp_getnode
(
self
):
node
=
uuid
.
_arp_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'arp'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_lanscan_getnode
(
self
):
node
=
uuid
.
_lanscan_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'lanscan'
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_netstat_getnode
(
self
):
node
=
uuid
.
_netstat_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'netstat'
)
@unittest.skipUnless
(
os
.
name
==
'nt'
,
'requires Windows'
)
def
test_ipconfig_getnode
(
self
):
node
=
uuid
.
_ipconfig_getnode
()
if
node
is
not
None
:
self
.
check_node
(
node
,
'ipconfig'
)
@unittest.skipUnless
(
importable
(
'win32wnet'
),
'requires win32wnet'
)
@unittest.skipUnless
(
importable
(
'netbios'
),
'requires netbios'
)
def
test_netbios_getnode
(
self
):
self
.
check_node
(
uuid
.
_netbios_getnode
(),
'netbios'
)
def
test_random_getnode
(
self
):
node
=
uuid
.
_random_getnode
()
# Least significant bit of first octet must be set.
self
.
assertTrue
(
node
&
0x010000000000
)
self
.
assertTrue
(
node
<
(
1
<<
48
))
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
@unittest.skipUnless
(
importable
(
'ctypes'
),
'requires ctypes'
)
def
test_unixdll_getnode
(
self
):
try
:
# Issues 1481, 3581: _uuid_generate_time() might be None.
self
.
check_node
(
uuid
.
_unixdll_getnode
(),
'unixdll'
)
except
TypeError
:
pass
@unittest.skipUnless
(
os
.
name
==
'nt'
,
'requires Windows'
)
@unittest.skipUnless
(
importable
(
'ctypes'
),
'requires ctypes'
)
def
test_windll_getnode
(
self
):
self
.
check_node
(
uuid
.
_windll_getnode
(),
'windll'
)
def
test_getnode
(
self
):
node1
=
uuid
.
getnode
()
self
.
check_node
(
node1
,
"getnode1"
)
self
.
assertTrue
(
0
<
node1
<
(
1
<<
48
),
'
%012
x'
%
node1
)
# Test it again to ensure consistency.
node2
=
uuid
.
getnode
()
self
.
check_node
(
node2
,
"getnode2"
)
self
.
assertEqual
(
node1
,
node2
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_find_mac
(
self
):
data
=
'''
fake hwaddr
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
popen
=
unittest
.
mock
.
MagicMock
()
popen
.
stdout
=
io
.
BytesIO
(
data
.
encode
())
with
unittest
.
mock
.
patch
.
object
(
shutil
,
'which'
,
return_value
=
'/sbin/ifconfig'
):
with
unittest
.
mock
.
patch
.
object
(
subprocess
,
'Popen'
,
return_value
=
popen
):
mac
=
uuid
.
_find_mac
(
command
=
'ifconfig'
,
args
=
''
,
hw_identifiers
=
[
b
'hwaddr'
],
get_index
=
lambda
x
:
x
+
1
,
)
self
.
assertEqual
(
mac
,
0x1234567890ab
)
self
.
assertEqual
(
node1
,
node2
,
'
%012
x !=
%012
x'
%
(
node1
,
node2
))
@unittest.skipUnless
(
importable
(
'ctypes'
),
'requires ctypes'
)
def
test_uuid1
(
self
):
...
...
@@ -518,5 +410,101 @@ eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
self
.
assertNotEqual
(
parent_value
,
child_value
)
class
TestInternals
(
unittest
.
TestCase
):
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_find_mac
(
self
):
data
=
'''
fake hwaddr
cscotun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
'''
popen
=
unittest
.
mock
.
MagicMock
()
popen
.
stdout
=
io
.
BytesIO
(
data
.
encode
())
with
unittest
.
mock
.
patch
.
object
(
shutil
,
'which'
,
return_value
=
'/sbin/ifconfig'
):
with
unittest
.
mock
.
patch
.
object
(
subprocess
,
'Popen'
,
return_value
=
popen
):
mac
=
uuid
.
_find_mac
(
command
=
'ifconfig'
,
args
=
''
,
hw_identifiers
=
[
b
'hwaddr'
],
get_index
=
lambda
x
:
x
+
1
,
)
self
.
assertEqual
(
mac
,
0x1234567890ab
)
def
check_node
(
self
,
node
,
requires
=
None
,
network
=
False
):
if
requires
and
node
is
None
:
self
.
skipTest
(
'requires '
+
requires
)
hex
=
'
%012
x'
%
node
if
support
.
verbose
>=
2
:
print
(
hex
,
end
=
' '
)
if
network
:
# 47 bit will never be set in IEEE 802 addresses obtained
# from network cards.
self
.
assertFalse
(
node
&
0x010000000000
,
hex
)
self
.
assertTrue
(
0
<
node
<
(
1
<<
48
),
"
%
s is not an RFC 4122 node ID"
%
hex
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_ifconfig_getnode
(
self
):
node
=
uuid
.
_ifconfig_getnode
()
self
.
check_node
(
node
,
'ifconfig'
,
True
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_ip_getnode
(
self
):
node
=
uuid
.
_ip_getnode
()
self
.
check_node
(
node
,
'ip'
,
True
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_arp_getnode
(
self
):
node
=
uuid
.
_arp_getnode
()
self
.
check_node
(
node
,
'arp'
,
True
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_lanscan_getnode
(
self
):
node
=
uuid
.
_lanscan_getnode
()
self
.
check_node
(
node
,
'lanscan'
,
True
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
def
test_netstat_getnode
(
self
):
node
=
uuid
.
_netstat_getnode
()
self
.
check_node
(
node
,
'netstat'
,
True
)
@unittest.skipUnless
(
os
.
name
==
'nt'
,
'requires Windows'
)
def
test_ipconfig_getnode
(
self
):
node
=
uuid
.
_ipconfig_getnode
()
self
.
check_node
(
node
,
'ipconfig'
,
True
)
@unittest.skipUnless
(
importable
(
'win32wnet'
),
'requires win32wnet'
)
@unittest.skipUnless
(
importable
(
'netbios'
),
'requires netbios'
)
def
test_netbios_getnode
(
self
):
node
=
uuid
.
_netbios_getnode
()
self
.
check_node
(
node
,
network
=
True
)
def
test_random_getnode
(
self
):
node
=
uuid
.
_random_getnode
()
# Least significant bit of first octet must be set.
self
.
assertTrue
(
node
&
0x010000000000
,
'
%012
x'
%
node
)
self
.
check_node
(
node
)
@unittest.skipUnless
(
os
.
name
==
'posix'
,
'requires Posix'
)
@unittest.skipUnless
(
importable
(
'ctypes'
),
'requires ctypes'
)
def
test_unixdll_getnode
(
self
):
try
:
# Issues 1481, 3581: _uuid_generate_time() might be None.
node
=
uuid
.
_unixdll_getnode
()
except
TypeError
:
self
.
skipTest
(
'requires uuid_generate_time'
)
self
.
check_node
(
node
)
@unittest.skipUnless
(
os
.
name
==
'nt'
,
'requires Windows'
)
@unittest.skipUnless
(
importable
(
'ctypes'
),
'requires ctypes'
)
def
test_windll_getnode
(
self
):
node
=
uuid
.
_windll_getnode
()
self
.
check_node
(
node
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment