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
7c08b19f
Kaydet (Commit)
7c08b19f
authored
Agu 22, 2014
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #19714: Tests for importlib.machinery.WindowsRegistryFinder.
Patch by Claudiu Popa, review by Martin v. Löwis.
üst
f499931b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
2 deletions
+63
-2
test_windows.py
Lib/test/test_importlib/test_windows.py
+63
-2
No files found.
Lib/test/test_importlib/test_windows.py
Dosyayı görüntüle @
7c08b19f
from
.
import
util
as
test_util
machinery
=
test_util
.
import_importlib
(
'importlib.machinery'
)
import
os
import
sys
import
unittest
from
test
import
support
from
contextlib
import
contextmanager
from
.util
import
temp_module
support
.
import_module
(
'winreg'
,
required_on
=
[
'win'
])
from
winreg
import
(
CreateKey
,
HKEY_CURRENT_USER
,
SetValue
,
REG_SZ
,
KEY_ALL_ACCESS
,
EnumKey
,
CloseKey
,
DeleteKey
,
OpenKey
)
def
delete_registry_tree
(
root
,
subkey
):
try
:
hkey
=
OpenKey
(
root
,
subkey
,
access
=
KEY_ALL_ACCESS
)
except
OSError
:
# subkey does not exist
return
while
True
:
try
:
subsubkey
=
EnumKey
(
hkey
,
0
)
except
OSError
:
# no more subkeys
break
delete_registry_tree
(
hkey
,
subsubkey
)
CloseKey
(
hkey
)
DeleteKey
(
root
,
subkey
)
@contextmanager
def
setup_module
(
machinery
,
name
,
path
=
None
):
if
machinery
.
WindowsRegistryFinder
.
DEBUG_BUILD
:
root
=
machinery
.
WindowsRegistryFinder
.
REGISTRY_KEY_DEBUG
else
:
root
=
machinery
.
WindowsRegistryFinder
.
REGISTRY_KEY
key
=
root
.
format
(
fullname
=
name
,
sys_version
=
sys
.
version
[:
3
])
try
:
with
temp_module
(
name
,
"a = 1"
)
as
location
:
subkey
=
CreateKey
(
HKEY_CURRENT_USER
,
key
)
if
path
is
None
:
path
=
location
+
".py"
SetValue
(
subkey
,
""
,
REG_SZ
,
path
)
yield
finally
:
if
machinery
.
WindowsRegistryFinder
.
DEBUG_BUILD
:
key
=
os
.
path
.
dirname
(
key
)
delete_registry_tree
(
HKEY_CURRENT_USER
,
key
)
@unittest.skipUnless
(
sys
.
platform
.
startswith
(
'win'
),
'requires Windows'
)
class
WindowsRegistryFinderTests
:
# XXX Need a test that finds the spec via the registry.
# The module name is process-specific, allowing for
# simultaneous runs of the same test on a single machine.
test_module
=
"spamham{}"
.
format
(
os
.
getpid
())
def
test_find_spec_missing
(
self
):
spec
=
self
.
machinery
.
WindowsRegistryFinder
.
find_spec
(
'spam'
)
...
...
@@ -18,6 +66,19 @@ class WindowsRegistryFinderTests:
loader
=
self
.
machinery
.
WindowsRegistryFinder
.
find_module
(
'spam'
)
self
.
assertIs
(
loader
,
None
)
def
test_module_found
(
self
):
with
setup_module
(
self
.
machinery
,
self
.
test_module
):
loader
=
self
.
machinery
.
WindowsRegistryFinder
.
find_module
(
self
.
test_module
)
spec
=
self
.
machinery
.
WindowsRegistryFinder
.
find_spec
(
self
.
test_module
)
self
.
assertIsNot
(
loader
,
None
)
self
.
assertIsNot
(
spec
,
None
)
def
test_module_not_found
(
self
):
with
setup_module
(
self
.
machinery
,
self
.
test_module
,
path
=
"."
):
loader
=
self
.
machinery
.
WindowsRegistryFinder
.
find_module
(
self
.
test_module
)
spec
=
self
.
machinery
.
WindowsRegistryFinder
.
find_spec
(
self
.
test_module
)
self
.
assertIsNone
(
loader
)
self
.
assertIsNone
(
spec
)
(
Frozen_WindowsRegistryFinderTests
,
Source_WindowsRegistryFinderTests
...
...
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