facebookarchive / codemod

Codemod is a tool/library to assist you with large-scale codebase refactors that can be partially automated but still require human oversight and occasional intervention. Codemod was developed at Facebook and released as open source.
Apache License 2.0
4.11k stars 198 forks source link

Attempt to fix unicode error when using python3.x to make test happy #104

Closed sbz closed 5 years ago

sbz commented 5 years ago

This PR add the following changes:

Code changes

(codemod-3.6) % codemod -m -d . --editor vim --extensions="py" -i '(extensions)' 'sbz test replace \1'
Resume where you left off, at ./build/lib/codemod/helpers.py:47 (y/n)?  y
Searching for first instance...
Traceback (most recent call last):
  File "/private/tmp/test/bin/codemod", line 11, in <module>
    load_entry_point('codemod==1.0.0', 'console_scripts', 'codemod')()
  File "/private/tmp/test/lib/python3.6/site-packages/codemod-1.0.0-py3.6.egg/codemod/base.py", line 493, in main
    run_interactive(**options)
  File "/private/tmp/test/lib/python3.6/site-packages/codemod-1.0.0-py3.6.egg/codemod/base.py", line 79, in run_interactive
    _ask_about_patch(patch, editor, default_no)
  File "/private/tmp/test/lib/python3.6/site-packages/codemod-1.0.0-py3.6.egg/codemod/base.py", line 252, in _ask_about_patch
    terminal.terminal_clear()
  File "/private/tmp/test/lib/python3.6/site-packages/codemod-1.0.0-py3.6.egg/codemod/terminal_helper.py", line 55, in terminal_clear
    if not _terminal_use_capability('clear'):
  File "/private/tmp/test/lib/python3.6/site-packages/codemod-1.0.0-py3.6.egg/codemod/terminal_helper.py", line 75, in _terminal_use_capability
    sys.stdout.write(unicode(capability, 'ascii'))
NameError: name 'unicode' is not defined

Tests verification should be ok after that change

(codemod-2.7) % make test
py.test --doctest-modules codemod
========================== test session starts  =============
platform darwin -- Python 2.7.14, pytest-3.8.2, py-1.6.0, pluggy-0.7.1
rootdir: /Users/sbrabez/github/codemod, inifile: pytest.ini
collected 18 items

codemod/base.py .                                                                                                                                                                                                                                                        [  5%]
codemod/helpers.py ...                                                                                                                                                                                                                                                   [ 22%]
codemod/patch.py .                                                                                                                                                                                                                                                       [ 27%]
codemod/position.py .                                                                                                                                                                                                                                                    [ 33%]
codemod/query.py ...                                                                                                                                                                                                                                                     [ 50%]
codemod/base.py .                                                                                                                                                                                                                                                        [ 50%]
codemod/helpers.py ...                                                                                                                                                                                                                                                   [ 50%]
codemod/patch.py .                                                                                                                                                                                                                                                       [ 50%]
codemod/position.py .                                                                                                                                                                                                                                                    [ 50%]
codemod/query.py ...

18 passed in 0.12 seconds
(codemod-3.6) % make test
py.test --doctest-modules codemod
========================== test session starts  =============
platform darwin -- Python 3.6.5, pytest-3.8.2, py-1.6.0, pluggy-0.7.1
rootdir: /Users/sbrabez/github/codemod, inifile: pytest.ini
collected 18 items

codemod/base.py .                                                                                                                                                                                                                                                        [  5%]
codemod/helpers.py ...                                                                                                                                                                                                                                                   [ 22%]
codemod/patch.py .                                                                                                                                                                                                                                                       [ 27%]
codemod/position.py .                                                                                                                                                                                                                                                    [ 33%]
codemod/query.py ...                                                                                                                                                                                                                                                     [ 50%]
codemod/base.py .                                                                                                                                                                                                                                                        [ 50%]
codemod/helpers.py ...                                                                                                                                                                                                                                                   [ 50%]
codemod/patch.py .                                                                                                                                                                                                                                                       [ 50%]
codemod/position.py .                                                                                                                                                                                                                                                    [ 50%]
codemod/query.py ...

18 passed in 0.13 seconds

Thank you for this awesome project to help refactoring huge code base!

I hack on this change for Hacktoberfest, please let me know your feedback.

modocache commented 5 years ago

Great, thank you!

sbz commented 5 years ago

@modocache Thank you for merging! It looks like the travis ci integration was disabled for facebook/codemod, so I run a build against my fork sbz/codemod rebased on master. Everything is fine as expected according the build logs \o/