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
4b965f6a
Kaydet (Commit)
4b965f6a
authored
Nis 26, 2009
tarafından
Walter Dörwald
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
üst
e73cbe7a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
56 deletions
+36
-56
test_optparse.py
Lib/test/test_optparse.py
+4
-16
test_posixpath.py
Lib/test/test_posixpath.py
+3
-4
test_site.py
Lib/test/test_site.py
+1
-1
test_tempfile.py
Lib/test/test_tempfile.py
+2
-7
test_urllib.py
Lib/test/test_urllib.py
+8
-8
test_xmlrpc.py
Lib/test/test_xmlrpc.py
+18
-20
No files found.
Lib/test/test_optparse.py
Dosyayı görüntüle @
4b965f6a
...
...
@@ -1464,15 +1464,9 @@ class TestHelp(BaseTest):
# we must restore its original value -- otherwise, this test
# screws things up for other tests when it's part of the Python
# test suite.
orig_columns
=
os
.
environ
.
get
(
'COLUMNS'
)
os
.
environ
[
'COLUMNS'
]
=
str
(
columns
)
try
:
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
set
(
'COLUMNS'
,
str
(
columns
))
return
InterceptingOptionParser
(
option_list
=
options
)
finally
:
if
orig_columns
is
None
:
del
os
.
environ
[
'COLUMNS'
]
else
:
os
.
environ
[
'COLUMNS'
]
=
orig_columns
def
assertHelpEquals
(
self
,
expected_output
):
if
type
(
expected_output
)
is
types
.
UnicodeType
:
...
...
@@ -1499,16 +1493,10 @@ class TestHelp(BaseTest):
self
.
assertHelpEquals
(
_expected_help_long_opts_first
)
def
test_help_title_formatter
(
self
):
save
=
os
.
environ
.
get
(
"COLUMNS"
)
try
:
os
.
environ
[
"COLUMNS"
]
=
"80"
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
set
(
"COLUMNS"
,
"80"
)
self
.
parser
.
formatter
=
TitledHelpFormatter
()
self
.
assertHelpEquals
(
_expected_help_title_formatter
)
finally
:
if
save
is
not
None
:
os
.
environ
[
"COLUMNS"
]
=
save
else
:
del
os
.
environ
[
"COLUMNS"
]
def
test_wrap_columns
(
self
):
# Ensure that wrapping respects $COLUMNS environment variable.
...
...
Lib/test/test_posixpath.py
Dosyayı görüntüle @
4b965f6a
...
...
@@ -345,10 +345,9 @@ class PosixPathTest(unittest.TestCase):
self
.
assert_
(
isinstance
(
posixpath
.
expanduser
(
"~root/"
),
basestring
))
self
.
assert_
(
isinstance
(
posixpath
.
expanduser
(
"~foo/"
),
basestring
))
orig_home
=
os
.
environ
[
'HOME'
]
os
.
environ
[
'HOME'
]
=
'/'
self
.
assertEqual
(
posixpath
.
expanduser
(
"~"
),
"/"
)
os
.
environ
[
'HOME'
]
=
orig_home
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
set
(
'HOME'
,
'/'
)
self
.
assertEqual
(
posixpath
.
expanduser
(
"~"
),
"/"
)
self
.
assertRaises
(
TypeError
,
posixpath
.
expanduser
)
...
...
Lib/test/test_site.py
Dosyayı görüntüle @
4b965f6a
...
...
@@ -5,7 +5,7 @@ executing have not been removed.
"""
import
unittest
from
test.test_support
import
run_unittest
,
TESTFN
from
test.test_support
import
run_unittest
,
TESTFN
,
EnvironmentVarGuard
import
__builtin__
import
os
import
sys
...
...
Lib/test/test_tempfile.py
Dosyayı görüntüle @
4b965f6a
...
...
@@ -149,13 +149,11 @@ class test__candidate_tempdir_list(TC):
# _candidate_tempdir_list contains the expected directories
# Make sure the interesting environment variables are all set.
added
=
[]
try
:
with
test_support
.
EnvironmentVarGuard
()
as
env
:
for
envname
in
'TMPDIR'
,
'TEMP'
,
'TMP'
:
dirname
=
os
.
getenv
(
envname
)
if
not
dirname
:
os
.
environ
[
envname
]
=
os
.
path
.
abspath
(
envname
)
added
.
append
(
envname
)
env
.
set
(
envname
,
os
.
path
.
abspath
(
envname
))
cand
=
tempfile
.
_candidate_tempdir_list
()
...
...
@@ -173,9 +171,6 @@ class test__candidate_tempdir_list(TC):
# Not practical to try to verify the presence of OS-specific
# paths in this list.
finally
:
for
p
in
added
:
del
os
.
environ
[
p
]
test_classes
.
append
(
test__candidate_tempdir_list
)
...
...
Lib/test/test_urllib.py
Dosyayı görüntüle @
4b965f6a
...
...
@@ -98,20 +98,20 @@ class urlopen_FileTests(unittest.TestCase):
class
ProxyTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
# Save all proxy related env vars
self
.
_saved_environ
=
dict
([(
k
,
v
)
for
k
,
v
in
os
.
environ
.
iteritems
()
if
k
.
lower
()
.
find
(
'proxy'
)
>=
0
])
# Records changes to env vars
self
.
env
=
test_support
.
EnvironmentVarGuard
()
# Delete all proxy related env vars
for
k
in
self
.
_saved_environ
:
del
os
.
environ
[
k
]
for
k
,
v
in
os
.
environ
.
iteritems
():
if
'proxy'
in
k
.
lower
():
env
.
unset
(
k
)
def
tearDown
(
self
):
# Restore all proxy related env vars
for
k
,
v
in
self
.
_saved_environ
.
iteritems
():
os
.
environ
[
k
]
=
v
self
.
env
.
__exit__
()
del
self
.
en
v
def
test_getproxies_environment_keep_no_proxies
(
self
):
os
.
environ
[
'NO_PROXY'
]
=
'localhost'
self
.
env
.
set
(
'NO_PROXY'
,
'localhost'
)
proxies
=
urllib
.
getproxies_environment
()
# getproxies_environment use lowered case truncated (no '_proxy') keys
self
.
assertEquals
(
'localhost'
,
proxies
[
'no'
])
...
...
Lib/test/test_xmlrpc.py
Dosyayı görüntüle @
4b965f6a
...
...
@@ -604,25 +604,25 @@ class CGIHandlerTestCase(unittest.TestCase):
self
.
cgi
=
None
def
test_cgi_get
(
self
):
os
.
environ
[
'REQUEST_METHOD'
]
=
'GET'
# if the method is GET and no request_text is given, it runs handle_get
# get sysout output
tmp
=
sys
.
stdout
sys
.
stdout
=
open
(
test_support
.
TESTFN
,
"w"
)
self
.
cgi
.
handle_request
()
sys
.
stdout
.
close
()
sys
.
stdout
=
tmp
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
set
(
'REQUEST_METHOD'
,
'GET'
)
# if the method is GET and no request_text is given, it runs handle_get
# get sysout output
tmp
=
sys
.
stdout
sys
.
stdout
=
open
(
test_support
.
TESTFN
,
"w"
)
self
.
cgi
.
handle_request
()
sys
.
stdout
.
close
()
sys
.
stdout
=
tmp
# parse Status header
handle
=
open
(
test_support
.
TESTFN
,
"r"
)
.
read
()
status
=
handle
.
split
()[
1
]
message
=
' '
.
join
(
handle
.
split
()[
2
:
4
])
# parse Status header
handle
=
open
(
test_support
.
TESTFN
,
"r"
)
.
read
()
status
=
handle
.
split
()[
1
]
message
=
' '
.
join
(
handle
.
split
()[
2
:
4
])
self
.
assertEqual
(
status
,
'400'
)
self
.
assertEqual
(
message
,
'Bad Request'
)
self
.
assertEqual
(
status
,
'400'
)
self
.
assertEqual
(
message
,
'Bad Request'
)
os
.
remove
(
test_support
.
TESTFN
)
os
.
environ
[
'REQUEST_METHOD'
]
=
''
os
.
remove
(
test_support
.
TESTFN
)
def
test_cgi_xmlrpc_response
(
self
):
data
=
"""<?xml version='1.0'?>
...
...
@@ -645,11 +645,9 @@ class CGIHandlerTestCase(unittest.TestCase):
sys
.
stdin
=
open
(
"xmldata.txt"
,
"r"
)
sys
.
stdout
=
open
(
test_support
.
TESTFN
,
"w"
)
os
.
environ
[
'CONTENT_LENGTH'
]
=
str
(
len
(
data
))
try
:
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
set
(
'CONTENT_LENGTH'
,
str
(
len
(
data
)))
self
.
cgi
.
handle_request
()
finally
:
del
os
.
environ
[
'CONTENT_LENGTH'
]
sys
.
stdin
.
close
()
sys
.
stdout
.
close
()
...
...
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