diff options
Diffstat (limited to 'test/automated/python-tests.el')
| -rw-r--r-- | test/automated/python-tests.el | 368 |
1 files changed, 326 insertions, 42 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index ab8eb4816d3..8462a863b84 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -444,6 +444,28 @@ objects = Thing.objects.all() \\\\ | |||
| 444 | (should (eq (car (python-indent-context)) 'after-line)) | 444 | (should (eq (car (python-indent-context)) 'after-line)) |
| 445 | (should (= (python-indent-calculate-indentation) 0)))) | 445 | (should (= (python-indent-calculate-indentation) 0)))) |
| 446 | 446 | ||
| 447 | (ert-deftest python-indent-block-enders () | ||
| 448 | "Test `python-indent-block-enders' value honoring." | ||
| 449 | (python-tests-with-temp-buffer | ||
| 450 | " | ||
| 451 | Class foo(object): | ||
| 452 | |||
| 453 | def bar(self): | ||
| 454 | if self.baz: | ||
| 455 | return (1, | ||
| 456 | 2, | ||
| 457 | 3) | ||
| 458 | |||
| 459 | else: | ||
| 460 | pass | ||
| 461 | " | ||
| 462 | (python-tests-look-at "3)") | ||
| 463 | (forward-line 1) | ||
| 464 | (= (python-indent-calculate-indentation) 12) | ||
| 465 | (python-tests-look-at "pass") | ||
| 466 | (forward-line 1) | ||
| 467 | (= (python-indent-calculate-indentation) 8))) | ||
| 468 | |||
| 447 | 469 | ||
| 448 | ;;; Navigation | 470 | ;;; Navigation |
| 449 | 471 | ||
| @@ -652,6 +674,201 @@ def decoratorFunctionWithArguments(arg1, arg2, arg3): | |||
| 652 | (python-tests-look-at "return wrapped_f") | 674 | (python-tests-look-at "return wrapped_f") |
| 653 | (line-beginning-position)))))) | 675 | (line-beginning-position)))))) |
| 654 | 676 | ||
| 677 | (ert-deftest python-nav-backward-defun-1 () | ||
| 678 | (python-tests-with-temp-buffer | ||
| 679 | " | ||
| 680 | class A(object): # A | ||
| 681 | |||
| 682 | def a(self): # a | ||
| 683 | pass | ||
| 684 | |||
| 685 | def b(self): # b | ||
| 686 | pass | ||
| 687 | |||
| 688 | class B(object): # B | ||
| 689 | |||
| 690 | class C(object): # C | ||
| 691 | |||
| 692 | def d(self): # d | ||
| 693 | pass | ||
| 694 | |||
| 695 | # def e(self): # e | ||
| 696 | # pass | ||
| 697 | |||
| 698 | def c(self): # c | ||
| 699 | pass | ||
| 700 | |||
| 701 | # def d(self): # d | ||
| 702 | # pass | ||
| 703 | " | ||
| 704 | (goto-char (point-max)) | ||
| 705 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 706 | (python-tests-look-at " def c(self): # c" -1))) | ||
| 707 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 708 | (python-tests-look-at " def d(self): # d" -1))) | ||
| 709 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 710 | (python-tests-look-at " class C(object): # C" -1))) | ||
| 711 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 712 | (python-tests-look-at " class B(object): # B" -1))) | ||
| 713 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 714 | (python-tests-look-at " def b(self): # b" -1))) | ||
| 715 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 716 | (python-tests-look-at " def a(self): # a" -1))) | ||
| 717 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 718 | (python-tests-look-at "class A(object): # A" -1))) | ||
| 719 | (should (not (python-nav-backward-defun))))) | ||
| 720 | |||
| 721 | (ert-deftest python-nav-backward-defun-2 () | ||
| 722 | (python-tests-with-temp-buffer | ||
| 723 | " | ||
| 724 | def decoratorFunctionWithArguments(arg1, arg2, arg3): | ||
| 725 | '''print decorated function call data to stdout. | ||
| 726 | |||
| 727 | Usage: | ||
| 728 | |||
| 729 | @decoratorFunctionWithArguments('arg1', 'arg2') | ||
| 730 | def func(a, b, c=True): | ||
| 731 | pass | ||
| 732 | ''' | ||
| 733 | |||
| 734 | def wwrap(f): | ||
| 735 | print 'Inside wwrap()' | ||
| 736 | def wrapped_f(*args): | ||
| 737 | print 'Inside wrapped_f()' | ||
| 738 | print 'Decorator arguments:', arg1, arg2, arg3 | ||
| 739 | f(*args) | ||
| 740 | print 'After f(*args)' | ||
| 741 | return wrapped_f | ||
| 742 | return wwrap | ||
| 743 | " | ||
| 744 | (goto-char (point-max)) | ||
| 745 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 746 | (python-tests-look-at " def wrapped_f(*args):" -1))) | ||
| 747 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 748 | (python-tests-look-at " def wwrap(f):" -1))) | ||
| 749 | (should (= (save-excursion (python-nav-backward-defun)) | ||
| 750 | (python-tests-look-at "def decoratorFunctionWithArguments(arg1, arg2, arg3):" -1))) | ||
| 751 | (should (not (python-nav-backward-defun))))) | ||
| 752 | |||
| 753 | (ert-deftest python-nav-backward-defun-3 () | ||
| 754 | (python-tests-with-temp-buffer | ||
| 755 | " | ||
| 756 | ''' | ||
| 757 | def u(self): | ||
| 758 | pass | ||
| 759 | |||
| 760 | def v(self): | ||
| 761 | pass | ||
| 762 | |||
| 763 | def w(self): | ||
| 764 | pass | ||
| 765 | ''' | ||
| 766 | |||
| 767 | class A(object): | ||
| 768 | pass | ||
| 769 | " | ||
| 770 | (goto-char (point-min)) | ||
| 771 | (let ((point (python-tests-look-at "class A(object):"))) | ||
| 772 | (should (not (python-nav-backward-defun))) | ||
| 773 | (should (= point (point)))))) | ||
| 774 | |||
| 775 | (ert-deftest python-nav-forward-defun-1 () | ||
| 776 | (python-tests-with-temp-buffer | ||
| 777 | " | ||
| 778 | class A(object): # A | ||
| 779 | |||
| 780 | def a(self): # a | ||
| 781 | pass | ||
| 782 | |||
| 783 | def b(self): # b | ||
| 784 | pass | ||
| 785 | |||
| 786 | class B(object): # B | ||
| 787 | |||
| 788 | class C(object): # C | ||
| 789 | |||
| 790 | def d(self): # d | ||
| 791 | pass | ||
| 792 | |||
| 793 | # def e(self): # e | ||
| 794 | # pass | ||
| 795 | |||
| 796 | def c(self): # c | ||
| 797 | pass | ||
| 798 | |||
| 799 | # def d(self): # d | ||
| 800 | # pass | ||
| 801 | " | ||
| 802 | (goto-char (point-min)) | ||
| 803 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 804 | (python-tests-look-at "(object): # A"))) | ||
| 805 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 806 | (python-tests-look-at "(self): # a"))) | ||
| 807 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 808 | (python-tests-look-at "(self): # b"))) | ||
| 809 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 810 | (python-tests-look-at "(object): # B"))) | ||
| 811 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 812 | (python-tests-look-at "(object): # C"))) | ||
| 813 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 814 | (python-tests-look-at "(self): # d"))) | ||
| 815 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 816 | (python-tests-look-at "(self): # c"))) | ||
| 817 | (should (not (python-nav-forward-defun))))) | ||
| 818 | |||
| 819 | (ert-deftest python-nav-forward-defun-2 () | ||
| 820 | (python-tests-with-temp-buffer | ||
| 821 | " | ||
| 822 | def decoratorFunctionWithArguments(arg1, arg2, arg3): | ||
| 823 | '''print decorated function call data to stdout. | ||
| 824 | |||
| 825 | Usage: | ||
| 826 | |||
| 827 | @decoratorFunctionWithArguments('arg1', 'arg2') | ||
| 828 | def func(a, b, c=True): | ||
| 829 | pass | ||
| 830 | ''' | ||
| 831 | |||
| 832 | def wwrap(f): | ||
| 833 | print 'Inside wwrap()' | ||
| 834 | def wrapped_f(*args): | ||
| 835 | print 'Inside wrapped_f()' | ||
| 836 | print 'Decorator arguments:', arg1, arg2, arg3 | ||
| 837 | f(*args) | ||
| 838 | print 'After f(*args)' | ||
| 839 | return wrapped_f | ||
| 840 | return wwrap | ||
| 841 | " | ||
| 842 | (goto-char (point-min)) | ||
| 843 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 844 | (python-tests-look-at "(arg1, arg2, arg3):"))) | ||
| 845 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 846 | (python-tests-look-at "(f):"))) | ||
| 847 | (should (= (save-excursion (python-nav-forward-defun)) | ||
| 848 | (python-tests-look-at "(*args):"))) | ||
| 849 | (should (not (python-nav-forward-defun))))) | ||
| 850 | |||
| 851 | (ert-deftest python-nav-forward-defun-3 () | ||
| 852 | (python-tests-with-temp-buffer | ||
| 853 | " | ||
| 854 | class A(object): | ||
| 855 | pass | ||
| 856 | |||
| 857 | ''' | ||
| 858 | def u(self): | ||
| 859 | pass | ||
| 860 | |||
| 861 | def v(self): | ||
| 862 | pass | ||
| 863 | |||
| 864 | def w(self): | ||
| 865 | pass | ||
| 866 | ''' | ||
| 867 | " | ||
| 868 | (goto-char (point-min)) | ||
| 869 | (let ((point (python-tests-look-at "(object):"))) | ||
| 870 | (should (not (python-nav-forward-defun))) | ||
| 871 | (should (= point (point)))))) | ||
| 655 | 872 | ||
| 656 | (ert-deftest python-nav-beginning-of-statement-1 () | 873 | (ert-deftest python-nav-beginning-of-statement-1 () |
| 657 | (python-tests-with-temp-buffer | 874 | (python-tests-with-temp-buffer |
| @@ -1456,66 +1673,133 @@ Using `python-shell-interpreter' and | |||
| 1456 | 1673 | ||
| 1457 | 1674 | ||
| 1458 | ;;; Imenu | 1675 | ;;; Imenu |
| 1459 | (ert-deftest python-imenu-prev-index-position-1 () | 1676 | |
| 1460 | (require 'imenu) | 1677 | (ert-deftest python-imenu-create-index-1 () |
| 1461 | (python-tests-with-temp-buffer | 1678 | (python-tests-with-temp-buffer |
| 1462 | " | 1679 | " |
| 1463 | def decoratorFunctionWithArguments(arg1, arg2, arg3): | 1680 | class Foo(models.Model): |
| 1681 | pass | ||
| 1682 | |||
| 1683 | |||
| 1684 | class Bar(models.Model): | ||
| 1685 | pass | ||
| 1686 | |||
| 1687 | |||
| 1688 | def decorator(arg1, arg2, arg3): | ||
| 1464 | '''print decorated function call data to stdout. | 1689 | '''print decorated function call data to stdout. |
| 1465 | 1690 | ||
| 1466 | Usage: | 1691 | Usage: |
| 1467 | 1692 | ||
| 1468 | @decoratorFunctionWithArguments('arg1', 'arg2') | 1693 | @decorator('arg1', 'arg2') |
| 1469 | def func(a, b, c=True): | 1694 | def func(a, b, c=True): |
| 1470 | pass | 1695 | pass |
| 1471 | ''' | 1696 | ''' |
| 1472 | 1697 | ||
| 1473 | def wwrap(f): | 1698 | def wrap(f): |
| 1474 | print 'Inside wwrap()' | 1699 | print ('wrap') |
| 1475 | def wrapped_f(*args): | 1700 | def wrapped_f(*args): |
| 1476 | print 'Inside wrapped_f()' | 1701 | print ('wrapped_f') |
| 1477 | print 'Decorator arguments:', arg1, arg2, arg3 | 1702 | print ('Decorator arguments:', arg1, arg2, arg3) |
| 1478 | f(*args) | 1703 | f(*args) |
| 1479 | print 'After f(*args)' | 1704 | print ('called f(*args)') |
| 1480 | return wrapped_f | 1705 | return wrapped_f |
| 1481 | return wwrap | 1706 | return wrap |
| 1482 | 1707 | ||
| 1483 | def test(): # Some comment | ||
| 1484 | 'This is a test function' | ||
| 1485 | print 'test' | ||
| 1486 | 1708 | ||
| 1487 | class C(object): | 1709 | class Baz(object): |
| 1488 | 1710 | ||
| 1489 | def m(self): | 1711 | def a(self): |
| 1490 | self.c() | 1712 | pass |
| 1491 | 1713 | ||
| 1492 | def b(): | 1714 | def b(self): |
| 1493 | pass | 1715 | pass |
| 1494 | 1716 | ||
| 1495 | def a(): | 1717 | class Frob(object): |
| 1718 | |||
| 1719 | def c(self): | ||
| 1496 | pass | 1720 | pass |
| 1721 | " | ||
| 1722 | (goto-char (point-max)) | ||
| 1723 | (should (equal | ||
| 1724 | (list | ||
| 1725 | (cons "Foo (class)" (copy-marker 2)) | ||
| 1726 | (cons "Bar (class)" (copy-marker 38)) | ||
| 1727 | (list | ||
| 1728 | "decorator (def)" | ||
| 1729 | (cons "*function definition*" (copy-marker 74)) | ||
| 1730 | (list | ||
| 1731 | "wrap (def)" | ||
| 1732 | (cons "*function definition*" (copy-marker 254)) | ||
| 1733 | (cons "wrapped_f (def)" (copy-marker 294)))) | ||
| 1734 | (list | ||
| 1735 | "Baz (class)" | ||
| 1736 | (cons "*class definition*" (copy-marker 519)) | ||
| 1737 | (cons "a (def)" (copy-marker 539)) | ||
| 1738 | (cons "b (def)" (copy-marker 570)) | ||
| 1739 | (list | ||
| 1740 | "Frob (class)" | ||
| 1741 | (cons "*class definition*" (copy-marker 601)) | ||
| 1742 | (cons "c (def)" (copy-marker 626))))) | ||
| 1743 | (python-imenu-create-index))))) | ||
| 1744 | |||
| 1745 | (ert-deftest python-imenu-create-flat-index-1 () | ||
| 1746 | (python-tests-with-temp-buffer | ||
| 1747 | " | ||
| 1748 | class Foo(models.Model): | ||
| 1749 | pass | ||
| 1497 | 1750 | ||
| 1498 | def c(self): | 1751 | |
| 1752 | class Bar(models.Model): | ||
| 1753 | pass | ||
| 1754 | |||
| 1755 | |||
| 1756 | def decorator(arg1, arg2, arg3): | ||
| 1757 | '''print decorated function call data to stdout. | ||
| 1758 | |||
| 1759 | Usage: | ||
| 1760 | |||
| 1761 | @decorator('arg1', 'arg2') | ||
| 1762 | def func(a, b, c=True): | ||
| 1499 | pass | 1763 | pass |
| 1764 | ''' | ||
| 1765 | |||
| 1766 | def wrap(f): | ||
| 1767 | print ('wrap') | ||
| 1768 | def wrapped_f(*args): | ||
| 1769 | print ('wrapped_f') | ||
| 1770 | print ('Decorator arguments:', arg1, arg2, arg3) | ||
| 1771 | f(*args) | ||
| 1772 | print ('called f(*args)') | ||
| 1773 | return wrapped_f | ||
| 1774 | return wrap | ||
| 1775 | |||
| 1776 | |||
| 1777 | class Baz(object): | ||
| 1778 | |||
| 1779 | def a(self): | ||
| 1780 | pass | ||
| 1781 | |||
| 1782 | def b(self): | ||
| 1783 | pass | ||
| 1784 | |||
| 1785 | class Frob(object): | ||
| 1786 | |||
| 1787 | def c(self): | ||
| 1788 | pass | ||
| 1500 | " | 1789 | " |
| 1501 | (let ((expected | 1790 | (goto-char (point-max)) |
| 1502 | '(("*Rescan*" . -99) | 1791 | (should (equal |
| 1503 | ("decoratorFunctionWithArguments" . 2) | 1792 | (list (cons "Foo" (copy-marker 2)) |
| 1504 | ("decoratorFunctionWithArguments.wwrap" . 224) | 1793 | (cons "Bar" (copy-marker 38)) |
| 1505 | ("decoratorFunctionWithArguments.wwrap.wrapped_f" . 273) | 1794 | (cons "decorator" (copy-marker 74)) |
| 1506 | ("test" . 500) | 1795 | (cons "decorator.wrap" (copy-marker 254)) |
| 1507 | ("C" . 575) | 1796 | (cons "decorator.wrap.wrapped_f" (copy-marker 294)) |
| 1508 | ("C.m" . 593) | 1797 | (cons "Baz" (copy-marker 519)) |
| 1509 | ("C.m.b" . 628) | 1798 | (cons "Baz.a" (copy-marker 539)) |
| 1510 | ("C.m.a" . 663) | 1799 | (cons "Baz.b" (copy-marker 570)) |
| 1511 | ("C.c" . 698)))) | 1800 | (cons "Baz.Frob" (copy-marker 601)) |
| 1512 | (mapc | 1801 | (cons "Baz.Frob.c" (copy-marker 626))) |
| 1513 | (lambda (elt) | 1802 | (python-imenu-create-flat-index))))) |
| 1514 | (should (= (cdr (assoc-string (car elt) expected)) | ||
| 1515 | (if (markerp (cdr elt)) | ||
| 1516 | (marker-position (cdr elt)) | ||
| 1517 | (cdr elt))))) | ||
| 1518 | (imenu--make-index-alist))))) | ||
| 1519 | 1803 | ||
| 1520 | 1804 | ||
| 1521 | ;;; Misc helpers | 1805 | ;;; Misc helpers |
| @@ -1546,13 +1830,13 @@ class C(object): | |||
| 1546 | return [] | 1830 | return [] |
| 1547 | 1831 | ||
| 1548 | def b(): | 1832 | def b(): |
| 1549 | pass | 1833 | do_b() |
| 1550 | 1834 | ||
| 1551 | def a(): | 1835 | def a(): |
| 1552 | pass | 1836 | do_a() |
| 1553 | 1837 | ||
| 1554 | def c(self): | 1838 | def c(self): |
| 1555 | pass | 1839 | do_c() |
| 1556 | " | 1840 | " |
| 1557 | (forward-line 1) | 1841 | (forward-line 1) |
| 1558 | (should (string= "C" (python-info-current-defun))) | 1842 | (should (string= "C" (python-info-current-defun))) |
| @@ -1582,7 +1866,7 @@ class C(object): | |||
| 1582 | (python-tests-look-at "def c(self):") | 1866 | (python-tests-look-at "def c(self):") |
| 1583 | (should (string= "C.c" (python-info-current-defun))) | 1867 | (should (string= "C.c" (python-info-current-defun))) |
| 1584 | (should (string= "def C.c" (python-info-current-defun t))) | 1868 | (should (string= "def C.c" (python-info-current-defun t))) |
| 1585 | (python-tests-look-at "pass") | 1869 | (python-tests-look-at "do_c()") |
| 1586 | (should (string= "C.c" (python-info-current-defun))) | 1870 | (should (string= "C.c" (python-info-current-defun))) |
| 1587 | (should (string= "def C.c" (python-info-current-defun t))))) | 1871 | (should (string= "def C.c" (python-info-current-defun t))))) |
| 1588 | 1872 | ||