Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
A
add-trailing-comma
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
add-trailing-comma
Commits
ed302842
Unverified
Kaydet (Commit)
ed302842
authored
Haz 03, 2019
tarafından
Anthony Sottile
Kaydeden (comit)
GitHub
Haz 03, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #75 from theevocater/jakeman/stdin
Add '-' to read from stdin
üst
4dff0db2
5a6c157f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
13 deletions
+38
-13
add_trailing_comma.py
add_trailing_comma.py
+13
-7
requirements-dev.txt
requirements-dev.txt
+1
-0
add_trailing_comma_test.py
tests/add_trailing_comma_test.py
+24
-6
No files found.
add_trailing_comma.py
Dosyayı görüntüle @
ed302842
from
__future__
import
absolute_import
from
__future__
import
print_function
from
__future__
import
unicode_literals
import
argparse
...
...
@@ -405,24 +406,29 @@ def _fix_src(contents_text, py35_plus, py36_plus):
def
fix_file
(
filename
,
args
):
with
open
(
filename
,
'rb'
)
as
f
:
contents_bytes
=
f
.
read
()
if
filename
==
'-'
:
contents_bytes
=
getattr
(
sys
.
stdin
,
'buffer'
,
sys
.
stdin
)
.
read
()
else
:
with
open
(
filename
,
'rb'
)
as
f
:
contents_bytes
=
f
.
read
()
try
:
contents_text_orig
=
contents_text
=
contents_bytes
.
decode
(
'UTF-8'
)
except
UnicodeDecodeError
:
print
(
'{} is non-utf-8 (not supported)'
.
format
(
filename
))
msg
=
'{} is non-utf-8 (not supported)'
.
format
(
filename
)
print
(
msg
,
file
=
sys
.
stderr
)
return
1
contents_text
=
_fix_src
(
contents_text
,
args
.
py35_plus
,
args
.
py36_plus
)
if
contents_text
!=
contents_text_orig
:
print
(
'Rewriting {}'
.
format
(
filename
))
if
filename
==
'-'
:
print
(
contents_text
,
end
=
''
)
elif
contents_text
!=
contents_text_orig
:
print
(
'Rewriting {}'
.
format
(
filename
),
file
=
sys
.
stderr
)
with
io
.
open
(
filename
,
'w'
,
newline
=
''
,
encoding
=
'UTF-8'
)
as
f
:
f
.
write
(
contents_text
)
return
1
return
0
return
contents_text
!=
contents_text_orig
def
main
(
argv
=
None
):
...
...
requirements-dev.txt
Dosyayı görüntüle @
ed302842
coverage
flake8
mock
pre-commit
pytest
tests/add_trailing_comma_test.py
Dosyayı görüntüle @
ed302842
...
...
@@ -3,8 +3,10 @@ from __future__ import absolute_import
from
__future__
import
unicode_literals
import
ast
import
io
import
sys
import
mock
import
pytest
from
add_trailing_comma
import
_fix_src
...
...
@@ -846,8 +848,8 @@ def test_main_changes_a_file(tmpdir, capsys):
f
=
tmpdir
.
join
(
'f.py'
)
f
.
write
(
'x(
\n
1
\n
)
\n
'
)
assert
main
((
f
.
strpath
,))
==
1
out
,
_
=
capsys
.
readouterr
()
assert
out
==
'Rewriting {}
\n
'
.
format
(
f
.
strpath
)
_
,
err
=
capsys
.
readouterr
()
assert
err
==
'Rewriting {}
\n
'
.
format
(
f
.
strpath
)
assert
f
.
read
()
==
'x(
\n
1,
\n
)
\n
'
...
...
@@ -855,8 +857,8 @@ def test_main_preserves_line_endings(tmpdir, capsys):
f
=
tmpdir
.
join
(
'f.py'
)
f
.
write_binary
(
b
'x(
\r\n
1
\r\n
)
\r\n
'
)
assert
main
((
f
.
strpath
,))
==
1
out
,
_
=
capsys
.
readouterr
()
assert
out
==
'Rewriting {}
\n
'
.
format
(
f
.
strpath
)
_
,
err
=
capsys
.
readouterr
()
assert
err
==
'Rewriting {}
\n
'
.
format
(
f
.
strpath
)
assert
f
.
read_binary
()
==
b
'x(
\r\n
1,
\r\n
)
\r\n
'
...
...
@@ -870,8 +872,8 @@ def test_main_non_utf8_bytes(tmpdir, capsys):
f
=
tmpdir
.
join
(
'f.py'
)
f
.
write_binary
(
'# -*- coding: cp1252 -*-
\n
x = €
\n
'
.
encode
(
'cp1252'
))
assert
main
((
f
.
strpath
,))
==
1
out
,
_
=
capsys
.
readouterr
()
assert
out
==
'{} is non-utf-8 (not supported)
\n
'
.
format
(
f
.
strpath
)
_
,
err
=
capsys
.
readouterr
()
assert
err
==
'{} is non-utf-8 (not supported)
\n
'
.
format
(
f
.
strpath
)
def
test_main_py35_plus_argument_star_args
(
tmpdir
):
...
...
@@ -911,3 +913,19 @@ def test_main_py36_plus_function_trailing_commas(
assert
f
.
read
()
==
'def f(
\n
**kwargs
\n
): pass
\n
'
assert
main
((
f
.
strpath
,
'--py36-plus'
))
==
1
assert
f
.
read
()
==
'def f(
\n
**kwargs,
\n
): pass
\n
'
def
test_main_stdin_no_changes
(
capsys
):
stdin
=
io
.
TextIOWrapper
(
io
.
BytesIO
(
b
'x = 5
\n
'
),
'UTF-8'
)
with
mock
.
patch
.
object
(
sys
,
'stdin'
,
stdin
):
assert
main
((
'-'
,))
==
0
out
,
err
=
capsys
.
readouterr
()
assert
out
==
'x = 5
\n
'
def
test_main_stdin_with_changes
(
capsys
):
stdin
=
io
.
TextIOWrapper
(
io
.
BytesIO
(
b
'x(
\n
1
\n
)
\n
'
),
'UTF-8'
)
with
mock
.
patch
.
object
(
sys
,
'stdin'
,
stdin
):
assert
main
((
'-'
,))
==
1
out
,
err
=
capsys
.
readouterr
()
assert
out
==
'x(
\n
1,
\n
)
\n
'
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