Conditions | 1 |
Total Lines | 433 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
278 | def gen_context_data_inputs_expected(): |
||
279 | # Extra field ignored |
||
280 | context_with_valid_extra_0 = ( |
||
281 | { |
||
282 | 'context_file': 'tests/test-generate-context-v2/test.json', |
||
283 | 'extra_context': [ |
||
284 | { |
||
285 | 'name': 'email', |
||
286 | 'default': '[email protected]', |
||
287 | 'description': 'Enter jazzy email...', |
||
288 | 'extra_field': 'extra_field_value', |
||
289 | } |
||
290 | ] |
||
291 | }, |
||
292 | { |
||
293 | "test": OrderedDict([ |
||
294 | ("name", "cookiecutter-pytest-plugin"), |
||
295 | ("cookiecutter_version", "2.0.0"), |
||
296 | ("variables", [ |
||
297 | OrderedDict([ |
||
298 | ("name", "full_name"), |
||
299 | ("default", "J. Paul Getty"), |
||
300 | ("prompt", "What's your full name?"), |
||
301 | ("description", "Please enter your full name. It will be displayed on the README file and used for the PyPI package definition."), |
||
302 | ("type", "string")]), |
||
303 | OrderedDict([ |
||
304 | ("name", "email"), |
||
305 | ("default", "[email protected]"), |
||
306 | ("prompt", "What's your email?"), |
||
307 | ("description", "Enter jazzy email..."), |
||
308 | ("type", "string")]), |
||
309 | ]) |
||
310 | ]) |
||
311 | } |
||
312 | ) |
||
313 | # Empty extra context precipitates no ill effect |
||
314 | context_with_valid_extra_1 = ( |
||
315 | { |
||
316 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
317 | 'extra_context': [] |
||
318 | # 'extra_context': [ |
||
319 | # { |
||
320 | # 'name': 'email', |
||
321 | # 'default': '[email protected]', |
||
322 | # 'description': 'Enter jazzy email...', |
||
323 | # 'extra_field': 'extra_field_value', |
||
324 | # } |
||
325 | # ] |
||
326 | }, |
||
327 | { |
||
328 | "representative": OrderedDict([ |
||
329 | ("name", "cc-representative"), |
||
330 | ("cookiecutter_version", "2.0.0"), |
||
331 | ("variables", [ |
||
332 | OrderedDict([ |
||
333 | ("name", "director_credit"), |
||
334 | ("default", True), |
||
335 | ("prompt", "Is there a director credit on this film?"), |
||
336 | ("description", "Directors take credit for most of their films, usually..."), |
||
337 | ("type", "boolean") |
||
338 | ]), |
||
339 | OrderedDict([ |
||
340 | ("name", "director_name"), |
||
341 | ("default", "Allan Smithe"), |
||
342 | ("prompt", "What's the Director's full name?"), |
||
343 | ("prompt_user", True), |
||
344 | ("description", "The default director is not proud of their work, we hope you are."), |
||
345 | ("hide_input", False), |
||
346 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
347 | ("validation", "^[a-z][A-Z]+$"), |
||
348 | ("validation_flags", ["verbose", "ascii"]), |
||
349 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
350 | ("type", "string") |
||
351 | ]) |
||
352 | ]) |
||
353 | ]) |
||
354 | } |
||
355 | ) |
||
356 | |||
357 | # Test the ability to change the variable's name field (since it is used |
||
358 | # to identify the variable to be modifed) with extra context and to remove |
||
359 | # a key from the context via the removal token: '<<ACTION::REMOVE>>' |
||
360 | context_with_valid_extra_2 = ( |
||
361 | { |
||
362 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
363 | 'extra_context': [ |
||
364 | { |
||
365 | 'name': 'director_credit::producer_credit', |
||
366 | 'prompt': 'Is there a producer credit on this film?', |
||
367 | 'description': 'There are usually a lot of producers...', |
||
368 | }, |
||
369 | { |
||
370 | 'name': 'director_name', |
||
371 | 'skip_if': '<<REMOVE::FIELD>>', |
||
372 | }, |
||
373 | |||
374 | ] |
||
375 | }, |
||
376 | { |
||
377 | "representative": OrderedDict([ |
||
378 | ("name", "cc-representative"), |
||
379 | ("cookiecutter_version", "2.0.0"), |
||
380 | ("variables", [ |
||
381 | OrderedDict([ |
||
382 | ("name", "producer_credit"), |
||
383 | ("default", True), |
||
384 | ("prompt", "Is there a producer credit on this film?"), |
||
385 | ("description", "There are usually a lot of producers..."), |
||
386 | ("type", "boolean") |
||
387 | ]), |
||
388 | OrderedDict([ |
||
389 | ("name", "director_name"), |
||
390 | ("default", "Allan Smithe"), |
||
391 | ("prompt", "What's the Director's full name?"), |
||
392 | ("prompt_user", True), |
||
393 | ("description", "The default director is not proud of their work, we hope you are."), |
||
394 | ("hide_input", False), |
||
395 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
396 | ("validation", "^[a-z][A-Z]+$"), |
||
397 | ("validation_flags", ["verbose", "ascii"]), |
||
398 | ("type", "string") |
||
399 | ]) |
||
400 | ]) |
||
401 | ]) |
||
402 | } |
||
403 | ) |
||
404 | # Test the ability to change the variable's name field (since it is used |
||
405 | # to identify the variable to be modifed) with extra context and to also |
||
406 | # test that any other references in other variables that might use the |
||
407 | # original variable name get updated as well. |
||
408 | context_with_valid_extra_2_B = ( |
||
409 | { |
||
410 | 'context_file': 'tests/test-generate-context-v2/representative_2B.json', |
||
411 | 'extra_context': [ |
||
412 | { |
||
413 | 'name': 'director_credit::producer_credit', |
||
414 | 'prompt': 'Is there a producer credit on this film?', |
||
415 | 'description': 'There are usually a lot of producers...', |
||
416 | }, |
||
417 | ] |
||
418 | }, |
||
419 | { |
||
420 | "representative_2B": OrderedDict([ |
||
421 | ("name", "cc-representative"), |
||
422 | ("cookiecutter_version", "2.0.0"), |
||
423 | ("variables", [ |
||
424 | OrderedDict([ |
||
425 | ("name", "producer_credit"), |
||
426 | ("default", True), |
||
427 | ("prompt", "Is there a producer credit on this film?"), |
||
428 | ("description", "There are usually a lot of producers..."), |
||
429 | ("type", "boolean") |
||
430 | ]), |
||
431 | OrderedDict([ |
||
432 | ("name", "director_name"), |
||
433 | ("default", "Allan Smithe"), |
||
434 | ("prompt", "What's the Director's full name?"), |
||
435 | ("prompt_user", True), |
||
436 | ("description", "The default director is not proud of their work, we hope you are."), |
||
437 | ("hide_input", False), |
||
438 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston", "{{cookiecutter.producer_credit}}"]), |
||
439 | ("validation", "^[a-z][A-Z]+$"), |
||
440 | ("validation_flags", ["verbose", "ascii"]), |
||
441 | ("skip_if", "{{cookiecutter.producer_credit == False}}"), |
||
442 | ("type", "string") |
||
443 | ]) |
||
444 | ]) |
||
445 | ]) |
||
446 | } |
||
447 | ) |
||
448 | |||
449 | # Test changing variable's name field value, default field, prompt field, |
||
450 | # and changing the type |
||
451 | context_with_valid_extra_3 = ( |
||
452 | { |
||
453 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
454 | 'extra_context': [ |
||
455 | { |
||
456 | 'name': 'director_credit::producer_credits', |
||
457 | 'default': 2, |
||
458 | 'prompt': 'How many producers does this film have?', |
||
459 | 'description': 'There are usually a lot of producers...', |
||
460 | 'type': "int", |
||
461 | } |
||
462 | ] |
||
463 | }, |
||
464 | { |
||
465 | "representative": OrderedDict([ |
||
466 | ("name", "cc-representative"), |
||
467 | ("cookiecutter_version", "2.0.0"), |
||
468 | ("variables", [ |
||
469 | OrderedDict([ |
||
470 | ("name", "producer_credits"), |
||
471 | ("default", 2), |
||
472 | ("prompt", "How many producers does this film have?"), |
||
473 | ("description", "There are usually a lot of producers..."), |
||
474 | ("type", "int") |
||
475 | ]), |
||
476 | OrderedDict([ |
||
477 | ("name", "director_name"), |
||
478 | ("default", "Allan Smithe"), |
||
479 | ("prompt", "What's the Director's full name?"), |
||
480 | ("prompt_user", True), |
||
481 | ("description", "The default director is not proud of their work, we hope you are."), |
||
482 | ("hide_input", False), |
||
483 | ("choices", ["Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
484 | ("validation", "^[a-z][A-Z]+$"), |
||
485 | ("validation_flags", ["verbose", "ascii"]), |
||
486 | ("skip_if", "{{cookiecutter.producer_credits == False}}"), |
||
487 | ("type", "string") |
||
488 | ]) |
||
489 | ]) |
||
490 | ]) |
||
491 | } |
||
492 | ) |
||
493 | # Test changing choices field without changing the default, but default |
||
494 | # does not change because the first position in choices matches default |
||
495 | context_with_valid_extra_4 = ( |
||
496 | { |
||
497 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
498 | 'extra_context': [ |
||
499 | { |
||
500 | 'name': 'director_name', |
||
501 | 'choices': ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', |
||
502 | 'John Ford', 'Billy Wilder'], |
||
503 | } |
||
504 | ] |
||
505 | }, |
||
506 | { |
||
507 | "representative": OrderedDict([ |
||
508 | ("name", "cc-representative"), |
||
509 | ("cookiecutter_version", "2.0.0"), |
||
510 | ("variables", [ |
||
511 | OrderedDict([ |
||
512 | ("name", "director_credit"), |
||
513 | ("default", True), |
||
514 | ("prompt", "Is there a director credit on this film?"), |
||
515 | ("description", "Directors take credit for most of their films, usually..."), |
||
516 | ("type", "boolean") |
||
517 | ]), |
||
518 | OrderedDict([ |
||
519 | ("name", "director_name"), |
||
520 | ("default", "Allan Smithe"), |
||
521 | ("prompt", "What's the Director's full name?"), |
||
522 | ("prompt_user", True), |
||
523 | ("description", "The default director is not proud of their work, we hope you are."), |
||
524 | ("hide_input", False), |
||
525 | ("choices", ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'John Ford', 'Billy Wilder']), |
||
526 | ("validation", "^[a-z][A-Z]+$"), |
||
527 | ("validation_flags", ["verbose", "ascii"]), |
||
528 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
529 | ("type", "string") |
||
530 | ]) |
||
531 | ]) |
||
532 | ]) |
||
533 | } |
||
534 | ) |
||
535 | # Test changing choices field and changing the default |
||
536 | context_with_valid_extra_5 = ( |
||
537 | { |
||
538 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
539 | 'extra_context': [ |
||
540 | { |
||
541 | 'name': 'director_name', |
||
542 | 'default': 'John Ford', |
||
543 | 'choices': ['Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', |
||
544 | 'John Ford', 'Billy Wilder'], |
||
545 | } |
||
546 | ] |
||
547 | }, |
||
548 | { |
||
549 | "representative": OrderedDict([ |
||
550 | ("name", "cc-representative"), |
||
551 | ("cookiecutter_version", "2.0.0"), |
||
552 | ("variables", [ |
||
553 | OrderedDict([ |
||
554 | ("name", "director_credit"), |
||
555 | ("default", True), |
||
556 | ("prompt", "Is there a director credit on this film?"), |
||
557 | ("description", "Directors take credit for most of their films, usually..."), |
||
558 | ("type", "boolean") |
||
559 | ]), |
||
560 | OrderedDict([ |
||
561 | ("name", "director_name"), |
||
562 | ("default", "John Ford"), |
||
563 | ("prompt", "What's the Director's full name?"), |
||
564 | ("prompt_user", True), |
||
565 | ("description", "The default director is not proud of their work, we hope you are."), |
||
566 | ("hide_input", False), |
||
567 | ("choices", ['John Ford', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'Billy Wilder']), |
||
568 | ("validation", "^[a-z][A-Z]+$"), |
||
569 | ("validation_flags", ["verbose", "ascii"]), |
||
570 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
571 | ("type", "string") |
||
572 | ]) |
||
573 | ]) |
||
574 | ]) |
||
575 | } |
||
576 | ) |
||
577 | # Test changing the default, but not the choices field, yet seeing choices field re-ordered |
||
578 | # to put default value in first location |
||
579 | context_with_valid_extra_6 = ( |
||
580 | { |
||
581 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
582 | 'extra_context': [ |
||
583 | { |
||
584 | 'name': 'director_name', |
||
585 | 'default': 'John Ford', |
||
586 | } |
||
587 | ] |
||
588 | }, |
||
589 | { |
||
590 | "representative": OrderedDict([ |
||
591 | ("name", "cc-representative"), |
||
592 | ("cookiecutter_version", "2.0.0"), |
||
593 | ("variables", [ |
||
594 | OrderedDict([ |
||
595 | ("name", "director_credit"), |
||
596 | ("default", True), |
||
597 | ("prompt", "Is there a director credit on this film?"), |
||
598 | ("description", "Directors take credit for most of their films, usually..."), |
||
599 | ("type", "boolean") |
||
600 | ]), |
||
601 | OrderedDict([ |
||
602 | ("name", "director_name"), |
||
603 | ("default", "John Ford"), |
||
604 | ("prompt", "What's the Director's full name?"), |
||
605 | ("prompt_user", True), |
||
606 | ("description", "The default director is not proud of their work, we hope you are."), |
||
607 | ("hide_input", False), |
||
608 | ("choices", ['John Ford', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston']), |
||
609 | ("validation", "^[a-z][A-Z]+$"), |
||
610 | ("validation_flags", ["verbose", "ascii"]), |
||
611 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
612 | ("type", "string") |
||
613 | ]) |
||
614 | ]) |
||
615 | ]) |
||
616 | } |
||
617 | ) |
||
618 | # Test changing choices field without changing the default, but default |
||
619 | # does get changee because the first position in choices field chagned |
||
620 | context_with_valid_extra_7 = ( |
||
621 | { |
||
622 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
623 | 'extra_context': [ |
||
624 | { |
||
625 | 'name': 'director_name', |
||
626 | 'choices': ['Billy Wilder', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', |
||
627 | 'John Ford'], |
||
628 | } |
||
629 | ] |
||
630 | }, |
||
631 | { |
||
632 | "representative": OrderedDict([ |
||
633 | ("name", "cc-representative"), |
||
634 | ("cookiecutter_version", "2.0.0"), |
||
635 | ("variables", [ |
||
636 | OrderedDict([ |
||
637 | ("name", "director_credit"), |
||
638 | ("default", True), |
||
639 | ("prompt", "Is there a director credit on this film?"), |
||
640 | ("description", "Directors take credit for most of their films, usually..."), |
||
641 | ("type", "boolean") |
||
642 | ]), |
||
643 | OrderedDict([ |
||
644 | ("name", "director_name"), |
||
645 | ("default", "Billy Wilder"), |
||
646 | ("prompt", "What's the Director's full name?"), |
||
647 | ("prompt_user", True), |
||
648 | ("description", "The default director is not proud of their work, we hope you are."), |
||
649 | ("hide_input", False), |
||
650 | ("choices", ['Billy Wilder', 'Allan Smithe', 'Ridley Scott', 'Victor Fleming', 'John Houston', 'John Ford']), |
||
651 | ("validation", "^[a-z][A-Z]+$"), |
||
652 | ("validation_flags", ["verbose", "ascii"]), |
||
653 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
654 | ("type", "string") |
||
655 | ]) |
||
656 | ]) |
||
657 | ]) |
||
658 | } |
||
659 | ) |
||
660 | # Test changing the default value with a value that is not in choices, |
||
661 | # we should see the choice first position get updated. |
||
662 | context_with_valid_extra_8 = ( |
||
663 | { |
||
664 | 'context_file': 'tests/test-generate-context-v2/representative.json', |
||
665 | 'extra_context': [ |
||
666 | { |
||
667 | 'name': 'director_name', |
||
668 | 'default': 'Peter Sellers', |
||
669 | } |
||
670 | ] |
||
671 | }, |
||
672 | { |
||
673 | "representative": OrderedDict([ |
||
674 | ("name", "cc-representative"), |
||
675 | ("cookiecutter_version", "2.0.0"), |
||
676 | ("variables", [ |
||
677 | OrderedDict([ |
||
678 | ("name", "director_credit"), |
||
679 | ("default", True), |
||
680 | ("prompt", "Is there a director credit on this film?"), |
||
681 | ("description", "Directors take credit for most of their films, usually..."), |
||
682 | ("type", "boolean") |
||
683 | ]), |
||
684 | OrderedDict([ |
||
685 | ("name", "director_name"), |
||
686 | ("default", "Peter Sellers"), |
||
687 | ("prompt", "What's the Director's full name?"), |
||
688 | ("prompt_user", True), |
||
689 | ("description", "The default director is not proud of their work, we hope you are."), |
||
690 | ("hide_input", False), |
||
691 | ("choices", ["Peter Sellers", "Allan Smithe", "Ridley Scott", "Victor Fleming", "John Houston"]), |
||
692 | ("validation", "^[a-z][A-Z]+$"), |
||
693 | ("validation_flags", ["verbose", "ascii"]), |
||
694 | ("skip_if", "{{cookiecutter.director_credit == False}}"), |
||
695 | ("type", "string") |
||
696 | ]) |
||
697 | ]) |
||
698 | ]) |
||
699 | } |
||
700 | ) |
||
701 | yield context_with_valid_extra_0 |
||
702 | yield context_with_valid_extra_1 |
||
703 | yield context_with_valid_extra_2 |
||
704 | yield context_with_valid_extra_2_B |
||
705 | yield context_with_valid_extra_3 |
||
706 | yield context_with_valid_extra_4 |
||
707 | yield context_with_valid_extra_5 |
||
708 | yield context_with_valid_extra_6 |
||
709 | yield context_with_valid_extra_7 |
||
710 | yield context_with_valid_extra_8 |
||
711 | |||
723 |