Mercurial > hg-stable
comparison tests/test-byteify-strings.t @ 42709:3364b4da5271
byteify-strings: add test for byteify-strings.py
This tests the basic features expected from this script, some cases may not
be covered yet.
A future patch will demonstrate an issue with multi-line `(`, `[` and `{`
alignment and propose a fix.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Fri, 02 Aug 2019 16:54:02 +0200 |
parents | |
children | 26a31c88e1a5 |
comparison
equal
deleted
inserted
replaced
42708:863e9e7f8850 | 42709:3364b4da5271 |
---|---|
1 #require py3 | |
2 | |
3 $ byteify_strings () { | |
4 > $PYTHON "$TESTDIR/../contrib/byteify-strings.py" "$@" | |
5 > } | |
6 | |
7 Test in-place | |
8 | |
9 $ cat > testfile.py <<EOF | |
10 > obj['test'] = b"1234" | |
11 > mydict.iteritems() | |
12 > EOF | |
13 $ byteify_strings testfile.py -i | |
14 $ cat testfile.py | |
15 obj[b'test'] = b"1234" | |
16 mydict.iteritems() | |
17 | |
18 Test with dictiter | |
19 | |
20 $ cat > testfile.py <<EOF | |
21 > obj['test'] = b"1234" | |
22 > mydict.iteritems() | |
23 > EOF | |
24 $ byteify_strings testfile.py --dictiter | |
25 obj[b'test'] = b"1234" | |
26 mydict.items() | |
27 | |
28 Test kwargs-like objects | |
29 | |
30 $ cat > testfile.py <<EOF | |
31 > kwargs['test'] = "123" | |
32 > kwargs[test['testing']] | |
33 > kwargs[test[[['testing']]]] | |
34 > kwargs[kwargs['testing']] | |
35 > kwargs.get('test') | |
36 > kwargs.pop('test') | |
37 > kwargs.get('test', 'testing') | |
38 > kwargs.pop('test', 'testing') | |
39 > kwargs.setdefault('test', 'testing') | |
40 > | |
41 > opts['test'] = "123" | |
42 > opts[test['testing']] | |
43 > opts[test[[['testing']]]] | |
44 > opts[opts['testing']] | |
45 > opts.get('test') | |
46 > opts.pop('test') | |
47 > opts.get('test', 'testing') | |
48 > opts.pop('test', 'testing') | |
49 > opts.setdefault('test', 'testing') | |
50 > | |
51 > commitopts['test'] = "123" | |
52 > commitopts[test['testing']] | |
53 > commitopts[test[[['testing']]]] | |
54 > commitopts[commitopts['testing']] | |
55 > commitopts.get('test') | |
56 > commitopts.pop('test') | |
57 > commitopts.get('test', 'testing') | |
58 > commitopts.pop('test', 'testing') | |
59 > commitopts.setdefault('test', 'testing') | |
60 > EOF | |
61 $ byteify_strings testfile.py --treat-as-kwargs kwargs opts commitopts | |
62 kwargs['test'] = b"123" | |
63 kwargs[test[b'testing']] | |
64 kwargs[test[[[b'testing']]]] | |
65 kwargs[kwargs['testing']] | |
66 kwargs.get('test') | |
67 kwargs.pop('test') | |
68 kwargs.get('test', b'testing') | |
69 kwargs.pop('test', b'testing') | |
70 kwargs.setdefault('test', b'testing') | |
71 | |
72 opts['test'] = b"123" | |
73 opts[test[b'testing']] | |
74 opts[test[[[b'testing']]]] | |
75 opts[opts['testing']] | |
76 opts.get('test') | |
77 opts.pop('test') | |
78 opts.get('test', b'testing') | |
79 opts.pop('test', b'testing') | |
80 opts.setdefault('test', b'testing') | |
81 | |
82 commitopts['test'] = b"123" | |
83 commitopts[test[b'testing']] | |
84 commitopts[test[[[b'testing']]]] | |
85 commitopts[commitopts['testing']] | |
86 commitopts.get('test') | |
87 commitopts.pop('test') | |
88 commitopts.get('test', b'testing') | |
89 commitopts.pop('test', b'testing') | |
90 commitopts.setdefault('test', b'testing') | |
91 | |
92 Test attr*() as methods | |
93 | |
94 $ cat > testfile.py <<EOF | |
95 > setattr(o, 'a', 1) | |
96 > util.setattr(o, 'ae', 1) | |
97 > util.getattr(o, 'alksjdf', 'default') | |
98 > util.addattr(o, 'asdf') | |
99 > util.hasattr(o, 'lksjdf', 'default') | |
100 > util.safehasattr(o, 'lksjdf', 'default') | |
101 > @eh.wrapfunction(func, 'lksjdf') | |
102 > def f(): | |
103 > pass | |
104 > @eh.wrapclass(klass, 'lksjdf') | |
105 > def f(): | |
106 > pass | |
107 > EOF | |
108 $ byteify_strings testfile.py --allow-attr-methods | |
109 setattr(o, 'a', 1) | |
110 util.setattr(o, 'ae', 1) | |
111 util.getattr(o, 'alksjdf', b'default') | |
112 util.addattr(o, 'asdf') | |
113 util.hasattr(o, 'lksjdf', b'default') | |
114 util.safehasattr(o, 'lksjdf', b'default') | |
115 @eh.wrapfunction(func, 'lksjdf') | |
116 def f(): | |
117 pass | |
118 @eh.wrapclass(klass, 'lksjdf') | |
119 def f(): | |
120 pass | |
121 | |
122 Test without attr*() as methods | |
123 | |
124 $ cat > testfile.py <<EOF | |
125 > setattr(o, 'a', 1) | |
126 > util.setattr(o, 'ae', 1) | |
127 > util.getattr(o, 'alksjdf', 'default') | |
128 > util.addattr(o, 'asdf') | |
129 > util.hasattr(o, 'lksjdf', 'default') | |
130 > util.safehasattr(o, 'lksjdf', 'default') | |
131 > @eh.wrapfunction(func, 'lksjdf') | |
132 > def f(): | |
133 > pass | |
134 > @eh.wrapclass(klass, 'lksjdf') | |
135 > def f(): | |
136 > pass | |
137 > EOF | |
138 $ byteify_strings testfile.py | |
139 setattr(o, 'a', 1) | |
140 util.setattr(o, b'ae', 1) | |
141 util.getattr(o, b'alksjdf', b'default') | |
142 util.addattr(o, b'asdf') | |
143 util.hasattr(o, b'lksjdf', b'default') | |
144 util.safehasattr(o, b'lksjdf', b'default') | |
145 @eh.wrapfunction(func, b'lksjdf') | |
146 def f(): | |
147 pass | |
148 @eh.wrapclass(klass, b'lksjdf') | |
149 def f(): | |
150 pass | |
151 | |
152 Test ignore comments | |
153 | |
154 $ cat > testfile.py <<EOF | |
155 > #py3-transform: off | |
156 > "none" | |
157 > "of" | |
158 > 'these' | |
159 > s = """should""" | |
160 > d = '''be''' | |
161 > #py3-transform: on | |
162 > "this should" | |
163 > 'and this also' | |
164 > | |
165 > #no-py3-transform | |
166 > l = "this should be ignored" | |
167 > l2 = "this shouldn't" | |
168 > | |
169 > EOF | |
170 $ byteify_strings testfile.py | |
171 #py3-transform: off | |
172 "none" | |
173 "of" | |
174 'these' | |
175 s = """should""" | |
176 d = '''be''' | |
177 #py3-transform: on | |
178 b"this should" | |
179 b'and this also' | |
180 | |
181 #no-py3-transform | |
182 l = "this should be ignored" | |
183 l2 = b"this shouldn't" | |
184 | |
185 Test triple-quoted strings | |
186 | |
187 $ cat > testfile.py <<EOF | |
188 > """This is ignored | |
189 > """ | |
190 > | |
191 > line = """ | |
192 > This should not be | |
193 > """ | |
194 > line = ''' | |
195 > Neither should this | |
196 > ''' | |
197 > EOF | |
198 $ byteify_strings testfile.py | |
199 """This is ignored | |
200 """ | |
201 | |
202 line = b""" | |
203 This should not be | |
204 """ | |
205 line = b''' | |
206 Neither should this | |
207 ''' | |
208 | |
209 Test prefixed strings | |
210 | |
211 $ cat > testfile.py <<EOF | |
212 > obj['test'] = b"1234" | |
213 > obj[r'test'] = u"1234" | |
214 > EOF | |
215 $ byteify_strings testfile.py | |
216 obj[b'test'] = b"1234" | |
217 obj[r'test'] = u"1234" |