##// END OF EJS Templates
issue6528: add a config option to control the fixing on the fly...
issue6528: add a config option to control the fixing on the fly This will allow people who know to be safe to avoid any performance overhead (and other potential issue). Differential Revision: https://phab.mercurial-scm.org/D11271

File last commit:

r43798:3a463e5e default
r48630:2813d406 5.9rc1 stable
Show More
test-byteify-strings.t
266 lines | 5.5 KiB | text/troff | Tads3Lexer
/ tests / test-byteify-strings.t
Ian Moody
contrib: require Python 3.7 for byteify-strings.py...
r43725 #require py37
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913
$ byteify_strings () {
Matt Harbison
tests: quote $PYTHON in test-byteify-strings.t...
r43798 > "$PYTHON" "$TESTDIR/../contrib/byteify-strings.py" "$@"
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 > }
Raphaël Gomès
byteify-strings: add --version argument...
r42929 Test version
$ byteify_strings --version
Byteify strings * (glob)
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 Test in-place
$ cat > testfile.py <<EOF
> obj['test'] = b"1234"
> mydict.iteritems()
> EOF
$ byteify_strings testfile.py -i
$ cat testfile.py
obj[b'test'] = b"1234"
mydict.iteritems()
Test with dictiter
$ cat > testfile.py <<EOF
> obj['test'] = b"1234"
> mydict.iteritems()
> EOF
$ byteify_strings testfile.py --dictiter
obj[b'test'] = b"1234"
mydict.items()
Test kwargs-like objects
$ cat > testfile.py <<EOF
> kwargs['test'] = "123"
> kwargs[test['testing']]
> kwargs[test[[['testing']]]]
> kwargs[kwargs['testing']]
> kwargs.get('test')
> kwargs.pop('test')
> kwargs.get('test', 'testing')
> kwargs.pop('test', 'testing')
> kwargs.setdefault('test', 'testing')
>
> opts['test'] = "123"
> opts[test['testing']]
> opts[test[[['testing']]]]
> opts[opts['testing']]
> opts.get('test')
> opts.pop('test')
> opts.get('test', 'testing')
> opts.pop('test', 'testing')
> opts.setdefault('test', 'testing')
>
> commitopts['test'] = "123"
> commitopts[test['testing']]
> commitopts[test[[['testing']]]]
> commitopts[commitopts['testing']]
> commitopts.get('test')
> commitopts.pop('test')
> commitopts.get('test', 'testing')
> commitopts.pop('test', 'testing')
> commitopts.setdefault('test', 'testing')
> EOF
$ byteify_strings testfile.py --treat-as-kwargs kwargs opts commitopts
kwargs['test'] = b"123"
kwargs[test[b'testing']]
kwargs[test[[[b'testing']]]]
kwargs[kwargs['testing']]
kwargs.get('test')
kwargs.pop('test')
kwargs.get('test', b'testing')
kwargs.pop('test', b'testing')
kwargs.setdefault('test', b'testing')
opts['test'] = b"123"
opts[test[b'testing']]
opts[test[[[b'testing']]]]
opts[opts['testing']]
opts.get('test')
opts.pop('test')
opts.get('test', b'testing')
opts.pop('test', b'testing')
opts.setdefault('test', b'testing')
commitopts['test'] = b"123"
commitopts[test[b'testing']]
commitopts[test[[[b'testing']]]]
commitopts[commitopts['testing']]
commitopts.get('test')
commitopts.pop('test')
commitopts.get('test', b'testing')
commitopts.pop('test', b'testing')
commitopts.setdefault('test', b'testing')
Test attr*() as methods
$ cat > testfile.py <<EOF
> setattr(o, 'a', 1)
> util.setattr(o, 'ae', 1)
> util.getattr(o, 'alksjdf', 'default')
> util.addattr(o, 'asdf')
> util.hasattr(o, 'lksjdf', 'default')
> util.safehasattr(o, 'lksjdf', 'default')
> @eh.wrapfunction(func, 'lksjdf')
> def f():
> pass
> @eh.wrapclass(klass, 'lksjdf')
> def f():
> pass
> EOF
$ byteify_strings testfile.py --allow-attr-methods
setattr(o, 'a', 1)
util.setattr(o, 'ae', 1)
util.getattr(o, 'alksjdf', b'default')
util.addattr(o, 'asdf')
util.hasattr(o, 'lksjdf', b'default')
util.safehasattr(o, 'lksjdf', b'default')
@eh.wrapfunction(func, 'lksjdf')
def f():
pass
@eh.wrapclass(klass, 'lksjdf')
def f():
pass
Test without attr*() as methods
$ cat > testfile.py <<EOF
> setattr(o, 'a', 1)
> util.setattr(o, 'ae', 1)
> util.getattr(o, 'alksjdf', 'default')
> util.addattr(o, 'asdf')
> util.hasattr(o, 'lksjdf', 'default')
> util.safehasattr(o, 'lksjdf', 'default')
> @eh.wrapfunction(func, 'lksjdf')
> def f():
> pass
> @eh.wrapclass(klass, 'lksjdf')
> def f():
> pass
> EOF
$ byteify_strings testfile.py
setattr(o, 'a', 1)
util.setattr(o, b'ae', 1)
util.getattr(o, b'alksjdf', b'default')
util.addattr(o, b'asdf')
util.hasattr(o, b'lksjdf', b'default')
util.safehasattr(o, b'lksjdf', b'default')
@eh.wrapfunction(func, b'lksjdf')
def f():
pass
@eh.wrapclass(klass, b'lksjdf')
def f():
pass
Test ignore comments
$ cat > testfile.py <<EOF
Raphaël Gomès
byteify-strings: add space in special comments to silence flake8 error...
r42928 > # py3-transform: off
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 > "none"
> "of"
> 'these'
> s = """should"""
> d = '''be'''
Raphaël Gomès
byteify-strings: add space in special comments to silence flake8 error...
r42928 > # py3-transform: on
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 > "this should"
> 'and this also'
>
Raphaël Gomès
byteify-strings: add space in special comments to silence flake8 error...
r42928 > # no-py3-transform
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 > l = "this should be ignored"
> l2 = "this shouldn't"
>
> EOF
$ byteify_strings testfile.py
Raphaël Gomès
byteify-strings: add space in special comments to silence flake8 error...
r42928 # py3-transform: off
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 "none"
"of"
'these'
s = """should"""
d = '''be'''
Raphaël Gomès
byteify-strings: add space in special comments to silence flake8 error...
r42928 # py3-transform: on
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 b"this should"
b'and this also'
Raphaël Gomès
byteify-strings: add space in special comments to silence flake8 error...
r42928 # no-py3-transform
Raphaël Gomès
byteify-strings: add test for byteify-strings.py...
r42913 l = "this should be ignored"
l2 = b"this shouldn't"
Test triple-quoted strings
$ cat > testfile.py <<EOF
> """This is ignored
> """
>
> line = """
> This should not be
> """
> line = '''
> Neither should this
> '''
> EOF
$ byteify_strings testfile.py
"""This is ignored
"""
line = b"""
This should not be
"""
line = b'''
Neither should this
'''
Test prefixed strings
$ cat > testfile.py <<EOF
> obj['test'] = b"1234"
> obj[r'test'] = u"1234"
> EOF
$ byteify_strings testfile.py
obj[b'test'] = b"1234"
obj[r'test'] = u"1234"
Raphaël Gomès
byteify-strings: fix misalignment with multi-line parenthesis...
r42914
Test multi-line alignment
$ cat > testfile.py <<'EOF'
> def foo():
> error.Abort(_("foo"
> "bar"
> "%s")
> % parameter)
> {
> 'test': dict,
> 'test2': dict,
> }
> [
> "thing",
> "thing2"
> ]
> (
> "tuple",
> "tuple2",
> )
> {"thing",
> }
> EOF
$ byteify_strings testfile.py
def foo():
error.Abort(_(b"foo"
b"bar"
b"%s")
% parameter)
{
b'test': dict,
b'test2': dict,
}
[
b"thing",
b"thing2"
]
(
b"tuple",
b"tuple2",
)
{b"thing",
}