Debian Codegraph @

tests/data/cases/multiline_strings.py

raw
1 """cow
2 say""",
3 call(3, "dogsay", textwrap.dedent("""dove
4 coo""" % "cowabunga"))
5 call(3, "dogsay", textwrap.dedent("""dove
6 coo""" % "cowabunga"))
7 call(3, textwrap.dedent("""cow
8 moo""" % "cowabunga"), "dogsay")
9 call(3, "dogsay", textwrap.dedent("""crow
10 caw""" % "cowabunga"),)
11 call(3, textwrap.dedent("""cat
12 meow""" % "cowabunga"), {"dog", "say"})
13 call(3, {"dog", "say"}, textwrap.dedent("""horse
14 neigh""" % "cowabunga"))
15 call(3, {"dog", "say"}, textwrap.dedent("""pig
16 oink""" % "cowabunga"),)
17 textwrap.dedent("""A one-line triple-quoted string.""")
18 textwrap.dedent("""A two-line triple-quoted string
19 since it goes to the next line.""")
20 textwrap.dedent("""A three-line triple-quoted string
21 that not only goes to the next line
22 but also goes one line beyond.""")
23 textwrap.dedent("""\
24 A triple-quoted string
25 actually leveraging the textwrap.dedent functionality
26 that ends in a trailing newline,
27 representing e.g. file contents.
28 """)
29 path.write_text(textwrap.dedent("""\
30 A triple-quoted string
31 actually leveraging the textwrap.dedent functionality
32 that ends in a trailing newline,
33 representing e.g. file contents.
34 """))
35 path.write_text(textwrap.dedent("""\
36 A triple-quoted string
37 actually leveraging the textwrap.dedent functionality
38 that ends in a trailing newline,
39 representing e.g. {config_filename} file contents.
40 """.format("config_filename", config_filename)))
41 # Another use case
42 data = yaml.load("""\
43 a: 1
44 b: 2
45 """)
46 data = yaml.load("""\
47 a: 1
48 b: 2
49 """,)
50 data = yaml.load(
51 """\
52 a: 1
53 b: 2
54 """
55 )
56
57 MULTILINE = """
58 foo
59 """.replace("\n", "")
60 generated_readme = lambda project_name: """
61 {}
62
63 <Add content here!>
64 """.strip().format(project_name)
65 parser.usage += """
66 Custom extra help summary.
67
68 Extra test:
69 - with
70 - bullets
71 """
72
73
74 def get_stuff(cr, value):
75 # original
76 cr.execute("""
77 SELECT whatever
78 FROM some_table t
79 WHERE id = %s
80 """, [value])
81 return cr.fetchone()
82
83
84 def get_stuff(cr, value):
85 # preferred
86 cr.execute(
87 """
88 SELECT whatever
89 FROM some_table t
90 WHERE id = %s
91 """,
92 [value],
93 )
94 return cr.fetchone()
95
96
97 call(arg1, arg2, """
98 short
99 """, arg3=True)
100 test_vectors = [
101 "one-liner\n",
102 "two\nliner\n",
103 """expressed
104 as a three line
105 mulitline string""",
106 ]
107
108 _wat = re.compile(
109 r"""
110 regex
111 """,
112 re.MULTILINE | re.VERBOSE,
113 )
114 dis_c_instance_method = """\
115 %3d 0 LOAD_FAST 1 (x)
116 2 LOAD_CONST 1 (1)
117 4 COMPARE_OP 2 (==)
118 6 LOAD_FAST 0 (self)
119 8 STORE_ATTR 0 (x)
120 10 LOAD_CONST 0 (None)
121 12 RETURN_VALUE
122 """ % (_C.__init__.__code__.co_firstlineno + 1,)
123 path.write_text(textwrap.dedent("""\
124 A triple-quoted string
125 actually {verb} the textwrap.dedent functionality
126 that ends in a trailing newline,
127 representing e.g. {file_type} file contents.
128 """.format(verb="using", file_type="test")))
129 {"""cow
130 moos"""}
131 ["""cow
132 moos"""]
133 ["""cow
134 moos""", """dog
135 woofs
136 and
137 barks"""]
138 def dastardly_default_value(
139 cow: String = json.loads("""this
140 is
141 quite
142 the
143 dastadardly
144 value!"""),
145 **kwargs,
146 ):
147 pass
148
149 print(f"""
150 This {animal}
151 moos and barks
152 {animal} say
153 """)
154 msg = f"""The arguments {bad_arguments} were passed in.
155 Please use `--build-option` instead,
156 `--global-option` is reserved to flags like `--verbose` or `--quiet`.
157 """
158
159 assert some_var == expected_result, """
160 test
161 """
162 assert some_var == expected_result, f"""
163 expected: {expected_result}
164 actual: {some_var}"""
165
166
167 def foo():
168 a = {
169 xxxx_xxxxxxx.xxxxxx_xxxxxxxxxxxx_xxxxxx_xx_xxx_xxxxxx: {
170 "xxxxx": """Sxxxxx xxxxxxxxxxxx xxx xxxxx (xxxxxx xxx xxxxxxx)""",
171 "xxxxxxxx": (
172 """Sxxxxxxx xxxxxxxx, xxxxxxx xx xxxxxxxxx
173 xxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxx-xxxxxxxxxx xxxxxx xx xxx-xxxxxx"""
174 ),
175 "xxxxxxxx": """Sxxxxxxx xxxxxxxx, xxxxxxx xx xxxxxxxxx
176 xxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxx-xxxxxxxxxx xxxxxx xx xxx-xxxxxx"""
177 },
178 }
179
180
181 xxxx_xxxxxxx.xxxxxx_xxxxxxxxxxxx_xxxxxx_xx_xxx_xxxxxx = {
182 "xxxxx": """Sxxxxx xxxxxxxxxxxx xxx xxxxx (xxxxxx xxx xxxxxxx)""",
183 "xxxxxxxx": (
184 """Sxxxxxxx xxxxxxxx, xxxxxxx xx xxxxxxxxx
185 xxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxx-xxxxxxxxxx xxxxxx xx xxx-xxxxxx"""
186 ),
187 "xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
188 """
189 a
190 a
191 a
192 a
193 a"""
194 ),
195 "xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": """
196 a
197 a
198 a
199 a
200 a""",
201 }
202
203 a = """
204 """ if """
205 """ == """
206 """ else """
207 """
208
209 a = """
210 """ if b else """
211 """
212
213 a = """
214 """ if """
215 """ == """
216 """ else b
217
218 a = b if """
219 """ == """
220 """ else """
221 """
222
223 a = """
224 """ if b else c
225
226 a = c if b else """
227 """
228
229 a = b if """
230 """ == """
231 """ else c
232
233 # output
234
235 """cow
236 say""",
237 call(
238 3,
239 "dogsay",
240 textwrap.dedent("""dove
241 coo""" % "cowabunga"),
242 )
243 call(
244 3,
245 "dogsay",
246 textwrap.dedent("""dove
247 coo""" % "cowabunga"),
248 )
249 call(
250 3,
251 textwrap.dedent("""cow
252 moo""" % "cowabunga"),
253 "dogsay",
254 )
255 call(
256 3,
257 "dogsay",
258 textwrap.dedent("""crow
259 caw""" % "cowabunga"),
260 )
261 call(
262 3,
263 textwrap.dedent("""cat
264 meow""" % "cowabunga"),
265 {"dog", "say"},
266 )
267 call(
268 3,
269 {"dog", "say"},
270 textwrap.dedent("""horse
271 neigh""" % "cowabunga"),
272 )
273 call(
274 3,
275 {"dog", "say"},
276 textwrap.dedent("""pig
277 oink""" % "cowabunga"),
278 )
279 textwrap.dedent("""A one-line triple-quoted string.""")
280 textwrap.dedent("""A two-line triple-quoted string
281 since it goes to the next line.""")
282 textwrap.dedent("""A three-line triple-quoted string
283 that not only goes to the next line
284 but also goes one line beyond.""")
285 textwrap.dedent("""\
286 A triple-quoted string
287 actually leveraging the textwrap.dedent functionality
288 that ends in a trailing newline,
289 representing e.g. file contents.
290 """)
291 path.write_text(textwrap.dedent("""\
292 A triple-quoted string
293 actually leveraging the textwrap.dedent functionality
294 that ends in a trailing newline,
295 representing e.g. file contents.
296 """))
297 path.write_text(textwrap.dedent("""\
298 A triple-quoted string
299 actually leveraging the textwrap.dedent functionality
300 that ends in a trailing newline,
301 representing e.g. {config_filename} file contents.
302 """.format("config_filename", config_filename)))
303 # Another use case
304 data = yaml.load("""\
305 a: 1
306 b: 2
307 """)
308 data = yaml.load(
309 """\
310 a: 1
311 b: 2
312 """,
313 )
314 data = yaml.load("""\
315 a: 1
316 b: 2
317 """)
318
319 MULTILINE = """
320 foo
321 """.replace("\n", "")
322 generated_readme = lambda project_name: """
323 {}
324
325 <Add content here!>
326 """.strip().format(project_name)
327 parser.usage += """
328 Custom extra help summary.
329
330 Extra test:
331 - with
332 - bullets
333 """
334
335
336 def get_stuff(cr, value):
337 # original
338 cr.execute(
339 """
340 SELECT whatever
341 FROM some_table t
342 WHERE id = %s
343 """,
344 [value],
345 )
346 return cr.fetchone()
347
348
349 def get_stuff(cr, value):
350 # preferred
351 cr.execute(
352 """
353 SELECT whatever
354 FROM some_table t
355 WHERE id = %s
356 """,
357 [value],
358 )
359 return cr.fetchone()
360
361
362 call(
363 arg1,
364 arg2,
365 """
366 short
367 """,
368 arg3=True,
369 )
370 test_vectors = [
371 "one-liner\n",
372 "two\nliner\n",
373 """expressed
374 as a three line
375 mulitline string""",
376 ]
377
378 _wat = re.compile(
379 r"""
380 regex
381 """,
382 re.MULTILINE | re.VERBOSE,
383 )
384 dis_c_instance_method = """\
385 %3d 0 LOAD_FAST 1 (x)
386 2 LOAD_CONST 1 (1)
387 4 COMPARE_OP 2 (==)
388 6 LOAD_FAST 0 (self)
389 8 STORE_ATTR 0 (x)
390 10 LOAD_CONST 0 (None)
391 12 RETURN_VALUE
392 """ % (_C.__init__.__code__.co_firstlineno + 1,)
393 path.write_text(textwrap.dedent("""\
394 A triple-quoted string
395 actually {verb} the textwrap.dedent functionality
396 that ends in a trailing newline,
397 representing e.g. {file_type} file contents.
398 """.format(verb="using", file_type="test")))
399 {"""cow
400 moos"""}
401 ["""cow
402 moos"""]
403 [
404 """cow
405 moos""",
406 """dog
407 woofs
408 and
409 barks""",
410 ]
411
412
413 def dastardly_default_value(
414 cow: String = json.loads("""this
415 is
416 quite
417 the
418 dastadardly
419 value!"""),
420 **kwargs,
421 ):
422 pass
423
424
425 print(f"""
426 This {animal}
427 moos and barks
428 {animal} say
429 """)
430 msg = f"""The arguments {bad_arguments} were passed in.
431 Please use `--build-option` instead,
432 `--global-option` is reserved to flags like `--verbose` or `--quiet`.
433 """
434
435 assert some_var == expected_result, """
436 test
437 """
438 assert some_var == expected_result, f"""
439 expected: {expected_result}
440 actual: {some_var}"""
441
442
443 def foo():
444 a = {
445 xxxx_xxxxxxx.xxxxxx_xxxxxxxxxxxx_xxxxxx_xx_xxx_xxxxxx: {
446 "xxxxx": """Sxxxxx xxxxxxxxxxxx xxx xxxxx (xxxxxx xxx xxxxxxx)""",
447 "xxxxxxxx": (
448 """Sxxxxxxx xxxxxxxx, xxxxxxx xx xxxxxxxxx
449 xxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxx-xxxxxxxxxx xxxxxx xx xxx-xxxxxx"""
450 ),
451 "xxxxxxxx": """Sxxxxxxx xxxxxxxx, xxxxxxx xx xxxxxxxxx
452 xxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxx-xxxxxxxxxx xxxxxx xx xxx-xxxxxx""",
453 },
454 }
455
456
457 xxxx_xxxxxxx.xxxxxx_xxxxxxxxxxxx_xxxxxx_xx_xxx_xxxxxx = {
458 "xxxxx": """Sxxxxx xxxxxxxxxxxx xxx xxxxx (xxxxxx xxx xxxxxxx)""",
459 "xxxxxxxx": (
460 """Sxxxxxxx xxxxxxxx, xxxxxxx xx xxxxxxxxx
461 xxxxxxxxxxxxx xxxxxxx xxxxxxxxx xxx-xxxxxxxxxx xxxxxx xx xxx-xxxxxx"""
462 ),
463 "xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": (
464 """
465 a
466 a
467 a
468 a
469 a"""
470 ),
471 "xx_xxxxx_xxxxxxxxxx_xxxxxxxxx_xx": """
472 a
473 a
474 a
475 a
476 a""",
477 }
478
479 a = (
480 """
481 """
482 if """
483 """
484 == """
485 """
486 else """
487 """
488 )
489
490 a = (
491 """
492 """
493 if b
494 else """
495 """
496 )
497
498 a = (
499 """
500 """
501 if """
502 """
503 == """
504 """
505 else b
506 )
507
508 a = (
509 b
510 if """
511 """
512 == """
513 """
514 else """
515 """
516 )
517
518 a = (
519 """
520 """
521 if b
522 else c
523 )
524
525 a = (
526 c
527 if b
528 else """
529 """
530 )
531
532 a = (
533 b
534 if """
535 """
536 == """
537 """
538 else c
539 )