diff options
Diffstat (limited to 'test/automated/python-tests.el')
| -rw-r--r-- | test/automated/python-tests.el | 509 |
1 files changed, 376 insertions, 133 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index de20a80ea52..ca43c45ac5e 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el | |||
| @@ -740,6 +740,39 @@ def b() | |||
| 740 | (python-tests-self-insert ":") | 740 | (python-tests-self-insert ":") |
| 741 | (should (= (current-indentation) 0)))) | 741 | (should (= (current-indentation) 0)))) |
| 742 | 742 | ||
| 743 | (ert-deftest python-indent-electric-colon-2 () | ||
| 744 | "Test indentation case for dedenter." | ||
| 745 | (python-tests-with-temp-buffer | ||
| 746 | " | ||
| 747 | if do: | ||
| 748 | something() | ||
| 749 | else | ||
| 750 | " | ||
| 751 | (python-tests-look-at "else") | ||
| 752 | (goto-char (line-end-position)) | ||
| 753 | (python-tests-self-insert ":") | ||
| 754 | (should (= (current-indentation) 0)))) | ||
| 755 | |||
| 756 | (ert-deftest python-indent-electric-colon-3 () | ||
| 757 | "Test indentation case for multi-line dedenter." | ||
| 758 | (python-tests-with-temp-buffer | ||
| 759 | " | ||
| 760 | if do: | ||
| 761 | something() | ||
| 762 | elif (this | ||
| 763 | and | ||
| 764 | that) | ||
| 765 | " | ||
| 766 | (python-tests-look-at "that)") | ||
| 767 | (goto-char (line-end-position)) | ||
| 768 | (python-tests-self-insert ":") | ||
| 769 | (python-tests-look-at "elif" -1) | ||
| 770 | (should (= (current-indentation) 0)) | ||
| 771 | (python-tests-look-at "and") | ||
| 772 | (should (= (current-indentation) 6)) | ||
| 773 | (python-tests-look-at "that)") | ||
| 774 | (should (= (current-indentation) 6)))) | ||
| 775 | |||
| 743 | (ert-deftest python-indent-region-1 () | 776 | (ert-deftest python-indent-region-1 () |
| 744 | "Test indentation case from Bug#18843." | 777 | "Test indentation case from Bug#18843." |
| 745 | (let ((contents " | 778 | (let ((contents " |
| @@ -1775,52 +1808,41 @@ def f(): | |||
| 1775 | (defvar python-tests-shell-interpreter "python") | 1808 | (defvar python-tests-shell-interpreter "python") |
| 1776 | 1809 | ||
| 1777 | (ert-deftest python-shell-get-process-name-1 () | 1810 | (ert-deftest python-shell-get-process-name-1 () |
| 1778 | "Check process name calculation on different scenarios." | 1811 | "Check process name calculation sans `buffer-file-name'." |
| 1779 | (python-tests-with-temp-buffer | 1812 | (python-tests-with-temp-buffer |
| 1780 | "" | 1813 | "" |
| 1781 | (should (string= (python-shell-get-process-name nil) | 1814 | (should (string= (python-shell-get-process-name nil) |
| 1782 | python-shell-buffer-name)) | 1815 | python-shell-buffer-name)) |
| 1783 | ;; When the `current-buffer' doesn't have `buffer-file-name', even | 1816 | (should (string= (python-shell-get-process-name t) |
| 1784 | ;; if dedicated flag is non-nil should not include its name. | 1817 | (format "%s[%s]" python-shell-buffer-name (buffer-name)))))) |
| 1785 | (should (string= (python-shell-get-process-name t) | 1818 | |
| 1786 | python-shell-buffer-name))) | 1819 | (ert-deftest python-shell-get-process-name-2 () |
| 1820 | "Check process name calculation with `buffer-file-name'." | ||
| 1787 | (python-tests-with-temp-file | 1821 | (python-tests-with-temp-file |
| 1788 | "" | 1822 | "" |
| 1789 | ;; `buffer-file-name' is non-nil but the dedicated flag is nil and | 1823 | ;; `buffer-file-name' is non-nil but the dedicated flag is nil and |
| 1790 | ;; should be respected. | 1824 | ;; should be respected. |
| 1791 | (should (string= (python-shell-get-process-name nil) | 1825 | (should (string= (python-shell-get-process-name nil) |
| 1792 | python-shell-buffer-name)) | 1826 | python-shell-buffer-name)) |
| 1793 | (should (string= | 1827 | (should (string= |
| 1794 | (python-shell-get-process-name t) | 1828 | (python-shell-get-process-name t) |
| 1795 | (format "%s[%s]" python-shell-buffer-name buffer-file-name))))) | 1829 | (format "%s[%s]" python-shell-buffer-name (buffer-name)))))) |
| 1796 | 1830 | ||
| 1797 | (ert-deftest python-shell-internal-get-process-name-1 () | 1831 | (ert-deftest python-shell-internal-get-process-name-1 () |
| 1798 | "Check the internal process name is config-unique." | 1832 | "Check the internal process name is buffer-unique sans `buffer-file-name'." |
| 1799 | (let* ((python-shell-interpreter python-tests-shell-interpreter) | 1833 | (python-tests-with-temp-buffer |
| 1800 | (python-shell-interpreter-args "") | 1834 | "" |
| 1801 | (python-shell-prompt-regexp ">>> ") | 1835 | (should (string= (python-shell-internal-get-process-name) |
| 1802 | (python-shell-prompt-block-regexp "[.][.][.] ") | 1836 | (format "%s[%s]" python-shell-internal-buffer-name (buffer-name)))))) |
| 1803 | (python-shell-setup-codes "") | 1837 | |
| 1804 | (python-shell-process-environment "") | 1838 | (ert-deftest python-shell-internal-get-process-name-2 () |
| 1805 | (python-shell-extra-pythonpaths "") | 1839 | "Check the internal process name is buffer-unique with `buffer-file-name'." |
| 1806 | (python-shell-exec-path "") | 1840 | (python-tests-with-temp-file |
| 1807 | (python-shell-virtualenv-path "") | 1841 | "" |
| 1808 | (expected (python-tests-with-temp-buffer | 1842 | (should (string= (python-shell-internal-get-process-name) |
| 1809 | "" (python-shell-internal-get-process-name)))) | 1843 | (format "%s[%s]" python-shell-internal-buffer-name (buffer-name)))))) |
| 1810 | ;; Same configurations should match. | 1844 | |
| 1811 | (should | 1845 | (ert-deftest python-shell-calculate-command-1 () |
| 1812 | (string= expected | ||
| 1813 | (python-tests-with-temp-buffer | ||
| 1814 | "" (python-shell-internal-get-process-name)))) | ||
| 1815 | (let ((python-shell-interpreter-args "-B")) | ||
| 1816 | ;; A minimal change should generate different names. | ||
| 1817 | (should | ||
| 1818 | (not (string= | ||
| 1819 | expected | ||
| 1820 | (python-tests-with-temp-buffer | ||
| 1821 | "" (python-shell-internal-get-process-name)))))))) | ||
| 1822 | |||
| 1823 | (ert-deftest python-shell-parse-command-1 () | ||
| 1824 | "Check the command to execute is calculated correctly. | 1846 | "Check the command to execute is calculated correctly. |
| 1825 | Using `python-shell-interpreter' and | 1847 | Using `python-shell-interpreter' and |
| 1826 | `python-shell-interpreter-args'." | 1848 | `python-shell-interpreter-args'." |
| @@ -1832,7 +1854,7 @@ Using `python-shell-interpreter' and | |||
| 1832 | (format "%s %s" | 1854 | (format "%s %s" |
| 1833 | python-shell-interpreter | 1855 | python-shell-interpreter |
| 1834 | python-shell-interpreter-args) | 1856 | python-shell-interpreter-args) |
| 1835 | (python-shell-parse-command))))) | 1857 | (python-shell-calculate-command))))) |
| 1836 | 1858 | ||
| 1837 | (ert-deftest python-shell-calculate-process-environment-1 () | 1859 | (ert-deftest python-shell-calculate-process-environment-1 () |
| 1838 | "Test `python-shell-process-environment' modification." | 1860 | "Test `python-shell-process-environment' modification." |
| @@ -1857,17 +1879,17 @@ Using `python-shell-interpreter' and | |||
| 1857 | path-separator original-pythonpath))))) | 1879 | path-separator original-pythonpath))))) |
| 1858 | 1880 | ||
| 1859 | (ert-deftest python-shell-calculate-process-environment-3 () | 1881 | (ert-deftest python-shell-calculate-process-environment-3 () |
| 1860 | "Test `python-shell-virtualenv-path' modification." | 1882 | "Test `python-shell-virtualenv-root' modification." |
| 1861 | (let* ((original-path (or (getenv "PATH") "")) | 1883 | (let* ((original-path (or (getenv "PATH") "")) |
| 1862 | (python-shell-virtualenv-path | 1884 | (python-shell-virtualenv-root |
| 1863 | (directory-file-name user-emacs-directory)) | 1885 | (directory-file-name user-emacs-directory)) |
| 1864 | (process-environment | 1886 | (process-environment |
| 1865 | (python-shell-calculate-process-environment))) | 1887 | (python-shell-calculate-process-environment))) |
| 1866 | (should (not (getenv "PYTHONHOME"))) | 1888 | (should (not (getenv "PYTHONHOME"))) |
| 1867 | (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-path)) | 1889 | (should (string= (getenv "VIRTUAL_ENV") python-shell-virtualenv-root)) |
| 1868 | (should (equal (getenv "PATH") | 1890 | (should (equal (getenv "PATH") |
| 1869 | (format "%s/bin%s%s" | 1891 | (format "%s/bin%s%s" |
| 1870 | python-shell-virtualenv-path | 1892 | python-shell-virtualenv-root |
| 1871 | path-separator original-path))))) | 1893 | path-separator original-path))))) |
| 1872 | 1894 | ||
| 1873 | (ert-deftest python-shell-calculate-process-environment-4 () | 1895 | (ert-deftest python-shell-calculate-process-environment-4 () |
| @@ -1900,13 +1922,13 @@ Using `python-shell-interpreter' and | |||
| 1900 | (ert-deftest python-shell-calculate-exec-path-2 () | 1922 | (ert-deftest python-shell-calculate-exec-path-2 () |
| 1901 | "Test `python-shell-exec-path' modification." | 1923 | "Test `python-shell-exec-path' modification." |
| 1902 | (let* ((original-exec-path exec-path) | 1924 | (let* ((original-exec-path exec-path) |
| 1903 | (python-shell-virtualenv-path | 1925 | (python-shell-virtualenv-root |
| 1904 | (directory-file-name (expand-file-name user-emacs-directory))) | 1926 | (directory-file-name (expand-file-name user-emacs-directory))) |
| 1905 | (exec-path (python-shell-calculate-exec-path))) | 1927 | (exec-path (python-shell-calculate-exec-path))) |
| 1906 | (should (equal | 1928 | (should (equal |
| 1907 | exec-path | 1929 | exec-path |
| 1908 | (append (cons | 1930 | (append (cons |
| 1909 | (format "%s/bin" python-shell-virtualenv-path) | 1931 | (format "%s/bin" python-shell-virtualenv-root) |
| 1910 | original-exec-path)))))) | 1932 | original-exec-path)))))) |
| 1911 | 1933 | ||
| 1912 | (ert-deftest python-shell-make-comint-1 () | 1934 | (ert-deftest python-shell-make-comint-1 () |
| @@ -1922,7 +1944,7 @@ Using `python-shell-interpreter' and | |||
| 1922 | (shell-buffer | 1944 | (shell-buffer |
| 1923 | (python-tests-with-temp-buffer | 1945 | (python-tests-with-temp-buffer |
| 1924 | "" (python-shell-make-comint | 1946 | "" (python-shell-make-comint |
| 1925 | (python-shell-parse-command) proc-name))) | 1947 | (python-shell-calculate-command) proc-name))) |
| 1926 | (process (get-buffer-process shell-buffer))) | 1948 | (process (get-buffer-process shell-buffer))) |
| 1927 | (unwind-protect | 1949 | (unwind-protect |
| 1928 | (progn | 1950 | (progn |
| @@ -1943,7 +1965,7 @@ Using `python-shell-interpreter' and | |||
| 1943 | (shell-buffer | 1965 | (shell-buffer |
| 1944 | (python-tests-with-temp-buffer | 1966 | (python-tests-with-temp-buffer |
| 1945 | "" (python-shell-make-comint | 1967 | "" (python-shell-make-comint |
| 1946 | (python-shell-parse-command) proc-name nil t))) | 1968 | (python-shell-calculate-command) proc-name nil t))) |
| 1947 | (process (get-buffer-process shell-buffer))) | 1969 | (process (get-buffer-process shell-buffer))) |
| 1948 | (unwind-protect | 1970 | (unwind-protect |
| 1949 | (progn | 1971 | (progn |
| @@ -2010,7 +2032,7 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2010 | (setenv "PYTHONSTARTUP" startup-file) | 2032 | (setenv "PYTHONSTARTUP" startup-file) |
| 2011 | (python-tests-with-temp-buffer | 2033 | (python-tests-with-temp-buffer |
| 2012 | "" (python-shell-make-comint | 2034 | "" (python-shell-make-comint |
| 2013 | (python-shell-parse-command) proc-name nil)))) | 2035 | (python-shell-calculate-command) proc-name nil)))) |
| 2014 | (process (get-buffer-process shell-buffer))) | 2036 | (process (get-buffer-process shell-buffer))) |
| 2015 | (unwind-protect | 2037 | (unwind-protect |
| 2016 | (progn | 2038 | (progn |
| @@ -2040,10 +2062,10 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2040 | (dedicated-proc-name (python-shell-get-process-name t)) | 2062 | (dedicated-proc-name (python-shell-get-process-name t)) |
| 2041 | (global-shell-buffer | 2063 | (global-shell-buffer |
| 2042 | (python-shell-make-comint | 2064 | (python-shell-make-comint |
| 2043 | (python-shell-parse-command) global-proc-name)) | 2065 | (python-shell-calculate-command) global-proc-name)) |
| 2044 | (dedicated-shell-buffer | 2066 | (dedicated-shell-buffer |
| 2045 | (python-shell-make-comint | 2067 | (python-shell-make-comint |
| 2046 | (python-shell-parse-command) dedicated-proc-name)) | 2068 | (python-shell-calculate-command) dedicated-proc-name)) |
| 2047 | (global-process (get-buffer-process global-shell-buffer)) | 2069 | (global-process (get-buffer-process global-shell-buffer)) |
| 2048 | (dedicated-process (get-buffer-process dedicated-shell-buffer))) | 2070 | (dedicated-process (get-buffer-process dedicated-shell-buffer))) |
| 2049 | (unwind-protect | 2071 | (unwind-protect |
| @@ -2061,84 +2083,6 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2061 | (ignore-errors (kill-buffer global-shell-buffer)) | 2083 | (ignore-errors (kill-buffer global-shell-buffer)) |
| 2062 | (ignore-errors (kill-buffer dedicated-shell-buffer)))))) | 2084 | (ignore-errors (kill-buffer dedicated-shell-buffer)))))) |
| 2063 | 2085 | ||
| 2064 | (ert-deftest python-shell-get-or-create-process-1 () | ||
| 2065 | "Check shell dedicated process creation." | ||
| 2066 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 2067 | (python-tests-with-temp-file | ||
| 2068 | "" | ||
| 2069 | (let* ((cmd | ||
| 2070 | (concat (executable-find python-tests-shell-interpreter) " -i")) | ||
| 2071 | (use-dialog-box) | ||
| 2072 | (dedicated-process-name (python-shell-get-process-name t)) | ||
| 2073 | (dedicated-process (python-shell-get-or-create-process cmd t)) | ||
| 2074 | (dedicated-shell-buffer (process-buffer dedicated-process))) | ||
| 2075 | (unwind-protect | ||
| 2076 | (progn | ||
| 2077 | (set-process-query-on-exit-flag dedicated-process nil) | ||
| 2078 | ;; should be dedicated. | ||
| 2079 | (should (equal (process-name dedicated-process) | ||
| 2080 | dedicated-process-name)) | ||
| 2081 | (kill-buffer dedicated-shell-buffer) | ||
| 2082 | ;; Check there are no processes for current buffer. | ||
| 2083 | (should (not (python-shell-get-process)))) | ||
| 2084 | (ignore-errors (kill-buffer dedicated-shell-buffer)))))) | ||
| 2085 | |||
| 2086 | (ert-deftest python-shell-get-or-create-process-2 () | ||
| 2087 | "Check shell global process creation." | ||
| 2088 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 2089 | (python-tests-with-temp-file | ||
| 2090 | "" | ||
| 2091 | (let* ((cmd | ||
| 2092 | (concat (executable-find python-tests-shell-interpreter) " -i")) | ||
| 2093 | (use-dialog-box) | ||
| 2094 | (process-name (python-shell-get-process-name nil)) | ||
| 2095 | (process (python-shell-get-or-create-process cmd)) | ||
| 2096 | (shell-buffer (process-buffer process))) | ||
| 2097 | (unwind-protect | ||
| 2098 | (progn | ||
| 2099 | (set-process-query-on-exit-flag process nil) | ||
| 2100 | ;; should be global. | ||
| 2101 | (should (equal (process-name process) process-name)) | ||
| 2102 | (kill-buffer shell-buffer) | ||
| 2103 | ;; Check there are no processes for current buffer. | ||
| 2104 | (should (not (python-shell-get-process)))) | ||
| 2105 | (ignore-errors (kill-buffer shell-buffer)))))) | ||
| 2106 | |||
| 2107 | (ert-deftest python-shell-get-or-create-process-3 () | ||
| 2108 | "Check shell dedicated/global process preference." | ||
| 2109 | (skip-unless (executable-find python-tests-shell-interpreter)) | ||
| 2110 | (python-tests-with-temp-file | ||
| 2111 | "" | ||
| 2112 | (let* ((cmd | ||
| 2113 | (concat (executable-find python-tests-shell-interpreter) " -i")) | ||
| 2114 | (python-shell-interpreter python-tests-shell-interpreter) | ||
| 2115 | (use-dialog-box) | ||
| 2116 | (dedicated-process-name (python-shell-get-process-name t)) | ||
| 2117 | (global-process) | ||
| 2118 | (dedicated-process)) | ||
| 2119 | (progn | ||
| 2120 | ;; Create global process | ||
| 2121 | (run-python cmd nil) | ||
| 2122 | (setq global-process (get-buffer-process "*Python*")) | ||
| 2123 | (should global-process) | ||
| 2124 | (set-process-query-on-exit-flag global-process nil) | ||
| 2125 | ;; Create dedicated process | ||
| 2126 | (run-python cmd t) | ||
| 2127 | (setq dedicated-process (get-process dedicated-process-name)) | ||
| 2128 | (should dedicated-process) | ||
| 2129 | (set-process-query-on-exit-flag dedicated-process nil) | ||
| 2130 | ;; Prefer dedicated. | ||
| 2131 | (should (equal (python-shell-get-or-create-process) | ||
| 2132 | dedicated-process)) | ||
| 2133 | ;; Kill the dedicated so the global takes over. | ||
| 2134 | (kill-buffer (process-buffer dedicated-process)) | ||
| 2135 | ;; Detect global. | ||
| 2136 | (should (equal (python-shell-get-or-create-process) global-process)) | ||
| 2137 | ;; Kill the global. | ||
| 2138 | (kill-buffer (process-buffer global-process)) | ||
| 2139 | ;; Check there are no processes for current buffer. | ||
| 2140 | (should (not (python-shell-get-process))))))) | ||
| 2141 | |||
| 2142 | (ert-deftest python-shell-internal-get-or-create-process-1 () | 2086 | (ert-deftest python-shell-internal-get-or-create-process-1 () |
| 2143 | "Check internal shell process creation fallback." | 2087 | "Check internal shell process creation fallback." |
| 2144 | (skip-unless (executable-find python-tests-shell-interpreter)) | 2088 | (skip-unless (executable-find python-tests-shell-interpreter)) |
| @@ -2424,9 +2368,229 @@ and `python-shell-interpreter-args' in the new shell buffer." | |||
| 2424 | "^\\(o\\.t \\|\\)"))) | 2368 | "^\\(o\\.t \\|\\)"))) |
| 2425 | (ignore-errors (delete-file startup-file))))) | 2369 | (ignore-errors (delete-file startup-file))))) |
| 2426 | 2370 | ||
| 2371 | (ert-deftest python-shell-buffer-substring-1 () | ||
| 2372 | "Selecting a substring of the whole buffer must match its contents." | ||
| 2373 | (python-tests-with-temp-buffer | ||
| 2374 | " | ||
| 2375 | class Foo(models.Model): | ||
| 2376 | pass | ||
| 2377 | |||
| 2378 | |||
| 2379 | class Bar(models.Model): | ||
| 2380 | pass | ||
| 2381 | " | ||
| 2382 | (should (string= (buffer-string) | ||
| 2383 | (python-shell-buffer-substring (point-min) (point-max)))))) | ||
| 2384 | |||
| 2385 | (ert-deftest python-shell-buffer-substring-2 () | ||
| 2386 | "Main block should be removed if NOMAIN is non-nil." | ||
| 2387 | (python-tests-with-temp-buffer | ||
| 2388 | " | ||
| 2389 | class Foo(models.Model): | ||
| 2390 | pass | ||
| 2391 | |||
| 2392 | class Bar(models.Model): | ||
| 2393 | pass | ||
| 2394 | |||
| 2395 | if __name__ == \"__main__\": | ||
| 2396 | foo = Foo() | ||
| 2397 | print (foo) | ||
| 2398 | " | ||
| 2399 | (should (string= (python-shell-buffer-substring (point-min) (point-max) t) | ||
| 2400 | " | ||
| 2401 | class Foo(models.Model): | ||
| 2402 | pass | ||
| 2403 | |||
| 2404 | class Bar(models.Model): | ||
| 2405 | pass | ||
| 2406 | |||
| 2407 | |||
| 2408 | |||
| 2409 | |||
| 2410 | ")))) | ||
| 2411 | |||
| 2412 | (ert-deftest python-shell-buffer-substring-3 () | ||
| 2413 | "Main block should be removed if NOMAIN is non-nil." | ||
| 2414 | (python-tests-with-temp-buffer | ||
| 2415 | " | ||
| 2416 | class Foo(models.Model): | ||
| 2417 | pass | ||
| 2418 | |||
| 2419 | if __name__ == \"__main__\": | ||
| 2420 | foo = Foo() | ||
| 2421 | print (foo) | ||
| 2422 | |||
| 2423 | class Bar(models.Model): | ||
| 2424 | pass | ||
| 2425 | " | ||
| 2426 | (should (string= (python-shell-buffer-substring (point-min) (point-max) t) | ||
| 2427 | " | ||
| 2428 | class Foo(models.Model): | ||
| 2429 | pass | ||
| 2430 | |||
| 2431 | |||
| 2432 | |||
| 2433 | |||
| 2434 | |||
| 2435 | class Bar(models.Model): | ||
| 2436 | pass | ||
| 2437 | ")))) | ||
| 2438 | |||
| 2439 | (ert-deftest python-shell-buffer-substring-4 () | ||
| 2440 | "Coding cookie should be added for substrings." | ||
| 2441 | (python-tests-with-temp-buffer | ||
| 2442 | "# coding: latin-1 | ||
| 2443 | |||
| 2444 | class Foo(models.Model): | ||
| 2445 | pass | ||
| 2446 | |||
| 2447 | if __name__ == \"__main__\": | ||
| 2448 | foo = Foo() | ||
| 2449 | print (foo) | ||
| 2450 | |||
| 2451 | class Bar(models.Model): | ||
| 2452 | pass | ||
| 2453 | " | ||
| 2454 | (should (string= (python-shell-buffer-substring | ||
| 2455 | (python-tests-look-at "class Foo(models.Model):") | ||
| 2456 | (progn (python-nav-forward-sexp) (point))) | ||
| 2457 | "# -*- coding: latin-1 -*- | ||
| 2458 | |||
| 2459 | class Foo(models.Model): | ||
| 2460 | pass")))) | ||
| 2461 | |||
| 2462 | (ert-deftest python-shell-buffer-substring-5 () | ||
| 2463 | "The proper amount of blank lines is added for a substring." | ||
| 2464 | (python-tests-with-temp-buffer | ||
| 2465 | "# coding: latin-1 | ||
| 2466 | |||
| 2467 | class Foo(models.Model): | ||
| 2468 | pass | ||
| 2469 | |||
| 2470 | if __name__ == \"__main__\": | ||
| 2471 | foo = Foo() | ||
| 2472 | print (foo) | ||
| 2473 | |||
| 2474 | class Bar(models.Model): | ||
| 2475 | pass | ||
| 2476 | " | ||
| 2477 | (should (string= (python-shell-buffer-substring | ||
| 2478 | (python-tests-look-at "class Bar(models.Model):") | ||
| 2479 | (progn (python-nav-forward-sexp) (point))) | ||
| 2480 | "# -*- coding: latin-1 -*- | ||
| 2481 | |||
| 2482 | |||
| 2483 | |||
| 2484 | |||
| 2485 | |||
| 2486 | |||
| 2487 | |||
| 2488 | |||
| 2489 | class Bar(models.Model): | ||
| 2490 | pass")))) | ||
| 2491 | |||
| 2492 | (ert-deftest python-shell-buffer-substring-6 () | ||
| 2493 | "Handle substring with coding cookie in the second line." | ||
| 2494 | (python-tests-with-temp-buffer | ||
| 2495 | " | ||
| 2496 | # coding: latin-1 | ||
| 2497 | |||
| 2498 | class Foo(models.Model): | ||
| 2499 | pass | ||
| 2500 | |||
| 2501 | if __name__ == \"__main__\": | ||
| 2502 | foo = Foo() | ||
| 2503 | print (foo) | ||
| 2504 | |||
| 2505 | class Bar(models.Model): | ||
| 2506 | pass | ||
| 2507 | " | ||
| 2508 | (should (string= (python-shell-buffer-substring | ||
| 2509 | (python-tests-look-at "# coding: latin-1") | ||
| 2510 | (python-tests-look-at "if __name__ == \"__main__\":")) | ||
| 2511 | "# -*- coding: latin-1 -*- | ||
| 2512 | |||
| 2513 | |||
| 2514 | class Foo(models.Model): | ||
| 2515 | pass | ||
| 2516 | |||
| 2517 | ")))) | ||
| 2518 | |||
| 2519 | (ert-deftest python-shell-buffer-substring-7 () | ||
| 2520 | "Ensure first coding cookie gets precedence." | ||
| 2521 | (python-tests-with-temp-buffer | ||
| 2522 | "# coding: utf-8 | ||
| 2523 | # coding: latin-1 | ||
| 2524 | |||
| 2525 | class Foo(models.Model): | ||
| 2526 | pass | ||
| 2527 | |||
| 2528 | if __name__ == \"__main__\": | ||
| 2529 | foo = Foo() | ||
| 2530 | print (foo) | ||
| 2531 | |||
| 2532 | class Bar(models.Model): | ||
| 2533 | pass | ||
| 2534 | " | ||
| 2535 | (should (string= (python-shell-buffer-substring | ||
| 2536 | (python-tests-look-at "# coding: latin-1") | ||
| 2537 | (python-tests-look-at "if __name__ == \"__main__\":")) | ||
| 2538 | "# -*- coding: utf-8 -*- | ||
| 2539 | |||
| 2540 | |||
| 2541 | class Foo(models.Model): | ||
| 2542 | pass | ||
| 2543 | |||
| 2544 | ")))) | ||
| 2545 | |||
| 2546 | (ert-deftest python-shell-buffer-substring-8 () | ||
| 2547 | "Ensure first coding cookie gets precedence when sending whole buffer." | ||
| 2548 | (python-tests-with-temp-buffer | ||
| 2549 | "# coding: utf-8 | ||
| 2550 | # coding: latin-1 | ||
| 2551 | |||
| 2552 | class Foo(models.Model): | ||
| 2553 | pass | ||
| 2554 | " | ||
| 2555 | (should (string= (python-shell-buffer-substring (point-min) (point-max)) | ||
| 2556 | "# coding: utf-8 | ||
| 2557 | |||
| 2558 | |||
| 2559 | class Foo(models.Model): | ||
| 2560 | pass | ||
| 2561 | ")))) | ||
| 2562 | |||
| 2563 | (ert-deftest python-shell-buffer-substring-9 () | ||
| 2564 | "Check substring starting from `point-min'." | ||
| 2565 | (python-tests-with-temp-buffer | ||
| 2566 | "# coding: utf-8 | ||
| 2567 | |||
| 2568 | class Foo(models.Model): | ||
| 2569 | pass | ||
| 2570 | |||
| 2571 | class Bar(models.Model): | ||
| 2572 | pass | ||
| 2573 | " | ||
| 2574 | (should (string= (python-shell-buffer-substring | ||
| 2575 | (point-min) | ||
| 2576 | (python-tests-look-at "class Bar(models.Model):")) | ||
| 2577 | "# coding: utf-8 | ||
| 2578 | |||
| 2579 | class Foo(models.Model): | ||
| 2580 | pass | ||
| 2581 | |||
| 2582 | ")))) | ||
| 2583 | |||
| 2427 | 2584 | ||
| 2428 | ;;; Shell completion | 2585 | ;;; Shell completion |
| 2429 | 2586 | ||
| 2587 | (ert-deftest python-shell-completion-native-interpreter-disabled-p-1 () | ||
| 2588 | (let* ((python-shell-completion-native-disabled-interpreters (list "pypy")) | ||
| 2589 | (python-shell-interpreter "/some/path/to/bin/pypy")) | ||
| 2590 | (should (python-shell-completion-native-interpreter-disabled-p)))) | ||
| 2591 | |||
| 2592 | |||
| 2593 | |||
| 2430 | 2594 | ||
| 2431 | ;;; PDB Track integration | 2595 | ;;; PDB Track integration |
| 2432 | 2596 | ||
| @@ -3738,6 +3902,85 @@ foo = True # another comment | |||
| 3738 | (forward-line 1) | 3902 | (forward-line 1) |
| 3739 | (should (python-info-current-line-empty-p)))) | 3903 | (should (python-info-current-line-empty-p)))) |
| 3740 | 3904 | ||
| 3905 | (ert-deftest python-info-encoding-from-cookie-1 () | ||
| 3906 | "Should detect it on first line." | ||
| 3907 | (python-tests-with-temp-buffer | ||
| 3908 | "# coding=latin-1 | ||
| 3909 | |||
| 3910 | foo = True # another comment | ||
| 3911 | " | ||
| 3912 | (should (eq (python-info-encoding-from-cookie) 'latin-1)))) | ||
| 3913 | |||
| 3914 | (ert-deftest python-info-encoding-from-cookie-2 () | ||
| 3915 | "Should detect it on second line." | ||
| 3916 | (python-tests-with-temp-buffer | ||
| 3917 | " | ||
| 3918 | # coding=latin-1 | ||
| 3919 | |||
| 3920 | foo = True # another comment | ||
| 3921 | " | ||
| 3922 | (should (eq (python-info-encoding-from-cookie) 'latin-1)))) | ||
| 3923 | |||
| 3924 | (ert-deftest python-info-encoding-from-cookie-3 () | ||
| 3925 | "Should not be detected on third line (and following ones)." | ||
| 3926 | (python-tests-with-temp-buffer | ||
| 3927 | " | ||
| 3928 | |||
| 3929 | # coding=latin-1 | ||
| 3930 | foo = True # another comment | ||
| 3931 | " | ||
| 3932 | (should (not (python-info-encoding-from-cookie))))) | ||
| 3933 | |||
| 3934 | (ert-deftest python-info-encoding-from-cookie-4 () | ||
| 3935 | "Should detect Emacs style." | ||
| 3936 | (python-tests-with-temp-buffer | ||
| 3937 | "# -*- coding: latin-1 -*- | ||
| 3938 | |||
| 3939 | foo = True # another comment" | ||
| 3940 | (should (eq (python-info-encoding-from-cookie) 'latin-1)))) | ||
| 3941 | |||
| 3942 | (ert-deftest python-info-encoding-from-cookie-5 () | ||
| 3943 | "Should detect Vim style." | ||
| 3944 | (python-tests-with-temp-buffer | ||
| 3945 | "# vim: set fileencoding=latin-1 : | ||
| 3946 | |||
| 3947 | foo = True # another comment" | ||
| 3948 | (should (eq (python-info-encoding-from-cookie) 'latin-1)))) | ||
| 3949 | |||
| 3950 | (ert-deftest python-info-encoding-from-cookie-6 () | ||
| 3951 | "First cookie wins." | ||
| 3952 | (python-tests-with-temp-buffer | ||
| 3953 | "# -*- coding: iso-8859-1 -*- | ||
| 3954 | # vim: set fileencoding=latin-1 : | ||
| 3955 | |||
| 3956 | foo = True # another comment" | ||
| 3957 | (should (eq (python-info-encoding-from-cookie) 'iso-8859-1)))) | ||
| 3958 | |||
| 3959 | (ert-deftest python-info-encoding-from-cookie-7 () | ||
| 3960 | "First cookie wins." | ||
| 3961 | (python-tests-with-temp-buffer | ||
| 3962 | "# vim: set fileencoding=latin-1 : | ||
| 3963 | # -*- coding: iso-8859-1 -*- | ||
| 3964 | |||
| 3965 | foo = True # another comment" | ||
| 3966 | (should (eq (python-info-encoding-from-cookie) 'latin-1)))) | ||
| 3967 | |||
| 3968 | (ert-deftest python-info-encoding-1 () | ||
| 3969 | "Should return the detected encoding from cookie." | ||
| 3970 | (python-tests-with-temp-buffer | ||
| 3971 | "# vim: set fileencoding=latin-1 : | ||
| 3972 | |||
| 3973 | foo = True # another comment" | ||
| 3974 | (should (eq (python-info-encoding) 'latin-1)))) | ||
| 3975 | |||
| 3976 | (ert-deftest python-info-encoding-2 () | ||
| 3977 | "Should default to utf-8." | ||
| 3978 | (python-tests-with-temp-buffer | ||
| 3979 | "# No encoding for you | ||
| 3980 | |||
| 3981 | foo = True # another comment" | ||
| 3982 | (should (eq (python-info-encoding) 'utf-8)))) | ||
| 3983 | |||
| 3741 | 3984 | ||
| 3742 | ;;; Utility functions | 3985 | ;;; Utility functions |
| 3743 | 3986 | ||
| @@ -3767,7 +4010,7 @@ def foo(a, b, c): | |||
| 3767 | . "from IPython.core.completerlib import module_completion") | 4010 | . "from IPython.core.completerlib import module_completion") |
| 3768 | (python-shell-completion-string-code | 4011 | (python-shell-completion-string-code |
| 3769 | . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n") | 4012 | . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n") |
| 3770 | (python-shell-virtualenv-path | 4013 | (python-shell-virtualenv-root |
| 3771 | . "/home/user/.virtualenvs/project")))) | 4014 | . "/home/user/.virtualenvs/project")))) |
| 3772 | (with-current-buffer buffer | 4015 | (with-current-buffer buffer |
| 3773 | (kill-all-local-variables) | 4016 | (kill-all-local-variables) |