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
d30829de
Kaydet (Commit)
d30829de
authored
Nis 24, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #26801: shutil.get_terminal_size() now handles the case of stdout is
reopened on Windows. Added tests for fallbacks.
üst
e37fc18b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletion
+32
-1
shutil.py
Lib/shutil.py
+3
-1
test_shutil.py
Lib/test/test_shutil.py
+29
-0
No files found.
Lib/shutil.py
Dosyayı görüntüle @
d30829de
...
...
@@ -1069,7 +1069,9 @@ def get_terminal_size(fallback=(80, 24)):
if
columns
<=
0
or
lines
<=
0
:
try
:
size
=
os
.
get_terminal_size
(
sys
.
__stdout__
.
fileno
())
except
(
AttributeError
,
OSError
):
except
(
AttributeError
,
ValueError
,
OSError
):
# stdout is None, closed, detached, or not a terminal, or
# os.get_terminal_size() is unsupported
size
=
os
.
terminal_size
(
fallback
)
if
columns
<=
0
:
columns
=
size
.
columns
...
...
Lib/test/test_shutil.py
Dosyayı görüntüle @
d30829de
...
...
@@ -1828,14 +1828,24 @@ class TermsizeTests(unittest.TestCase):
with
support
.
EnvironmentVarGuard
()
as
env
:
env
[
'COLUMNS'
]
=
'777'
del
env
[
'LINES'
]
size
=
shutil
.
get_terminal_size
()
self
.
assertEqual
(
size
.
columns
,
777
)
with
support
.
EnvironmentVarGuard
()
as
env
:
del
env
[
'COLUMNS'
]
env
[
'LINES'
]
=
'888'
size
=
shutil
.
get_terminal_size
()
self
.
assertEqual
(
size
.
lines
,
888
)
def
test_bad_environ
(
self
):
with
support
.
EnvironmentVarGuard
()
as
env
:
env
[
'COLUMNS'
]
=
'xxx'
env
[
'LINES'
]
=
'yyy'
size
=
shutil
.
get_terminal_size
()
self
.
assertGreaterEqual
(
size
.
columns
,
0
)
self
.
assertGreaterEqual
(
size
.
lines
,
0
)
@unittest.skipUnless
(
os
.
isatty
(
sys
.
__stdout__
.
fileno
()),
"not on tty"
)
@unittest.skipUnless
(
hasattr
(
os
,
'get_terminal_size'
),
'need os.get_terminal_size()'
)
...
...
@@ -1859,6 +1869,25 @@ class TermsizeTests(unittest.TestCase):
self
.
assertEqual
(
expected
,
actual
)
def
test_fallback
(
self
):
with
support
.
EnvironmentVarGuard
()
as
env
:
del
env
[
'LINES'
]
del
env
[
'COLUMNS'
]
# sys.__stdout__ has no fileno()
with
support
.
swap_attr
(
sys
,
'__stdout__'
,
None
):
size
=
shutil
.
get_terminal_size
(
fallback
=
(
10
,
20
))
self
.
assertEqual
(
size
.
columns
,
10
)
self
.
assertEqual
(
size
.
lines
,
20
)
# sys.__stdout__ is not a terminal on Unix
# or fileno() not in (0, 1, 2) on Windows
with
open
(
os
.
devnull
,
'w'
)
as
f
,
\
support
.
swap_attr
(
sys
,
'__stdout__'
,
f
):
size
=
shutil
.
get_terminal_size
(
fallback
=
(
30
,
40
))
self
.
assertEqual
(
size
.
columns
,
30
)
self
.
assertEqual
(
size
.
lines
,
40
)
class
PublicAPITests
(
unittest
.
TestCase
):
"""Ensures that the correct values are exposed in the public API."""
...
...
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