1# Copyright 2016 Google Inc. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14"""Buganizer tests for yapf.reformatter.""" 15 16import textwrap 17import unittest 18 19from yapf.yapflib import reformatter 20from yapf.yapflib import style 21 22from yapftests import yapf_test_helper 23 24 25class BuganizerFixes(yapf_test_helper.YAPFTest): 26 27 @classmethod 28 def setUpClass(cls): 29 style.SetGlobalStyle(style.CreateYapfStyle()) 30 31 def testB137580392(self): 32 code = """\ 33def _create_testing_simulator_and_sink( 34) -> Tuple[_batch_simulator:_batch_simulator.BatchSimulator, 35 _batch_simulator.SimulationSink]: 36 pass 37""" 38 llines = yapf_test_helper.ParseAndUnwrap(code) 39 self.assertCodeEqual(code, reformatter.Reformat(llines)) 40 41 def testB73279849(self): 42 unformatted_code = """\ 43class A: 44 def _(a): 45 return 'hello' [ a ] 46""" 47 expected_formatted_code = """\ 48class A: 49 def _(a): 50 return 'hello'[a] 51""" 52 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 53 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 54 55 def testB122455211(self): 56 unformatted_code = """\ 57_zzzzzzzzzzzzzzzzzzzz = Union[sssssssssssssssssssss.pppppppppppppppp, 58 sssssssssssssssssssss.pppppppppppppppppppppppppppp] 59""" 60 expected_formatted_code = """\ 61_zzzzzzzzzzzzzzzzzzzz = Union[ 62 sssssssssssssssssssss.pppppppppppppppp, 63 sssssssssssssssssssss.pppppppppppppppppppppppppppp] 64""" 65 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 66 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 67 68 def testB119300344(self): 69 code = """\ 70def _GenerateStatsEntries( 71 process_id: Text, 72 timestamp: Optional[rdfvalue.RDFDatetime] = None 73) -> Sequence[stats_values.StatsStoreEntry]: 74 pass 75""" 76 llines = yapf_test_helper.ParseAndUnwrap(code) 77 self.assertCodeEqual(code, reformatter.Reformat(llines)) 78 79 def testB132886019(self): 80 code = """\ 81X = { 82 'some_dict_key': 83 frozenset([ 84 # pylint: disable=line-too-long 85 '//this/path/is/really/too/long/for/this/line/and/probably/should/be/split', 86 ]), 87} 88""" 89 llines = yapf_test_helper.ParseAndUnwrap(code) 90 self.assertCodeEqual(code, reformatter.Reformat(llines)) 91 92 def testB26521719(self): 93 code = """\ 94class _(): 95 96 def _(self): 97 self.stubs.Set(some_type_of_arg, 'ThisIsAStringArgument', 98 lambda *unused_args, **unused_kwargs: fake_resolver) 99""" 100 llines = yapf_test_helper.ParseAndUnwrap(code) 101 self.assertCodeEqual(code, reformatter.Reformat(llines)) 102 103 def testB122541552(self): 104 code = """\ 105# pylint: disable=g-explicit-bool-comparison,singleton-comparison 106_QUERY = account.Account.query(account.Account.enabled == True) 107# pylint: enable=g-explicit-bool-comparison,singleton-comparison 108 109 110def _(): 111 pass 112""" 113 llines = yapf_test_helper.ParseAndUnwrap(code) 114 self.assertCodeEqual(code, reformatter.Reformat(llines)) 115 116 def testB124415889(self): 117 code = """\ 118class _(): 119 120 def run_queue_scanners(): 121 return xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( 122 { 123 components.NAME.FNOR: True, 124 components.NAME.DEVO: True, 125 }, 126 default=False) 127 128 def modules_to_install(): 129 modules = DeepCopy(GetDef({})) 130 modules.update({ 131 'xxxxxxxxxxxxxxxxxxxx': 132 GetDef('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', None), 133 }) 134 return modules 135""" 136 llines = yapf_test_helper.ParseAndUnwrap(code) 137 self.assertCodeEqual(code, reformatter.Reformat(llines)) 138 139 def testB73166511(self): 140 code = """\ 141def _(): 142 if min_std is not None: 143 groundtruth_age_variances = tf.maximum(groundtruth_age_variances, 144 min_std**2) 145""" 146 llines = yapf_test_helper.ParseAndUnwrap(code) 147 self.assertCodeEqual(code, reformatter.Reformat(llines)) 148 149 def testB118624921(self): 150 code = """\ 151def _(): 152 function_call( 153 alert_name='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 154 time_delta='1h', 155 alert_level='bbbbbbbb', 156 metric='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 157 bork=foo) 158""" 159 llines = yapf_test_helper.ParseAndUnwrap(code) 160 self.assertCodeEqual(code, reformatter.Reformat(llines)) 161 162 def testB35417079(self): 163 code = """\ 164class _(): 165 166 def _(): 167 X = ( 168 _ares_label_prefix + 169 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' # pylint: disable=line-too-long 170 'PyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyTypePyType' # pytype: disable=attribute-error 171 'CopybaraCopybaraCopybaraCopybaraCopybaraCopybaraCopybaraCopybaraCopybara' # copybara:strip 172 ) 173""" # noqa 174 llines = yapf_test_helper.ParseAndUnwrap(code) 175 self.assertCodeEqual(code, reformatter.Reformat(llines)) 176 177 def testB120047670(self): 178 unformatted_code = """\ 179X = { 180 'NO_PING_COMPONENTS': [ 181 79775, # Releases / FOO API 182 79770, # Releases / BAZ API 183 79780], # Releases / MUX API 184 185 'PING_BLOCKED_BUGS': False, 186} 187""" 188 expected_formatted_code = """\ 189X = { 190 'NO_PING_COMPONENTS': [ 191 79775, # Releases / FOO API 192 79770, # Releases / BAZ API 193 79780 194 ], # Releases / MUX API 195 'PING_BLOCKED_BUGS': False, 196} 197""" 198 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 199 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 200 201 def testB120245013(self): 202 unformatted_code = """\ 203class Foo(object): 204 def testNoAlertForShortPeriod(self, rutabaga): 205 self.targets[:][streamz_path,self._fillInOtherFields(streamz_path, {streamz_field_of_interest:True})] = series.Counter('1s', '+ 500x10000') 206""" # noqa 207 expected_formatted_code = """\ 208class Foo(object): 209 210 def testNoAlertForShortPeriod(self, rutabaga): 211 self.targets[:][ 212 streamz_path, 213 self._fillInOtherFields(streamz_path, {streamz_field_of_interest: True} 214 )] = series.Counter('1s', '+ 500x10000') 215""" 216 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 217 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 218 219 def testB117841880(self): 220 code = """\ 221def xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( 222 aaaaaaaaaaaaaaaaaaa: AnyStr, 223 bbbbbbbbbbbb: Optional[Sequence[AnyStr]] = None, 224 cccccccccc: AnyStr = cst.DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD, 225 dddddddddd: Sequence[SliceDimension] = (), 226 eeeeeeeeeeee: AnyStr = cst.DEFAULT_CONTROL_NAME, 227 ffffffffffffffffffff: Optional[Callable[[pd.DataFrame], 228 pd.DataFrame]] = None, 229 gggggggggggggg: ooooooooooooo = ooooooooooooo() 230) -> pd.DataFrame: 231 pass 232""" 233 llines = yapf_test_helper.ParseAndUnwrap(code) 234 self.assertCodeEqual(code, reformatter.Reformat(llines)) 235 236 def testB111764402(self): 237 unformatted_code = """\ 238x = self.stubs.stub(video_classification_map, 'read_video_classifications', (lambda external_ids, **unused_kwargs: {external_id: self._get_serving_classification('video') for external_id in external_ids})) 239""" # noqa 240 expected_formatted_code = """\ 241x = self.stubs.stub(video_classification_map, 'read_video_classifications', 242 (lambda external_ids, **unused_kwargs: { 243 external_id: self._get_serving_classification('video') 244 for external_id in external_ids 245 })) 246""" 247 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 248 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 249 250 def testB116825060(self): 251 code = """\ 252result_df = pd.DataFrame({LEARNED_CTR_COLUMN: learned_ctr}, 253 index=df_metrics.index) 254""" 255 llines = yapf_test_helper.ParseAndUnwrap(code) 256 self.assertCodeEqual(code, reformatter.Reformat(llines)) 257 258 def testB112711217(self): 259 code = """\ 260def _(): 261 stats['moderated'] = ~stats.moderation_reason.isin( 262 approved_moderation_reasons) 263""" 264 llines = yapf_test_helper.ParseAndUnwrap(code) 265 self.assertCodeEqual(code, reformatter.Reformat(llines)) 266 267 def testB112867548(self): 268 unformatted_code = """\ 269def _(): 270 return flask.make_response( 271 'Records: {}, Problems: {}, More: {}'.format( 272 process_result.result_ct, process_result.problem_ct, 273 process_result.has_more), 274 httplib.ACCEPTED if process_result.has_more else httplib.OK, 275 {'content-type': _TEXT_CONTEXT_TYPE}) 276""" 277 expected_formatted_code = """\ 278def _(): 279 return flask.make_response( 280 'Records: {}, Problems: {}, More: {}'.format(process_result.result_ct, 281 process_result.problem_ct, 282 process_result.has_more), 283 httplib.ACCEPTED if process_result.has_more else httplib.OK, 284 {'content-type': _TEXT_CONTEXT_TYPE}) 285""" 286 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 287 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 288 289 def testB112651423(self): 290 unformatted_code = """\ 291def potato(feeditems, browse_use_case=None): 292 for item in turnip: 293 if kumquat: 294 if not feeds_variants.variants['FEEDS_LOAD_PLAYLIST_VIDEOS_FOR_ALL_ITEMS'] and item.video: 295 continue 296""" # noqa 297 expected_formatted_code = """\ 298def potato(feeditems, browse_use_case=None): 299 for item in turnip: 300 if kumquat: 301 if not feeds_variants.variants[ 302 'FEEDS_LOAD_PLAYLIST_VIDEOS_FOR_ALL_ITEMS'] and item.video: 303 continue 304""" 305 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 306 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 307 308 def testB80484938(self): 309 code = """\ 310for sssssss, aaaaaaaaaa in [ 311 ('ssssssssssssssssssss', 'sssssssssssssssssssssssss'), 312 ('nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn', 313 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn'), 314 ('pppppppppppppppppppppppppppp', 'pppppppppppppppppppppppppppppppp'), 315 ('wwwwwwwwwwwwwwwwwwww', 'wwwwwwwwwwwwwwwwwwwwwwwww'), 316 ('sssssssssssssssss', 'sssssssssssssssssssssss'), 317 ('ggggggggggggggggggggggg', 'gggggggggggggggggggggggggggg'), 318 ('ggggggggggggggggg', 'gggggggggggggggggggggg'), 319 ('eeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeee') 320]: 321 pass 322 323for sssssss, aaaaaaaaaa in [ 324 ('ssssssssssssssssssss', 'sssssssssssssssssssssssss'), 325 ('nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn', 'nnnnnnnnnnnnnnnnnnnnnnnnn'), 326 ('pppppppppppppppppppppppppppp', 'pppppppppppppppppppppppppppppppp'), 327 ('wwwwwwwwwwwwwwwwwwww', 'wwwwwwwwwwwwwwwwwwwwwwwww'), 328 ('sssssssssssssssss', 'sssssssssssssssssssssss'), 329 ('ggggggggggggggggggggggg', 'gggggggggggggggggggggggggggg'), 330 ('ggggggggggggggggg', 'gggggggggggggggggggggg'), 331 ('eeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeee') 332]: 333 pass 334 335for sssssss, aaaaaaaaaa in [ 336 ('ssssssssssssssssssss', 'sssssssssssssssssssssssss'), 337 ('nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn', 338 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn'), 339 ('pppppppppppppppppppppppppppp', 'pppppppppppppppppppppppppppppppp'), 340 ('wwwwwwwwwwwwwwwwwwww', 'wwwwwwwwwwwwwwwwwwwwwwwww'), 341 ('sssssssssssssssss', 'sssssssssssssssssssssss'), 342 ('ggggggggggggggggggggggg', 'gggggggggggggggggggggggggggg'), 343 ('ggggggggggggggggg', 'gggggggggggggggggggggg'), 344 ('eeeeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeeeeeeeeee'), 345]: 346 pass 347""" 348 llines = yapf_test_helper.ParseAndUnwrap(code) 349 self.assertCodeEqual(code, reformatter.Reformat(llines)) 350 351 def testB120771563(self): 352 code = """\ 353class A: 354 355 def b(): 356 d = { 357 "123456": [{ 358 "12": "aa" 359 }, { 360 "12": "bb" 361 }, { 362 "12": "cc", 363 "1234567890": { 364 "1234567": [{ 365 "12": "dd", 366 "12345": "text 1" 367 }, { 368 "12": "ee", 369 "12345": "text 2" 370 }] 371 } 372 }] 373 } 374""" 375 llines = yapf_test_helper.ParseAndUnwrap(code) 376 self.assertCodeEqual(code, reformatter.Reformat(llines)) 377 378 def testB79462249(self): 379 code = """\ 380foo.bar(baz, [ 381 quux(thud=42), 382 norf, 383]) 384foo.bar(baz, [ 385 quux(), 386 norf, 387]) 388foo.bar(baz, quux(thud=42), aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbb, 389 ccccccccccccccccccc) 390foo.bar( 391 baz, 392 quux(thud=42), 393 aaaaaaaaaaaaaaaaaaaaaa=1, 394 bbbbbbbbbbbbbbbbbbbbb=2, 395 ccccccccccccccccccc=3) 396""" 397 llines = yapf_test_helper.ParseAndUnwrap(code) 398 self.assertCodeEqual(code, reformatter.Reformat(llines)) 399 400 def testB113210278(self): 401 unformatted_code = """\ 402def _(): 403 aaaaaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.cccccccccccccccccccccccccccc(\ 404eeeeeeeeeeeeeeeeeeeeeeeeee.fffffffffffffffffffffffffffffffffffffff.\ 405ggggggggggggggggggggggggggggggggg.hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh()) 406""" # noqa 407 expected_formatted_code = """\ 408def _(): 409 aaaaaaaaaaa = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.cccccccccccccccccccccccccccc( 410 eeeeeeeeeeeeeeeeeeeeeeeeee.fffffffffffffffffffffffffffffffffffffff 411 .ggggggggggggggggggggggggggggggggg.hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh()) 412""" # noqa 413 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 414 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 415 416 def testB77923341(self): 417 code = """\ 418def f(): 419 if (aaaaaaaaaaaaaa.bbbbbbbbbbbb.ccccc <= 0 and # pytype: disable=attribute-error 420 ddddddddddd.eeeeeeeee == constants.FFFFFFFFFFFFFF): 421 raise "yo" 422""" # noqa 423 llines = yapf_test_helper.ParseAndUnwrap(code) 424 self.assertCodeEqual(code, reformatter.Reformat(llines)) 425 426 def testB77329955(self): 427 code = """\ 428class _(): 429 430 @parameterized.named_parameters( 431 ('ReadyExpiredSuccess', True, True, True, None, None), 432 ('SpannerUpdateFails', True, False, True, None, None), 433 ('ReadyNotExpired', False, True, True, True, None), 434 # ('ReadyNotExpiredNotHealthy', False, True, True, False, True), 435 # ('ReadyNotExpiredNotHealthyErrorFails', False, True, True, False, False 436 # ('ReadyNotExpiredNotHealthyUpdateFails', False, False, True, False, True 437 ) 438 def _(): 439 pass 440""" 441 llines = yapf_test_helper.ParseAndUnwrap(code) 442 self.assertCodeEqual(code, reformatter.Reformat(llines)) 443 444 def testB65197969(self): 445 unformatted_code = """\ 446class _(): 447 448 def _(): 449 return timedelta(seconds=max(float(time_scale), small_interval) * 450 1.41 ** min(num_attempts, 9)) 451""" 452 expected_formatted_code = """\ 453class _(): 454 455 def _(): 456 return timedelta( 457 seconds=max(float(time_scale), small_interval) * 458 1.41**min(num_attempts, 9)) 459""" 460 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 461 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 462 463 def testB65546221(self): 464 unformatted_code = """\ 465SUPPORTED_PLATFORMS = ( 466 "centos-6", 467 "centos-7", 468 "ubuntu-1204-precise", 469 "ubuntu-1404-trusty", 470 "ubuntu-1604-xenial", 471 "debian-7-wheezy", 472 "debian-8-jessie", 473 "debian-9-stretch",) 474""" 475 expected_formatted_code = """\ 476SUPPORTED_PLATFORMS = ( 477 "centos-6", 478 "centos-7", 479 "ubuntu-1204-precise", 480 "ubuntu-1404-trusty", 481 "ubuntu-1604-xenial", 482 "debian-7-wheezy", 483 "debian-8-jessie", 484 "debian-9-stretch", 485) 486""" 487 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 488 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 489 490 def testB30500455(self): 491 unformatted_code = """\ 492INITIAL_SYMTAB = dict([(name, 'exception#' + name) for name in INITIAL_EXCEPTIONS 493] * [(name, 'type#' + name) for name in INITIAL_TYPES] + [ 494 (name, 'function#' + name) for name in INITIAL_FUNCTIONS 495] + [(name, 'const#' + name) for name in INITIAL_CONSTS]) 496""" # noqa 497 expected_formatted_code = """\ 498INITIAL_SYMTAB = dict( 499 [(name, 'exception#' + name) for name in INITIAL_EXCEPTIONS] * 500 [(name, 'type#' + name) for name in INITIAL_TYPES] + 501 [(name, 'function#' + name) for name in INITIAL_FUNCTIONS] + 502 [(name, 'const#' + name) for name in INITIAL_CONSTS]) 503""" 504 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 505 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 506 507 def testB38343525(self): 508 code = """\ 509# This does foo. 510@arg.String('some_path_to_a_file', required=True) 511# This does bar. 512@arg.String('some_path_to_a_file', required=True) 513def f(): 514 print 1 515""" 516 llines = yapf_test_helper.ParseAndUnwrap(code) 517 self.assertCodeEqual(code, reformatter.Reformat(llines)) 518 519 def testB37099651(self): 520 unformatted_code = """\ 521_MEMCACHE = lazy.MakeLazy( 522 # pylint: disable=g-long-lambda 523 lambda: function.call.mem.clients(FLAGS.some_flag_thingy, default_namespace=_LAZY_MEM_NAMESPACE, allow_pickle=True) 524 # pylint: enable=g-long-lambda 525) 526""" # noqa 527 expected_formatted_code = """\ 528_MEMCACHE = lazy.MakeLazy( 529 # pylint: disable=g-long-lambda 530 lambda: function.call.mem.clients( 531 FLAGS.some_flag_thingy, 532 default_namespace=_LAZY_MEM_NAMESPACE, 533 allow_pickle=True) 534 # pylint: enable=g-long-lambda 535) 536""" 537 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 538 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 539 540 def testB33228502(self): 541 unformatted_code = """\ 542def _(): 543 success_rate_stream_table = module.Precompute( 544 query_function=module.DefineQueryFunction( 545 name='Response error ratio', 546 expression=((m.Fetch( 547 m.Raw('monarch.BorgTask', 548 '/corp/travel/trips2/dispatcher/email/response'), 549 {'borg_job': module_config.job, 'metric:response_type': 'SUCCESS'}), 550 m.Fetch(m.Raw('monarch.BorgTask', '/corp/travel/trips2/dispatcher/email/response'), {'borg_job': module_config.job})) 551 | m.Window(m.Delta('1h')) 552 | m.Join('successes', 'total') 553 | m.Point(m.VAL['successes'] / m.VAL['total'])))) 554""" # noqa 555 expected_formatted_code = """\ 556def _(): 557 success_rate_stream_table = module.Precompute( 558 query_function=module.DefineQueryFunction( 559 name='Response error ratio', 560 expression=( 561 (m.Fetch( 562 m.Raw('monarch.BorgTask', 563 '/corp/travel/trips2/dispatcher/email/response'), { 564 'borg_job': module_config.job, 565 'metric:response_type': 'SUCCESS' 566 }), 567 m.Fetch( 568 m.Raw('monarch.BorgTask', 569 '/corp/travel/trips2/dispatcher/email/response'), 570 {'borg_job': module_config.job})) 571 | m.Window(m.Delta('1h')) 572 | m.Join('successes', 'total') 573 | m.Point(m.VAL['successes'] / m.VAL['total'])))) 574""" 575 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 576 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 577 578 def testB30394228(self): 579 code = """\ 580class _(): 581 582 def _(self): 583 return some.randome.function.calling( 584 wf, None, alert.Format(alert.subject, alert=alert, threshold=threshold), 585 alert.Format(alert.body, alert=alert, threshold=threshold), 586 alert.html_formatting) 587""" 588 llines = yapf_test_helper.ParseAndUnwrap(code) 589 self.assertCodeEqual(code, reformatter.Reformat(llines)) 590 591 def testB65246454(self): 592 unformatted_code = """\ 593class _(): 594 595 def _(self): 596 self.assertEqual({i.id 597 for i in successful_instances}, 598 {i.id 599 for i in self._statuses.successful_instances}) 600""" 601 expected_formatted_code = """\ 602class _(): 603 604 def _(self): 605 self.assertEqual({i.id for i in successful_instances}, 606 {i.id for i in self._statuses.successful_instances}) 607""" 608 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 609 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 610 611 def testB67935450(self): 612 unformatted_code = """\ 613def _(): 614 return ( 615 (Gauge( 616 metric='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 617 group_by=group_by + ['metric:process_name'], 618 metric_filter={'metric:process_name': process_name_re}), 619 Gauge( 620 metric='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 621 group_by=group_by + ['metric:process_name'], 622 metric_filter={'metric:process_name': process_name_re})) 623 | expr.Join( 624 left_name='start', left_default=0, right_name='end', right_default=0) 625 | m.Point( 626 m.Cond(m.VAL['end'] != 0, m.VAL['end'], k.TimestampMicros() / 627 1000000L) - m.Cond(m.VAL['start'] != 0, m.VAL['start'], 628 m.TimestampMicros() / 1000000L))) 629""" 630 expected_formatted_code = """\ 631def _(): 632 return ( 633 (Gauge( 634 metric='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 635 group_by=group_by + ['metric:process_name'], 636 metric_filter={'metric:process_name': process_name_re}), 637 Gauge( 638 metric='bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 639 group_by=group_by + ['metric:process_name'], 640 metric_filter={'metric:process_name': process_name_re})) 641 | expr.Join( 642 left_name='start', left_default=0, right_name='end', right_default=0) 643 | m.Point( 644 m.Cond(m.VAL['end'] != 0, m.VAL['end'], 645 k.TimestampMicros() / 1000000L) - 646 m.Cond(m.VAL['start'] != 0, m.VAL['start'], 647 m.TimestampMicros() / 1000000L))) 648""" 649 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 650 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 651 652 def testB66011084(self): 653 unformatted_code = """\ 654X = { 655"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": # Comment 1. 656([] if True else [ # Comment 2. 657 "bbbbbbbbbbbbbbbbbbb", # Comment 3. 658 "cccccccccccccccccccccccc", # Comment 4. 659 "ddddddddddddddddddddddddd", # Comment 5. 660 "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", # Comment 6. 661 "fffffffffffffffffffffffffffffff", # Comment 7. 662 "ggggggggggggggggggggggggggg", # Comment 8. 663 "hhhhhhhhhhhhhhhhhh", # Comment 9. 664]), 665} 666""" 667 expected_formatted_code = """\ 668X = { 669 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": # Comment 1. 670 ([] if True else [ # Comment 2. 671 "bbbbbbbbbbbbbbbbbbb", # Comment 3. 672 "cccccccccccccccccccccccc", # Comment 4. 673 "ddddddddddddddddddddddddd", # Comment 5. 674 "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", # Comment 6. 675 "fffffffffffffffffffffffffffffff", # Comment 7. 676 "ggggggggggggggggggggggggggg", # Comment 8. 677 "hhhhhhhhhhhhhhhhhh", # Comment 9. 678 ]), 679} 680""" 681 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 682 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 683 684 def testB67455376(self): 685 unformatted_code = """\ 686sponge_ids.extend(invocation.id() for invocation in self._client.GetInvocationsByLabels(labels)) 687""" # noqa 688 expected_formatted_code = """\ 689sponge_ids.extend(invocation.id() 690 for invocation in self._client.GetInvocationsByLabels(labels)) 691""" 692 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 693 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 694 695 def testB35210351(self): 696 unformatted_code = """\ 697def _(): 698 config.AnotherRuleThing( 699 'the_title_to_the_thing_here', 700 {'monitorname': 'firefly', 701 'service': ACCOUNTING_THING, 702 'severity': 'the_bug', 703 'monarch_module_name': alerts.TheLabel(qa_module_regexp, invert=True)}, 704 fanout, 705 alerts.AlertUsToSomething( 706 GetTheAlertToIt('the_title_to_the_thing_here'), 707 GetNotificationTemplate('your_email_here'))) 708""" 709 expected_formatted_code = """\ 710def _(): 711 config.AnotherRuleThing( 712 'the_title_to_the_thing_here', { 713 'monitorname': 'firefly', 714 'service': ACCOUNTING_THING, 715 'severity': 'the_bug', 716 'monarch_module_name': alerts.TheLabel(qa_module_regexp, invert=True) 717 }, fanout, 718 alerts.AlertUsToSomething( 719 GetTheAlertToIt('the_title_to_the_thing_here'), 720 GetNotificationTemplate('your_email_here'))) 721""" 722 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 723 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 724 725 def testB34774905(self): 726 unformatted_code = """\ 727x=[VarExprType(ir_name=IrName( value='x', 728expr_type=UnresolvedAttrExprType( atom=UnknownExprType(), attr_name=IrName( 729 value='x', expr_type=UnknownExprType(), usage='UNKNOWN', fqn=None, 730 astn=None), usage='REF'), usage='ATTR', fqn='<attr>.x', astn=None))] 731""" 732 expected_formatted_code = """\ 733x = [ 734 VarExprType( 735 ir_name=IrName( 736 value='x', 737 expr_type=UnresolvedAttrExprType( 738 atom=UnknownExprType(), 739 attr_name=IrName( 740 value='x', 741 expr_type=UnknownExprType(), 742 usage='UNKNOWN', 743 fqn=None, 744 astn=None), 745 usage='REF'), 746 usage='ATTR', 747 fqn='<attr>.x', 748 astn=None)) 749] 750""" 751 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 752 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 753 754 def testB65176185(self): 755 code = """\ 756xx = zip(*[(a, b) for (a, b, c) in yy]) 757""" 758 llines = yapf_test_helper.ParseAndUnwrap(code) 759 self.assertCodeEqual(code, reformatter.Reformat(llines)) 760 761 def testB35210166(self): 762 unformatted_code = """\ 763def _(): 764 query = ( 765 m.Fetch(n.Raw('monarch.BorgTask', '/proc/container/memory/usage'), { 'borg_user': borguser, 'borg_job': jobname }) 766 | o.Window(m.Align('5m')) | p.GroupBy(['borg_user', 'borg_job', 'borg_cell'], q.Mean())) 767""" # noqa 768 expected_formatted_code = """\ 769def _(): 770 query = ( 771 m.Fetch( 772 n.Raw('monarch.BorgTask', '/proc/container/memory/usage'), { 773 'borg_user': borguser, 774 'borg_job': jobname 775 }) 776 | o.Window(m.Align('5m')) 777 | p.GroupBy(['borg_user', 'borg_job', 'borg_cell'], q.Mean())) 778""" 779 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 780 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 781 782 def testB32167774(self): 783 unformatted_code = """\ 784X = ( 785 'is_official', 786 'is_cover', 787 'is_remix', 788 'is_instrumental', 789 'is_live', 790 'has_lyrics', 791 'is_album', 792 'is_compilation',) 793""" 794 expected_formatted_code = """\ 795X = ( 796 'is_official', 797 'is_cover', 798 'is_remix', 799 'is_instrumental', 800 'is_live', 801 'has_lyrics', 802 'is_album', 803 'is_compilation', 804) 805""" 806 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 807 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 808 809 def testB66912275(self): 810 unformatted_code = """\ 811def _(): 812 with self.assertRaisesRegexp(errors.HttpError, 'Invalid'): 813 patch_op = api_client.forwardingRules().patch( 814 project=project_id, 815 region=region, 816 forwardingRule=rule_name, 817 body={'fingerprint': base64.urlsafe_b64encode('invalid_fingerprint')}).execute() 818""" # noqa 819 expected_formatted_code = """\ 820def _(): 821 with self.assertRaisesRegexp(errors.HttpError, 'Invalid'): 822 patch_op = api_client.forwardingRules().patch( 823 project=project_id, 824 region=region, 825 forwardingRule=rule_name, 826 body={ 827 'fingerprint': base64.urlsafe_b64encode('invalid_fingerprint') 828 }).execute() 829""" 830 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 831 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 832 833 def testB67312284(self): 834 code = """\ 835def _(): 836 self.assertEqual( 837 [u'to be published 2', u'to be published 1', u'to be published 0'], 838 [el.text for el in page.first_column_tds]) 839""" 840 llines = yapf_test_helper.ParseAndUnwrap(code) 841 self.assertCodeEqual(code, reformatter.Reformat(llines)) 842 843 def testB65241516(self): 844 unformatted_code = """\ 845checkpoint_files = gfile.Glob(os.path.join(TrainTraceDir(unit_key, "*", "*"), embedding_model.CHECKPOINT_FILENAME + "-*")) 846""" # noqa 847 expected_formatted_code = """\ 848checkpoint_files = gfile.Glob( 849 os.path.join( 850 TrainTraceDir(unit_key, "*", "*"), 851 embedding_model.CHECKPOINT_FILENAME + "-*")) 852""" 853 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 854 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 855 856 def testB37460004(self): 857 code = textwrap.dedent("""\ 858 assert all(s not in (_SENTINEL, None) for s in nested_schemas 859 ), 'Nested schemas should never contain None/_SENTINEL' 860 """) 861 llines = yapf_test_helper.ParseAndUnwrap(code) 862 self.assertCodeEqual(code, reformatter.Reformat(llines)) 863 864 def testB36806207(self): 865 code = """\ 866def _(): 867 linearity_data = [[row] for row in [ 868 "%.1f mm" % (np.mean(linearity_values["pos_error"]) * 1000.0), 869 "%.1f mm" % (np.max(linearity_values["pos_error"]) * 1000.0), 870 "%.1f mm" % (np.mean(linearity_values["pos_error_chunk_mean"]) * 1000.0), 871 "%.1f mm" % (np.max(linearity_values["pos_error_chunk_max"]) * 1000.0), 872 "%.1f deg" % math.degrees(np.mean(linearity_values["rot_noise"])), 873 "%.1f deg" % math.degrees(np.max(linearity_values["rot_noise"])), 874 "%.1f deg" % math.degrees(np.mean(linearity_values["rot_drift"])), 875 "%.1f deg" % math.degrees(np.max(linearity_values["rot_drift"])), 876 "%.1f%%" % (np.max(linearity_values["pos_discontinuity"]) * 100.0), 877 "%.1f%%" % (np.max(linearity_values["rot_discontinuity"]) * 100.0) 878 ]] 879""" 880 llines = yapf_test_helper.ParseAndUnwrap(code) 881 self.assertCodeEqual(code, reformatter.Reformat(llines)) 882 883 def testB36215507(self): 884 code = textwrap.dedent("""\ 885 class X(): 886 887 def _(): 888 aaaaaaaaaaaaa._bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb( 889 mmmmmmmmmmmmm, nnnnn, ooooooooo, 890 _(ppppppppppppppppppppppppppppppppppppp), 891 *(qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq), 892 **(qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq)) 893 """) 894 llines = yapf_test_helper.ParseAndUnwrap(code) 895 self.assertCodeEqual(code, reformatter.Reformat(llines)) 896 897 def testB35212469(self): 898 unformatted_code = textwrap.dedent("""\ 899 def _(): 900 X = { 901 'retain': { 902 'loadtest': # This is a comment in the middle of a dictionary entry 903 ('/some/path/to/a/file/that/is/needed/by/this/process') 904 } 905 } 906 """) # noqa 907 expected_formatted_code = textwrap.dedent("""\ 908 def _(): 909 X = { 910 'retain': { 911 'loadtest': # This is a comment in the middle of a dictionary entry 912 ('/some/path/to/a/file/that/is/needed/by/this/process') 913 } 914 } 915 """) # noqa 916 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 917 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 918 919 def testB31063453(self): 920 unformatted_code = textwrap.dedent("""\ 921 def _(): 922 while ((not mpede_proc) or ((time_time() - last_modified) < FLAGS_boot_idle_timeout)): 923 pass 924 """) # noqa 925 expected_formatted_code = textwrap.dedent("""\ 926 def _(): 927 while ((not mpede_proc) or 928 ((time_time() - last_modified) < FLAGS_boot_idle_timeout)): 929 pass 930 """) 931 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 932 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 933 934 def testB35021894(self): 935 unformatted_code = textwrap.dedent("""\ 936 def _(): 937 labelacl = Env(qa={ 938 'read': 'name/some-type-of-very-long-name-for-reading-perms', 939 'modify': 'name/some-other-type-of-very-long-name-for-modifying' 940 }, 941 prod={ 942 'read': 'name/some-type-of-very-long-name-for-reading-perms', 943 'modify': 'name/some-other-type-of-very-long-name-for-modifying' 944 }) 945 """) # noqa 946 expected_formatted_code = textwrap.dedent("""\ 947 def _(): 948 labelacl = Env( 949 qa={ 950 'read': 'name/some-type-of-very-long-name-for-reading-perms', 951 'modify': 'name/some-other-type-of-very-long-name-for-modifying' 952 }, 953 prod={ 954 'read': 'name/some-type-of-very-long-name-for-reading-perms', 955 'modify': 'name/some-other-type-of-very-long-name-for-modifying' 956 }) 957 """) # noqa 958 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 959 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 960 961 def testB34682902(self): 962 unformatted_code = textwrap.dedent("""\ 963 logging.info("Mean angular velocity norm: %.3f", np.linalg.norm(np.mean(ang_vel_arr, axis=0))) 964 """) # noqa 965 expected_formatted_code = textwrap.dedent("""\ 966 logging.info("Mean angular velocity norm: %.3f", 967 np.linalg.norm(np.mean(ang_vel_arr, axis=0))) 968 """) 969 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 970 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 971 972 def testB33842726(self): 973 unformatted_code = textwrap.dedent("""\ 974 class _(): 975 def _(): 976 hints.append(('hg tag -f -l -r %s %s # %s' % (short(ctx.node( 977 )), candidatetag, firstline))[:78]) 978 """) 979 expected_formatted_code = textwrap.dedent("""\ 980 class _(): 981 def _(): 982 hints.append(('hg tag -f -l -r %s %s # %s' % 983 (short(ctx.node()), candidatetag, firstline))[:78]) 984 """) 985 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 986 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 987 988 def testB32931780(self): 989 unformatted_code = textwrap.dedent("""\ 990 environments = { 991 'prod': { 992 # this is a comment before the first entry. 993 'entry one': 994 'an entry.', 995 # this is the comment before the second entry. 996 'entry number 2.': 997 'something', 998 # this is the comment before the third entry and it's a doozy. So big! 999 'who': 1000 'allin', 1001 # This is an entry that has a dictionary in it. It's ugly 1002 'something': { 1003 'page': ['[email protected]', '[email protected]'], 1004 'bug': ['[email protected]'], 1005 'email': ['[email protected]'], 1006 }, 1007 # a short comment 1008 'yolo!!!!!': 1009 '[email protected]', 1010 # this entry has an implicit string concatenation 1011 'implicit': 1012 'https://this-is-very-long.url-addr.com/' 1013 '?something=something%20some%20more%20stuff..', 1014 # A more normal entry. 1015 '.....': 1016 'this is an entry', 1017 } 1018 } 1019 """) # noqa 1020 expected_formatted_code = textwrap.dedent("""\ 1021 environments = { 1022 'prod': { 1023 # this is a comment before the first entry. 1024 'entry one': 'an entry.', 1025 # this is the comment before the second entry. 1026 'entry number 2.': 'something', 1027 # this is the comment before the third entry and it's a doozy. So big! 1028 'who': 'allin', 1029 # This is an entry that has a dictionary in it. It's ugly 1030 'something': { 1031 'page': [ 1032 '[email protected]', '[email protected]' 1033 ], 1034 'bug': ['[email protected]'], 1035 'email': ['[email protected]'], 1036 }, 1037 # a short comment 1038 'yolo!!!!!': '[email protected]', 1039 # this entry has an implicit string concatenation 1040 'implicit': 'https://this-is-very-long.url-addr.com/' 1041 '?something=something%20some%20more%20stuff..', 1042 # A more normal entry. 1043 '.....': 'this is an entry', 1044 } 1045 } 1046 """) # noqa 1047 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1048 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1049 1050 def testB33047408(self): 1051 code = textwrap.dedent("""\ 1052 def _(): 1053 for sort in (sorts or []): 1054 request['sorts'].append({ 1055 'field': { 1056 'user_field': sort 1057 }, 1058 'order': 'ASCENDING' 1059 }) 1060 """) 1061 llines = yapf_test_helper.ParseAndUnwrap(code) 1062 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1063 1064 def testB32714745(self): 1065 code = textwrap.dedent("""\ 1066 class _(): 1067 1068 def _BlankDefinition(): 1069 '''Return a generic blank dictionary for a new field.''' 1070 return { 1071 'type': '', 1072 'validation': '', 1073 'name': 'fieldname', 1074 'label': 'Field Label', 1075 'help': '', 1076 'initial': '', 1077 'required': False, 1078 'required_msg': 'Required', 1079 'invalid_msg': 'Please enter a valid value', 1080 'options': { 1081 'regex': '', 1082 'widget_attr': '', 1083 'choices_checked': '', 1084 'choices_count': '', 1085 'choices': {} 1086 }, 1087 'isnew': True, 1088 'dirty': False, 1089 } 1090 """) 1091 llines = yapf_test_helper.ParseAndUnwrap(code) 1092 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1093 1094 def testB32737279(self): 1095 unformatted_code = textwrap.dedent("""\ 1096 here_is_a_dict = { 1097 'key': 1098 # Comment. 1099 'value' 1100 } 1101 """) 1102 expected_formatted_code = textwrap.dedent("""\ 1103 here_is_a_dict = { 1104 'key': # Comment. 1105 'value' 1106 } 1107 """) 1108 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1109 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1110 1111 def testB32570937(self): 1112 code = textwrap.dedent("""\ 1113 def _(): 1114 if (job_message.ball not in ('*', ball) or 1115 job_message.call not in ('*', call) or 1116 job_message.mall not in ('*', job_name)): 1117 return False 1118 """) 1119 llines = yapf_test_helper.ParseAndUnwrap(code) 1120 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1121 1122 def testB31937033(self): 1123 code = textwrap.dedent("""\ 1124 class _(): 1125 1126 def __init__(self, metric, fields_cb=None): 1127 self._fields_cb = fields_cb or (lambda *unused_args, **unused_kwargs: {}) 1128 """) # noqa 1129 llines = yapf_test_helper.ParseAndUnwrap(code) 1130 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1131 1132 def testB31911533(self): 1133 code = """\ 1134class _(): 1135 1136 @parameterized.NamedParameters( 1137 ('IncludingModInfoWithHeaderList', AAAA, aaaa), 1138 ('IncludingModInfoWithoutHeaderList', BBBB, bbbbb), 1139 ('ExcludingModInfoWithHeaderList', CCCCC, cccc), 1140 ('ExcludingModInfoWithoutHeaderList', DDDDD, ddddd), 1141 ) 1142 def _(): 1143 pass 1144""" 1145 llines = yapf_test_helper.ParseAndUnwrap(code) 1146 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1147 1148 def testB31847238(self): 1149 unformatted_code = textwrap.dedent("""\ 1150 class _(): 1151 1152 def aaaaa(self, bbbbb, cccccccccccccc=None): # TODO(who): pylint: disable=unused-argument 1153 return 1 1154 1155 def xxxxx(self, yyyyy, zzzzzzzzzzzzzz=None): # A normal comment that runs over the column limit. 1156 return 1 1157 """) # noqa 1158 expected_formatted_code = textwrap.dedent("""\ 1159 class _(): 1160 1161 def aaaaa(self, bbbbb, cccccccccccccc=None): # TODO(who): pylint: disable=unused-argument 1162 return 1 1163 1164 def xxxxx( 1165 self, 1166 yyyyy, 1167 zzzzzzzzzzzzzz=None): # A normal comment that runs over the column limit. 1168 return 1 1169 """) # noqa 1170 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1171 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1172 1173 def testB30760569(self): 1174 unformatted_code = textwrap.dedent("""\ 1175 {'1234567890123456789012345678901234567890123456789012345678901234567890': 1176 '1234567890123456789012345678901234567890'} 1177 """) # noqa 1178 expected_formatted_code = textwrap.dedent("""\ 1179 { 1180 '1234567890123456789012345678901234567890123456789012345678901234567890': 1181 '1234567890123456789012345678901234567890' 1182 } 1183 """) # noqa 1184 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1185 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1186 1187 def testB26034238(self): 1188 unformatted_code = textwrap.dedent("""\ 1189 class Thing: 1190 1191 def Function(self): 1192 thing.Scrape('/aaaaaaaaa/bbbbbbbbbb/ccccc/dddd/eeeeeeeeeeeeee/ffffffffffffff').AndReturn(42) 1193 """) # noqa 1194 expected_formatted_code = textwrap.dedent("""\ 1195 class Thing: 1196 1197 def Function(self): 1198 thing.Scrape( 1199 '/aaaaaaaaa/bbbbbbbbbb/ccccc/dddd/eeeeeeeeeeeeee/ffffffffffffff' 1200 ).AndReturn(42) 1201 """) 1202 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1203 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1204 1205 def testB30536435(self): 1206 unformatted_code = textwrap.dedent("""\ 1207 def main(unused_argv): 1208 if True: 1209 if True: 1210 aaaaaaaaaaa.comment('import-from[{}] {} {}'.format( 1211 bbbbbbbbb.usage, 1212 ccccccccc.within, 1213 imports.ddddddddddddddddddd(name_item.ffffffffffffffff))) 1214 """) 1215 expected_formatted_code = textwrap.dedent("""\ 1216 def main(unused_argv): 1217 if True: 1218 if True: 1219 aaaaaaaaaaa.comment('import-from[{}] {} {}'.format( 1220 bbbbbbbbb.usage, ccccccccc.within, 1221 imports.ddddddddddddddddddd(name_item.ffffffffffffffff))) 1222 """) 1223 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1224 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1225 1226 def testB30442148(self): 1227 unformatted_code = textwrap.dedent("""\ 1228 def lulz(): 1229 return (some_long_module_name.SomeLongClassName. 1230 some_long_attribute_name.some_long_method_name()) 1231 """) 1232 expected_formatted_code = textwrap.dedent("""\ 1233 def lulz(): 1234 return (some_long_module_name.SomeLongClassName.some_long_attribute_name 1235 .some_long_method_name()) 1236 """) # noqa 1237 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1238 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1239 1240 def testB26868213(self): 1241 unformatted_code = textwrap.dedent("""\ 1242 def _(): 1243 xxxxxxxxxxxxxxxxxxx = { 1244 'ssssss': {'ddddd': 'qqqqq', 1245 'p90': aaaaaaaaaaaaaaaaa, 1246 'p99': bbbbbbbbbbbbbbbbb, 1247 'lllllllllllll': yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy(),}, 1248 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb': { 1249 'ddddd': 'bork bork bork bo', 1250 'p90': wwwwwwwwwwwwwwwww, 1251 'p99': wwwwwwwwwwwwwwwww, 1252 'lllllllllllll': None, # use the default 1253 } 1254 } 1255 """) # noqa 1256 expected_formatted_code = textwrap.dedent("""\ 1257 def _(): 1258 xxxxxxxxxxxxxxxxxxx = { 1259 'ssssss': { 1260 'ddddd': 'qqqqq', 1261 'p90': aaaaaaaaaaaaaaaaa, 1262 'p99': bbbbbbbbbbbbbbbbb, 1263 'lllllllllllll': yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy(), 1264 }, 1265 'bbbbbbbbbbbbbbbbbbbbbbbbbbbb': { 1266 'ddddd': 'bork bork bork bo', 1267 'p90': wwwwwwwwwwwwwwwww, 1268 'p99': wwwwwwwwwwwwwwwww, 1269 'lllllllllllll': None, # use the default 1270 } 1271 } 1272 """) 1273 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1274 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1275 1276 def testB30173198(self): 1277 code = textwrap.dedent("""\ 1278 class _(): 1279 1280 def _(): 1281 self.assertFalse( 1282 evaluation_runner.get_larps_in_eval_set('these_arent_the_larps')) 1283 """) # noqa 1284 llines = yapf_test_helper.ParseAndUnwrap(code) 1285 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1286 1287 def testB29908765(self): 1288 code = textwrap.dedent("""\ 1289 class _(): 1290 1291 def __repr__(self): 1292 return '<session %s on %s>' % ( 1293 self._id, self._stub._stub.rpc_channel().target()) # pylint:disable=protected-access 1294 """) # noqa 1295 llines = yapf_test_helper.ParseAndUnwrap(code) 1296 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1297 1298 def testB30087362(self): 1299 code = textwrap.dedent("""\ 1300 def _(): 1301 for s in sorted(env['foo']): 1302 bar() 1303 # This is a comment 1304 1305 # This is another comment 1306 foo() 1307 """) 1308 llines = yapf_test_helper.ParseAndUnwrap(code) 1309 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1310 1311 def testB30087363(self): 1312 code = textwrap.dedent("""\ 1313 if False: 1314 bar() 1315 # This is a comment 1316 # This is another comment 1317 elif True: 1318 foo() 1319 """) 1320 llines = yapf_test_helper.ParseAndUnwrap(code) 1321 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1322 1323 def testB29093579(self): 1324 unformatted_code = textwrap.dedent("""\ 1325 def _(): 1326 _xxxxxxxxxxxxxxx(aaaaaaaa, bbbbbbbbbbbbbb.cccccccccc[ 1327 dddddddddddddddddddddddddddd.eeeeeeeeeeeeeeeeeeeeee.fffffffffffffffffffff]) 1328 """) # noqa 1329 expected_formatted_code = textwrap.dedent("""\ 1330 def _(): 1331 _xxxxxxxxxxxxxxx( 1332 aaaaaaaa, 1333 bbbbbbbbbbbbbb.cccccccccc[dddddddddddddddddddddddddddd 1334 .eeeeeeeeeeeeeeeeeeeeee.fffffffffffffffffffff]) 1335 """) # noqa 1336 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1337 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1338 1339 def testB26382315(self): 1340 code = textwrap.dedent("""\ 1341 @hello_world 1342 # This is a first comment 1343 1344 # Comment 1345 def foo(): 1346 pass 1347 """) 1348 llines = yapf_test_helper.ParseAndUnwrap(code) 1349 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1350 1351 def testB27616132(self): 1352 unformatted_code = textwrap.dedent("""\ 1353 if True: 1354 query.fetch_page.assert_has_calls([ 1355 mock.call(100, 1356 start_cursor=None), 1357 mock.call(100, 1358 start_cursor=cursor_1), 1359 mock.call(100, 1360 start_cursor=cursor_2), 1361 ]) 1362 """) 1363 expected_formatted_code = textwrap.dedent("""\ 1364 if True: 1365 query.fetch_page.assert_has_calls([ 1366 mock.call(100, start_cursor=None), 1367 mock.call(100, start_cursor=cursor_1), 1368 mock.call(100, start_cursor=cursor_2), 1369 ]) 1370 """) 1371 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1372 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1373 1374 def testB27590179(self): 1375 unformatted_code = textwrap.dedent("""\ 1376 if True: 1377 if True: 1378 self.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = ( 1379 { True: 1380 self.bbb.cccccccccc(ddddddddddddddddddddddd.eeeeeeeeeeeeeeeeeeeeee), 1381 False: 1382 self.bbb.cccccccccc(ddddddddddddddddddddddd.eeeeeeeeeeeeeeeeeeeeee) 1383 }) 1384 """) # noqa 1385 expected_formatted_code = textwrap.dedent("""\ 1386 if True: 1387 if True: 1388 self.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = ({ 1389 True: 1390 self.bbb.cccccccccc(ddddddddddddddddddddddd.eeeeeeeeeeeeeeeeeeeeee), 1391 False: 1392 self.bbb.cccccccccc(ddddddddddddddddddddddd.eeeeeeeeeeeeeeeeeeeeee) 1393 }) 1394 """) # noqa 1395 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1396 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1397 1398 def testB27266946(self): 1399 unformatted_code = textwrap.dedent("""\ 1400 def _(): 1401 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = (self.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.cccccccccccccccccccccccccccccccccccc) 1402 """) # noqa 1403 expected_formatted_code = textwrap.dedent("""\ 1404 def _(): 1405 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = ( 1406 self.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 1407 .cccccccccccccccccccccccccccccccccccc) 1408 """) 1409 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1410 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1411 1412 def testB25505359(self): 1413 code = textwrap.dedent("""\ 1414 _EXAMPLE = { 1415 'aaaaaaaaaaaaaa': [{ 1416 'bbbb': 'cccccccccccccccccccccc', 1417 'dddddddddddd': [] 1418 }, { 1419 'bbbb': 'ccccccccccccccccccc', 1420 'dddddddddddd': [] 1421 }] 1422 } 1423 """) 1424 llines = yapf_test_helper.ParseAndUnwrap(code) 1425 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1426 1427 def testB25324261(self): 1428 code = textwrap.dedent("""\ 1429 aaaaaaaaa = set(bbbb.cccc 1430 for ddd in eeeeee.fffffffffff.gggggggggggggggg 1431 for cccc in ddd.specification) 1432 """) 1433 llines = yapf_test_helper.ParseAndUnwrap(code) 1434 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1435 1436 def testB25136704(self): 1437 code = textwrap.dedent("""\ 1438 class f: 1439 1440 def test(self): 1441 self.bbbbbbb[0]['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', { 1442 'xxxxxx': 'yyyyyy' 1443 }] = cccccc.ddd('1m', '10x1+1') 1444 """) 1445 llines = yapf_test_helper.ParseAndUnwrap(code) 1446 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1447 1448 def testB25165602(self): 1449 code = textwrap.dedent("""\ 1450 def f(): 1451 ids = {u: i for u, i in zip(self.aaaaa, xrange(42, 42 + len(self.aaaaaa)))} 1452 """) # noqa 1453 llines = yapf_test_helper.ParseAndUnwrap(code) 1454 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1455 1456 def testB25157123(self): 1457 code = textwrap.dedent("""\ 1458 def ListArgs(): 1459 FairlyLongMethodName([relatively_long_identifier_for_a_list], 1460 another_argument_with_a_long_identifier) 1461 """) 1462 llines = yapf_test_helper.ParseAndUnwrap(code) 1463 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1464 1465 def testB25136820(self): 1466 unformatted_code = textwrap.dedent("""\ 1467 def foo(): 1468 return collections.OrderedDict({ 1469 # Preceding comment. 1470 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 1471 '$bbbbbbbbbbbbbbbbbbbbbbbb', 1472 }) 1473 """) 1474 expected_formatted_code = textwrap.dedent("""\ 1475 def foo(): 1476 return collections.OrderedDict({ 1477 # Preceding comment. 1478 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa': 1479 '$bbbbbbbbbbbbbbbbbbbbbbbb', 1480 }) 1481 """) 1482 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1483 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1484 1485 def testB25131481(self): 1486 unformatted_code = textwrap.dedent("""\ 1487 APPARENT_ACTIONS = ('command_type', { 1488 'materialize': lambda x: some_type_of_function('materialize ' + x.command_def), 1489 '#': lambda x: x # do nothing 1490 }) 1491 """) # noqa 1492 expected_formatted_code = textwrap.dedent("""\ 1493 APPARENT_ACTIONS = ( 1494 'command_type', 1495 { 1496 'materialize': 1497 lambda x: some_type_of_function('materialize ' + x.command_def), 1498 '#': 1499 lambda x: x # do nothing 1500 }) 1501 """) # noqa 1502 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1503 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1504 1505 def testB23445244(self): 1506 unformatted_code = textwrap.dedent("""\ 1507 def foo(): 1508 if True: 1509 return xxxxxxxxxxxxxxxx( 1510 command, 1511 extra_env={ 1512 "OOOOOOOOOOOOOOOOOOOOO": FLAGS.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, 1513 "PPPPPPPPPPPPPPPPPPPPP": 1514 FLAGS.aaaaaaaaaaaaaa + FLAGS.bbbbbbbbbbbbbbbbbbb, 1515 }) 1516 """) # noqa 1517 expected_formatted_code = textwrap.dedent("""\ 1518 def foo(): 1519 if True: 1520 return xxxxxxxxxxxxxxxx( 1521 command, 1522 extra_env={ 1523 "OOOOOOOOOOOOOOOOOOOOO": 1524 FLAGS.zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz, 1525 "PPPPPPPPPPPPPPPPPPPPP": 1526 FLAGS.aaaaaaaaaaaaaa + FLAGS.bbbbbbbbbbbbbbbbbbb, 1527 }) 1528 """) # noqa 1529 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1530 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1531 1532 def testB20559654(self): 1533 unformatted_code = textwrap.dedent("""\ 1534 class A(object): 1535 1536 def foo(self): 1537 unused_error, result = server.Query( 1538 ['AA BBBB CCC DDD EEEEEEEE X YY ZZZZ FFF EEE AAAAAAAA'], 1539 aaaaaaaaaaa=True, bbbbbbbb=None) 1540 """) 1541 expected_formatted_code = textwrap.dedent("""\ 1542 class A(object): 1543 1544 def foo(self): 1545 unused_error, result = server.Query( 1546 ['AA BBBB CCC DDD EEEEEEEE X YY ZZZZ FFF EEE AAAAAAAA'], 1547 aaaaaaaaaaa=True, 1548 bbbbbbbb=None) 1549 """) 1550 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1551 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1552 1553 def testB23943842(self): 1554 unformatted_code = textwrap.dedent("""\ 1555 class F(): 1556 def f(): 1557 self.assertDictEqual( 1558 accounts, { 1559 'foo': 1560 {'account': 'foo', 1561 'lines': 'l1\\nl2\\nl3\\n1 line(s) were elided.'}, 1562 'bar': {'account': 'bar', 1563 'lines': 'l5\\nl6\\nl7'}, 1564 'wiz': {'account': 'wiz', 1565 'lines': 'l8'} 1566 }) 1567 """) 1568 expected_formatted_code = textwrap.dedent("""\ 1569 class F(): 1570 1571 def f(): 1572 self.assertDictEqual( 1573 accounts, { 1574 'foo': { 1575 'account': 'foo', 1576 'lines': 'l1\\nl2\\nl3\\n1 line(s) were elided.' 1577 }, 1578 'bar': { 1579 'account': 'bar', 1580 'lines': 'l5\\nl6\\nl7' 1581 }, 1582 'wiz': { 1583 'account': 'wiz', 1584 'lines': 'l8' 1585 } 1586 }) 1587 """) 1588 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1589 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1590 1591 def testB20551180(self): 1592 unformatted_code = textwrap.dedent("""\ 1593 def foo(): 1594 if True: 1595 return (struct.pack('aaaa', bbbbbbbbbb, ccccccccccccccc, dddddddd) + eeeeeee) 1596 """) # noqa 1597 expected_formatted_code = textwrap.dedent("""\ 1598 def foo(): 1599 if True: 1600 return (struct.pack('aaaa', bbbbbbbbbb, ccccccccccccccc, dddddddd) + 1601 eeeeeee) 1602 """) 1603 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1604 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1605 1606 def testB23944849(self): 1607 unformatted_code = textwrap.dedent("""\ 1608 class A(object): 1609 def xxxxxxxxx(self, aaaaaaa, bbbbbbb=ccccccccccc, dddddd=300, eeeeeeeeeeeeee=None, fffffffffffffff=0): 1610 pass 1611 """) # noqa 1612 expected_formatted_code = textwrap.dedent("""\ 1613 class A(object): 1614 1615 def xxxxxxxxx(self, 1616 aaaaaaa, 1617 bbbbbbb=ccccccccccc, 1618 dddddd=300, 1619 eeeeeeeeeeeeee=None, 1620 fffffffffffffff=0): 1621 pass 1622 """) 1623 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1624 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1625 1626 def testB23935890(self): 1627 unformatted_code = textwrap.dedent("""\ 1628 class F(): 1629 def functioni(self, aaaaaaa, bbbbbbb, cccccc, dddddddddddddd, eeeeeeeeeeeeeee): 1630 pass 1631 """) # noqa 1632 expected_formatted_code = textwrap.dedent("""\ 1633 class F(): 1634 1635 def functioni(self, aaaaaaa, bbbbbbb, cccccc, dddddddddddddd, 1636 eeeeeeeeeeeeeee): 1637 pass 1638 """) 1639 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1640 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1641 1642 def testB28414371(self): 1643 code = textwrap.dedent("""\ 1644 def _(): 1645 return ((m.fffff( 1646 m.rrr('mmmmmmmmmmmmmmmm', 'ssssssssssssssssssssssssss'), ffffffffffffffff) 1647 | m.wwwwww(m.ddddd('1h')) 1648 | m.ggggggg(bbbbbbbbbbbbbbb) 1649 | m.ppppp( 1650 (1 - m.ffffffffffffffff(llllllllllllllllllllll * 1000000, m.vvv)) 1651 * m.ddddddddddddddddd(m.vvv)), 1652 m.fffff( 1653 m.rrr('mmmmmmmmmmmmmmmm', 'sssssssssssssssssssssss'), 1654 dict( 1655 ffffffffffffffff, **{ 1656 'mmmmmm:ssssss': 1657 m.rrrrrrrrrrr('|'.join(iiiiiiiiiiiiii), iiiiii=True) 1658 })) 1659 | m.wwwwww(m.rrrr('1h')) 1660 | m.ggggggg(bbbbbbbbbbbbbbb)) 1661 | m.jjjj() 1662 | m.ppppp(m.vvv[0] + m.vvv[1])) 1663 """) # noqa 1664 llines = yapf_test_helper.ParseAndUnwrap(code) 1665 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1666 1667 def testB20127686(self): 1668 code = textwrap.dedent("""\ 1669 def f(): 1670 if True: 1671 return ((m.fffff( 1672 m.rrr('xxxxxxxxxxxxxxxx', 1673 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'), 1674 mmmmmmmm) 1675 | m.wwwwww(m.rrrr(self.tttttttttt, self.mmmmmmmmmmmmmmmmmmmmm)) 1676 | m.ggggggg(self.gggggggg, m.sss()), m.fffff('aaaaaaaaaaaaaaaa') 1677 | m.wwwwww(m.ddddd(self.tttttttttt, self.mmmmmmmmmmmmmmmmmmmmm)) 1678 | m.ggggggg(self.gggggggg)) 1679 | m.jjjj() 1680 | m.ppppp(m.VAL[0] / m.VAL[1])) 1681 """) # noqa 1682 llines = yapf_test_helper.ParseAndUnwrap(code) 1683 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1684 1685 def testB20016122(self): 1686 unformatted_code = textwrap.dedent("""\ 1687 from a_very_long_or_indented_module_name_yada_yada import (long_argument_1, 1688 long_argument_2) 1689 """) # noqa 1690 expected_formatted_code = textwrap.dedent("""\ 1691 from a_very_long_or_indented_module_name_yada_yada import ( 1692 long_argument_1, long_argument_2) 1693 """) 1694 1695 try: 1696 style.SetGlobalStyle( 1697 style.CreateStyleFromConfig( 1698 '{based_on_style: pep8, split_penalty_import_names: 350}')) 1699 1700 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1701 self.assertCodeEqual(expected_formatted_code, 1702 reformatter.Reformat(llines)) 1703 finally: 1704 style.SetGlobalStyle(style.CreatePEP8Style()) 1705 1706 code = textwrap.dedent("""\ 1707 class foo(): 1708 1709 def __eq__(self, other): 1710 return (isinstance(other, type(self)) 1711 and self.xxxxxxxxxxx == other.xxxxxxxxxxx 1712 and self.xxxxxxxx == other.xxxxxxxx 1713 and self.aaaaaaaaaaaa == other.aaaaaaaaaaaa 1714 and self.bbbbbbbbbbb == other.bbbbbbbbbbb 1715 and self.ccccccccccccccccc == other.ccccccccccccccccc 1716 and self.ddddddddddddddddddddddd == other.ddddddddddddddddddddddd 1717 and self.eeeeeeeeeeee == other.eeeeeeeeeeee 1718 and self.ffffffffffffff == other.time_completed 1719 and self.gggggg == other.gggggg and self.hhh == other.hhh 1720 and len(self.iiiiiiii) == len(other.iiiiiiii) 1721 and all(jjjjjjj in other.iiiiiiii for jjjjjjj in self.iiiiiiii)) 1722 """) # noqa 1723 1724 try: 1725 style.SetGlobalStyle( 1726 style.CreateStyleFromConfig('{based_on_style: yapf, ' 1727 'split_before_logical_operator: True}')) 1728 1729 llines = yapf_test_helper.ParseAndUnwrap(code) 1730 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1731 finally: 1732 style.SetGlobalStyle(style.CreateYapfStyle()) 1733 1734 def testB22527411(self): 1735 unformatted_code = textwrap.dedent("""\ 1736 def f(): 1737 if True: 1738 aaaaaa.bbbbbbbbbbbbbbbbbbbb[-1].cccccccccccccc.ddd().eeeeeeee(ffffffffffffff) 1739 """) # noqa 1740 expected_formatted_code = textwrap.dedent("""\ 1741 def f(): 1742 if True: 1743 aaaaaa.bbbbbbbbbbbbbbbbbbbb[-1].cccccccccccccc.ddd().eeeeeeee( 1744 ffffffffffffff) 1745 """) 1746 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1747 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1748 1749 def testB20849933(self): 1750 unformatted_code = textwrap.dedent("""\ 1751 def main(unused_argv): 1752 if True: 1753 aaaaaaaa = { 1754 'xxx': '%s/cccccc/ddddddddddddddddddd.jar' % 1755 (eeeeee.FFFFFFFFFFFFFFFFFF), 1756 } 1757 """) 1758 expected_formatted_code = textwrap.dedent("""\ 1759 def main(unused_argv): 1760 if True: 1761 aaaaaaaa = { 1762 'xxx': 1763 '%s/cccccc/ddddddddddddddddddd.jar' % (eeeeee.FFFFFFFFFFFFFFFFFF), 1764 } 1765 """) # noqa 1766 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1767 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1768 1769 def testB20813997(self): 1770 code = textwrap.dedent("""\ 1771 def myfunc_1(): 1772 myarray = numpy.zeros((2, 2, 2)) 1773 print(myarray[:, 1, :]) 1774 """) 1775 llines = yapf_test_helper.ParseAndUnwrap(code) 1776 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1777 1778 def testB20605036(self): 1779 code = textwrap.dedent("""\ 1780 foo = { 1781 'aaaa': { 1782 # A comment for no particular reason. 1783 'xxxxxxxx': 'bbbbbbbbb', 1784 'yyyyyyyyyyyyyyyyyy': 'cccccccccccccccccccccccccccccc' 1785 'dddddddddddddddddddddddddddddddddddddddddd', 1786 } 1787 } 1788 """) # noqa 1789 llines = yapf_test_helper.ParseAndUnwrap(code) 1790 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1791 1792 def testB20562732(self): 1793 code = textwrap.dedent("""\ 1794 foo = [ 1795 # Comment about first list item 1796 'First item', 1797 # Comment about second list item 1798 'Second item', 1799 ] 1800 """) 1801 llines = yapf_test_helper.ParseAndUnwrap(code) 1802 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1803 1804 def testB20128830(self): 1805 code = textwrap.dedent("""\ 1806 a = { 1807 'xxxxxxxxxxxxxxxxxxxx': { 1808 'aaaa': 1809 'mmmmmmm', 1810 'bbbbb': 1811 'mmmmmmmmmmmmmmmmmmmmm', 1812 'cccccccccc': [ 1813 'nnnnnnnnnnn', 1814 'ooooooooooo', 1815 'ppppppppppp', 1816 'qqqqqqqqqqq', 1817 ], 1818 }, 1819 } 1820 """) 1821 llines = yapf_test_helper.ParseAndUnwrap(code) 1822 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1823 1824 def testB20073838(self): 1825 code = textwrap.dedent("""\ 1826 class DummyModel(object): 1827 1828 def do_nothing(self, class_1_count): 1829 if True: 1830 class_0_count = num_votes - class_1_count 1831 return ('{class_0_name}={class_0_count}, {class_1_name}={class_1_count}' 1832 .format( 1833 class_0_name=self.class_0_name, 1834 class_0_count=class_0_count, 1835 class_1_name=self.class_1_name, 1836 class_1_count=class_1_count)) 1837 """) # noqa 1838 llines = yapf_test_helper.ParseAndUnwrap(code) 1839 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1840 1841 def testB19626808(self): 1842 code = textwrap.dedent("""\ 1843 if True: 1844 aaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbb( 1845 'ccccccccccc', ddddddddd='eeeee').fffffffff([ggggggggggggggggggggg]) 1846 """) # noqa 1847 llines = yapf_test_helper.ParseAndUnwrap(code) 1848 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1849 1850 def testB19547210(self): 1851 code = textwrap.dedent("""\ 1852 while True: 1853 if True: 1854 if True: 1855 if True: 1856 if xxxxxxxxxxxx.yyyyyyy(aa).zzzzzzz() not in ( 1857 xxxxxxxxxxxx.yyyyyyyyyyyyyy.zzzzzzzz, 1858 xxxxxxxxxxxx.yyyyyyyyyyyyyy.zzzzzzzz): 1859 continue 1860 """) 1861 llines = yapf_test_helper.ParseAndUnwrap(code) 1862 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1863 1864 def testB19377034(self): 1865 code = textwrap.dedent("""\ 1866 def f(): 1867 if (aaaaaaaaaaaaaaa.start >= aaaaaaaaaaaaaaa.end or 1868 bbbbbbbbbbbbbbb.start >= bbbbbbbbbbbbbbb.end): 1869 return False 1870 """) 1871 llines = yapf_test_helper.ParseAndUnwrap(code) 1872 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1873 1874 def testB19372573(self): 1875 code = textwrap.dedent("""\ 1876 def f(): 1877 if a: return 42 1878 while True: 1879 if b: continue 1880 if c: break 1881 return 0 1882 """) 1883 1884 try: 1885 style.SetGlobalStyle(style.CreatePEP8Style()) 1886 1887 llines = yapf_test_helper.ParseAndUnwrap(code) 1888 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1889 finally: 1890 style.SetGlobalStyle(style.CreateYapfStyle()) 1891 1892 def testB19353268(self): 1893 code = textwrap.dedent("""\ 1894 a = {1, 2, 3}[x] 1895 b = {'foo': 42, 'bar': 37}['foo'] 1896 """) 1897 llines = yapf_test_helper.ParseAndUnwrap(code) 1898 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1899 1900 def testB19287512(self): 1901 unformatted_code = textwrap.dedent("""\ 1902 class Foo(object): 1903 1904 def bar(self): 1905 with xxxxxxxxxx.yyyyy( 1906 'aaaaaaa.bbbbbbbb.ccccccc.dddddddddddddddddddd.eeeeeeeeeee', 1907 fffffffffff=(aaaaaaa.bbbbbbbb.ccccccc.dddddddddddddddddddd 1908 .Mmmmmmmmmmmmmmmmmm(-1, 'permission error'))): 1909 self.assertRaises(nnnnnnnnnnnnnnnn.ooooo, ppppp.qqqqqqqqqqqqqqqqq) 1910 """) # noqa 1911 expected_formatted_code = textwrap.dedent("""\ 1912 class Foo(object): 1913 1914 def bar(self): 1915 with xxxxxxxxxx.yyyyy( 1916 'aaaaaaa.bbbbbbbb.ccccccc.dddddddddddddddddddd.eeeeeeeeeee', 1917 fffffffffff=( 1918 aaaaaaa.bbbbbbbb.ccccccc.dddddddddddddddddddd.Mmmmmmmmmmmmmmmmmm( 1919 -1, 'permission error'))): 1920 self.assertRaises(nnnnnnnnnnnnnnnn.ooooo, ppppp.qqqqqqqqqqqqqqqqq) 1921 """) # noqa 1922 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 1923 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 1924 1925 def testB19194420(self): 1926 code = textwrap.dedent("""\ 1927 method.Set( 1928 'long argument goes here that causes the line to break', 1929 lambda arg2=0.5: arg2) 1930 """) 1931 llines = yapf_test_helper.ParseAndUnwrap(code) 1932 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1933 1934 def testB19073499(self): 1935 code = """\ 1936instance = ( 1937 aaaaaaa.bbbbbbb().ccccccccccccccccc().ddddddddddd({ 1938 'aa': 'context!' 1939 }).eeeeeeeeeeeeeeeeeee({ # Inline comment about why fnord has the value 6. 1940 'fnord': 6 1941 })) 1942""" 1943 llines = yapf_test_helper.ParseAndUnwrap(code) 1944 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1945 1946 def testB18257115(self): 1947 code = textwrap.dedent("""\ 1948 if True: 1949 if True: 1950 self._Test(aaaa, bbbbbbb.cccccccccc, dddddddd, eeeeeeeeeee, 1951 [ffff, ggggggggggg, hhhhhhhhhhhh, iiiiii, jjjj]) 1952 """) 1953 llines = yapf_test_helper.ParseAndUnwrap(code) 1954 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1955 1956 def testB18256666(self): 1957 code = textwrap.dedent("""\ 1958 class Foo(object): 1959 1960 def Bar(self): 1961 aaaaa.bbbbbbb( 1962 ccc='ddddddddddddddd', 1963 eeee='ffffffffffffffffffffff-%s-%s' % (gggg, int(time.time())), 1964 hhhhhh={ 1965 'iiiiiiiiiii': iiiiiiiiiii, 1966 'jjjj': jjjj.jjjjj(), 1967 'kkkkkkkkkkkk': kkkkkkkkkkkk, 1968 }, 1969 llllllllll=mmmmmm.nnnnnnnnnnnnnnnn) 1970 """) 1971 llines = yapf_test_helper.ParseAndUnwrap(code) 1972 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1973 1974 def testB18256826(self): 1975 code = textwrap.dedent("""\ 1976 if True: 1977 pass 1978 # A multiline comment. 1979 # Line two. 1980 elif False: 1981 pass 1982 1983 if True: 1984 pass 1985 # A multiline comment. 1986 # Line two. 1987 elif False: 1988 pass 1989 """) 1990 llines = yapf_test_helper.ParseAndUnwrap(code) 1991 self.assertCodeEqual(code, reformatter.Reformat(llines)) 1992 1993 def testB18255697(self): 1994 code = textwrap.dedent("""\ 1995 AAAAAAAAAAAAAAA = { 1996 'XXXXXXXXXXXXXX': 4242, # Inline comment 1997 # Next comment 1998 'YYYYYYYYYYYYYYYY': ['zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'], 1999 } 2000 """) 2001 llines = yapf_test_helper.ParseAndUnwrap(code) 2002 self.assertCodeEqual(code, reformatter.Reformat(llines)) 2003 2004 def testB17534869(self): 2005 unformatted_code = textwrap.dedent("""\ 2006 if True: 2007 self.assertLess(abs(time.time()-aaaa.bbbbbbbbbbb( 2008 datetime.datetime.now())), 1) 2009 """) 2010 expected_formatted_code = textwrap.dedent("""\ 2011 if True: 2012 self.assertLess( 2013 abs(time.time() - aaaa.bbbbbbbbbbb(datetime.datetime.now())), 1) 2014 """) 2015 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2016 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2017 2018 def testB17489866(self): 2019 unformatted_code = textwrap.dedent("""\ 2020 def f(): 2021 if True: 2022 if True: 2023 return aaaa.bbbbbbbbb(ccccccc=dddddddddddddd({('eeee', \ 2024'ffffffff'): str(j)})) 2025 """) 2026 expected_formatted_code = textwrap.dedent("""\ 2027 def f(): 2028 if True: 2029 if True: 2030 return aaaa.bbbbbbbbb( 2031 ccccccc=dddddddddddddd({('eeee', 'ffffffff'): str(j)})) 2032 """) 2033 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2034 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2035 2036 def testB17133019(self): 2037 unformatted_code = textwrap.dedent("""\ 2038 class aaaaaaaaaaaaaa(object): 2039 2040 def bbbbbbbbbb(self): 2041 with io.open("/dev/null", "rb"): 2042 with io.open(os.path.join(aaaaa.bbbbb.ccccccccccc, 2043 DDDDDDDDDDDDDDD, 2044 "eeeeeeeee ffffffffff" 2045 ), "rb") as gggggggggggggggggggg: 2046 print(gggggggggggggggggggg) 2047 """) 2048 expected_formatted_code = textwrap.dedent("""\ 2049 class aaaaaaaaaaaaaa(object): 2050 2051 def bbbbbbbbbb(self): 2052 with io.open("/dev/null", "rb"): 2053 with io.open( 2054 os.path.join(aaaaa.bbbbb.ccccccccccc, DDDDDDDDDDDDDDD, 2055 "eeeeeeeee ffffffffff"), "rb") as gggggggggggggggggggg: 2056 print(gggggggggggggggggggg) 2057 """) # noqa 2058 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2059 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2060 2061 def testB17011869(self): 2062 unformatted_code = textwrap.dedent("""\ 2063 '''blah......''' 2064 2065 class SomeClass(object): 2066 '''blah.''' 2067 2068 AAAAAAAAAAAA = { # Comment. 2069 'BBB': 1.0, 2070 'DDDDDDDD': 0.4811 2071 } 2072 """) 2073 expected_formatted_code = textwrap.dedent("""\ 2074 '''blah......''' 2075 2076 2077 class SomeClass(object): 2078 '''blah.''' 2079 2080 AAAAAAAAAAAA = { # Comment. 2081 'BBB': 1.0, 2082 'DDDDDDDD': 0.4811 2083 } 2084 """) 2085 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2086 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2087 2088 def testB16783631(self): 2089 unformatted_code = textwrap.dedent("""\ 2090 if True: 2091 with aaaaaaaaaaaaaa.bbbbbbbbbbbbb.ccccccc(ddddddddddddd, 2092 eeeeeeeee=self.fffffffffffff 2093 )as gggg: 2094 pass 2095 """) # noqa 2096 expected_formatted_code = textwrap.dedent("""\ 2097 if True: 2098 with aaaaaaaaaaaaaa.bbbbbbbbbbbbb.ccccccc( 2099 ddddddddddddd, eeeeeeeee=self.fffffffffffff) as gggg: 2100 pass 2101 """) 2102 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2103 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2104 2105 def testB16572361(self): 2106 unformatted_code = textwrap.dedent("""\ 2107 def foo(self): 2108 def bar(my_dict_name): 2109 self.my_dict_name['foo-bar-baz-biz-boo-baa-baa'].IncrementBy.assert_called_once_with('foo_bar_baz_boo') 2110 """) # noqa 2111 expected_formatted_code = textwrap.dedent("""\ 2112 def foo(self): 2113 2114 def bar(my_dict_name): 2115 self.my_dict_name[ 2116 'foo-bar-baz-biz-boo-baa-baa'].IncrementBy.assert_called_once_with( 2117 'foo_bar_baz_boo') 2118 """) # noqa 2119 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2120 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2121 2122 def testB15884241(self): 2123 unformatted_code = textwrap.dedent("""\ 2124 if 1: 2125 if 1: 2126 for row in AAAA: 2127 self.create(aaaaaaaa="/aaa/bbbb/cccc/dddddd/eeeeeeeeeeeeeeeeeeeeeeeeee/%s" % row [0].replace(".foo", ".bar"), aaaaa=bbb[1], ccccc=bbb[2], dddd=bbb[3], eeeeeeeeeee=[s.strip() for s in bbb[4].split(",")], ffffffff=[s.strip() for s in bbb[5].split(",")], gggggg=bbb[6]) 2128 """) # noqa 2129 expected_formatted_code = textwrap.dedent("""\ 2130 if 1: 2131 if 1: 2132 for row in AAAA: 2133 self.create( 2134 aaaaaaaa="/aaa/bbbb/cccc/dddddd/eeeeeeeeeeeeeeeeeeeeeeeeee/%s" % 2135 row[0].replace(".foo", ".bar"), 2136 aaaaa=bbb[1], 2137 ccccc=bbb[2], 2138 dddd=bbb[3], 2139 eeeeeeeeeee=[s.strip() for s in bbb[4].split(",")], 2140 ffffffff=[s.strip() for s in bbb[5].split(",")], 2141 gggggg=bbb[6]) 2142 """) # noqa 2143 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2144 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2145 2146 def testB15697268(self): 2147 unformatted_code = textwrap.dedent("""\ 2148 def main(unused_argv): 2149 ARBITRARY_CONSTANT_A = 10 2150 an_array_with_an_exceedingly_long_name = range(ARBITRARY_CONSTANT_A + 1) 2151 ok = an_array_with_an_exceedingly_long_name[:ARBITRARY_CONSTANT_A] 2152 bad_slice = map(math.sqrt, an_array_with_an_exceedingly_long_name[:ARBITRARY_CONSTANT_A]) 2153 a_long_name_slicing = an_array_with_an_exceedingly_long_name[:ARBITRARY_CONSTANT_A] 2154 bad_slice = ("I am a crazy, no good, string what's too long, etc." + " no really ")[:ARBITRARY_CONSTANT_A] 2155 """) # noqa 2156 expected_formatted_code = textwrap.dedent("""\ 2157 def main(unused_argv): 2158 ARBITRARY_CONSTANT_A = 10 2159 an_array_with_an_exceedingly_long_name = range(ARBITRARY_CONSTANT_A + 1) 2160 ok = an_array_with_an_exceedingly_long_name[:ARBITRARY_CONSTANT_A] 2161 bad_slice = map(math.sqrt, 2162 an_array_with_an_exceedingly_long_name[:ARBITRARY_CONSTANT_A]) 2163 a_long_name_slicing = an_array_with_an_exceedingly_long_name[: 2164 ARBITRARY_CONSTANT_A] 2165 bad_slice = ("I am a crazy, no good, string what's too long, etc." + 2166 " no really ")[:ARBITRARY_CONSTANT_A] 2167 """) # noqa 2168 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2169 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2170 2171 def testB15597568(self): 2172 unformatted_code = """\ 2173if True: 2174 if True: 2175 if True: 2176 print(("Return code was %d" + (", and the process timed out." if did_time_out else ".")) % errorcode) 2177""" # noqa 2178 expected_formatted_code = """\ 2179if True: 2180 if True: 2181 if True: 2182 print(("Return code was %d" + 2183 (", and the process timed out." if did_time_out else ".")) % 2184 errorcode) 2185""" 2186 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2187 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2188 2189 def testB15542157(self): 2190 unformatted_code = textwrap.dedent("""\ 2191 aaaaaaaaaaaa = bbbb.ccccccccccccccc(dddddd.eeeeeeeeeeeeee, ffffffffffffffffff, gggggg.hhhhhhhhhhhhhhhhh) 2192 """) # noqa 2193 expected_formatted_code = textwrap.dedent("""\ 2194 aaaaaaaaaaaa = bbbb.ccccccccccccccc(dddddd.eeeeeeeeeeeeee, ffffffffffffffffff, 2195 gggggg.hhhhhhhhhhhhhhhhh) 2196 """) # noqa 2197 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2198 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2199 2200 def testB15438132(self): 2201 unformatted_code = textwrap.dedent("""\ 2202 if aaaaaaa.bbbbbbbbbb: 2203 cccccc.dddddddddd(eeeeeeeeeee=fffffffffffff.gggggggggggggggggg) 2204 if hhhhhh.iiiii.jjjjjjjjjjjjj: 2205 # This is a comment in the middle of it all. 2206 kkkkkkk.llllllllll.mmmmmmmmmmmmm = True 2207 if (aaaaaa.bbbbb.ccccccccccccc != ddddddd.eeeeeeeeee.fffffffffffff or 2208 eeeeee.fffff.ggggggggggggggggggggggggggg() != hhhhhhh.iiiiiiiiii.jjjjjjjjjjjj): 2209 aaaaaaaa.bbbbbbbbbbbb( 2210 aaaaaa.bbbbb.cc, 2211 dddddddddddd=eeeeeeeeeeeeeeeeeee.fffffffffffffffff( 2212 gggggg.hh, 2213 iiiiiiiiiiiiiiiiiii.jjjjjjjjjj.kkkkkkk, 2214 lllll.mm), 2215 nnnnnnnnnn=ooooooo.pppppppppp) 2216 """) # noqa 2217 expected_formatted_code = textwrap.dedent("""\ 2218 if aaaaaaa.bbbbbbbbbb: 2219 cccccc.dddddddddd(eeeeeeeeeee=fffffffffffff.gggggggggggggggggg) 2220 if hhhhhh.iiiii.jjjjjjjjjjjjj: 2221 # This is a comment in the middle of it all. 2222 kkkkkkk.llllllllll.mmmmmmmmmmmmm = True 2223 if (aaaaaa.bbbbb.ccccccccccccc != ddddddd.eeeeeeeeee.fffffffffffff or 2224 eeeeee.fffff.ggggggggggggggggggggggggggg() != 2225 hhhhhhh.iiiiiiiiii.jjjjjjjjjjjj): 2226 aaaaaaaa.bbbbbbbbbbbb( 2227 aaaaaa.bbbbb.cc, 2228 dddddddddddd=eeeeeeeeeeeeeeeeeee.fffffffffffffffff( 2229 gggggg.hh, iiiiiiiiiiiiiiiiiii.jjjjjjjjjj.kkkkkkk, lllll.mm), 2230 nnnnnnnnnn=ooooooo.pppppppppp) 2231 """) # noqa 2232 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2233 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2234 2235 def testB14468247(self): 2236 unformatted_code = """\ 2237call(a=1, 2238 b=2, 2239) 2240""" 2241 expected_formatted_code = """\ 2242call( 2243 a=1, 2244 b=2, 2245) 2246""" 2247 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2248 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2249 2250 def testB14406499(self): 2251 unformatted_code = textwrap.dedent("""\ 2252 def foo1(parameter_1, parameter_2, parameter_3, parameter_4, \ 2253parameter_5, parameter_6): pass 2254 """) 2255 expected_formatted_code = textwrap.dedent("""\ 2256 def foo1(parameter_1, parameter_2, parameter_3, parameter_4, parameter_5, 2257 parameter_6): 2258 pass 2259 """) # noqa 2260 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2261 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2262 2263 def testB13900309(self): 2264 unformatted_code = textwrap.dedent("""\ 2265 self.aaaaaaaaaaa( # A comment in the middle of it all. 2266 948.0/3600, self.bbb.ccccccccccccccccccccc(dddddddddddddddd.eeee, True)) 2267 """) # noqa 2268 expected_formatted_code = textwrap.dedent("""\ 2269 self.aaaaaaaaaaa( # A comment in the middle of it all. 2270 948.0 / 3600, self.bbb.ccccccccccccccccccccc(dddddddddddddddd.eeee, True)) 2271 """) # noqa 2272 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2273 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2274 2275 code = textwrap.dedent("""\ 2276 aaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbb.cccccccccccccccccccccccccccccc( 2277 DC_1, (CL - 50, CL), AAAAAAAA, BBBBBBBBBBBBBBBB, 98.0, 2278 CCCCCCC).ddddddddd( # Look! A comment is here. 2279 AAAAAAAA - (20 * 60 - 5)) 2280 """) 2281 llines = yapf_test_helper.ParseAndUnwrap(code) 2282 self.assertCodeEqual(code, reformatter.Reformat(llines)) 2283 2284 unformatted_code = textwrap.dedent("""\ 2285 aaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbb.ccccccccccccccccccccccccc().dddddddddddddddddddddddddd(1, 2, 3, 4) 2286 """) # noqa 2287 expected_formatted_code = textwrap.dedent("""\ 2288 aaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbb.ccccccccccccccccccccccccc( 2289 ).dddddddddddddddddddddddddd(1, 2, 3, 4) 2290 """) 2291 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2292 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2293 2294 unformatted_code = textwrap.dedent("""\ 2295 aaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbb.ccccccccccccccccccccccccc(x).dddddddddddddddddddddddddd(1, 2, 3, 4) 2296 """) # noqa 2297 expected_formatted_code = textwrap.dedent("""\ 2298 aaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbb.ccccccccccccccccccccccccc( 2299 x).dddddddddddddddddddddddddd(1, 2, 3, 4) 2300 """) 2301 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2302 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2303 2304 unformatted_code = textwrap.dedent("""\ 2305 aaaaaaaaaaaaaaaaaaaaaaaa(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx).dddddddddddddddddddddddddd(1, 2, 3, 4) 2306 """) # noqa 2307 expected_formatted_code = textwrap.dedent("""\ 2308 aaaaaaaaaaaaaaaaaaaaaaaa( 2309 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx).dddddddddddddddddddddddddd(1, 2, 3, 4) 2310 """) # noqa 2311 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2312 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2313 2314 unformatted_code = textwrap.dedent("""\ 2315 aaaaaaaaaaaaaaaaaaaaaaaa().bbbbbbbbbbbbbbbbbbbbbbbb().ccccccccccccccccccc().\ 2316dddddddddddddddddd().eeeeeeeeeeeeeeeeeeeee().fffffffffffffffff().gggggggggggggggggg() 2317 """) 2318 expected_formatted_code = textwrap.dedent("""\ 2319 aaaaaaaaaaaaaaaaaaaaaaaa().bbbbbbbbbbbbbbbbbbbbbbbb().ccccccccccccccccccc( 2320 ).dddddddddddddddddd().eeeeeeeeeeeeeeeeeeeee().fffffffffffffffff( 2321 ).gggggggggggggggggg() 2322 """) 2323 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2324 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2325 2326 def testB67935687(self): 2327 code = textwrap.dedent("""\ 2328 Fetch( 2329 Raw('monarch.BorgTask', '/union/row_operator_action_delay'), 2330 {'borg_user': self.borg_user}) 2331 """) 2332 llines = yapf_test_helper.ParseAndUnwrap(code) 2333 self.assertCodeEqual(code, reformatter.Reformat(llines)) 2334 2335 unformatted_code = textwrap.dedent("""\ 2336 shelf_renderer.expand_text = text.translate_to_unicode( 2337 expand_text % { 2338 'creator': creator 2339 }) 2340 """) 2341 expected_formatted_code = textwrap.dedent("""\ 2342 shelf_renderer.expand_text = text.translate_to_unicode(expand_text % 2343 {'creator': creator}) 2344 """) # noqa 2345 llines = yapf_test_helper.ParseAndUnwrap(unformatted_code) 2346 self.assertCodeEqual(expected_formatted_code, reformatter.Reformat(llines)) 2347 2348 2349if __name__ == '__main__': 2350 unittest.main() 2351