aboutsummaryrefslogtreecommitdiffstats
path: root/test/automated/python-tests.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2014-07-19 10:13:07 -0300
committerFabián Ezequiel Gallina2014-07-19 10:13:07 -0300
commitd949ade3c101981d015b3d78d061bdff584df13a (patch)
treed5e486ede2477b8f139720eabda8f6965086daef /test/automated/python-tests.el
parent64384ca4ded41824f30a0a2470a65160dd486207 (diff)
downloademacs-d949ade3c101981d015b3d78d061bdff584df13a.tar.gz
emacs-d949ade3c101981d015b3d78d061bdff584df13a.zip
Autodetect Python shell prompts.
* lisp/progmodes/python.el: (python-shell-interpreter-interactive-arg) (python-shell-prompt-detect-enabled) (python-shell-prompt-detect-failure-warning) (python-shell-prompt-input-regexps) (python-shell-prompt-output-regexps): New vars. (python-shell-prompt-calculated-input-regexp) (python-shell-prompt-calculated-output-regexp): New vars. (python-shell-get-process-name) (python-shell-internal-get-process-name) (python-shell-output-filter) (python-shell-completion-get-completions): Use them. (python-shell-prompt-detect) (python-shell-prompt-validate-regexps): New functions. (python-shell-prompt-set-calculated-regexps): New function. (inferior-python-mode): Use it. Also honor overriden python-shell-interpreter and python-shell-interpreter-args. (python-shell-make-comint): Honor overriden python-shell-interpreter and python-shell-interpreter-args. (python-shell-get-or-create-process): Make it testable by allowing to call run-python non-interactively. (python-util-valid-regexp-p): New function. (python-shell-prompt-regexp, python-shell-prompt-block-regexp) (python-shell-prompt-output-regexp) (python-shell-prompt-pdb-regexp): Use it as defcustom :safe. * test/automated/python-tests.el (python-shell-make-comint-1): (python-shell-make-comint-2): Fix indentation. (python-shell-make-comint-3) (python-shell-make-comint-4): New tests. (python-shell-get-or-create-process-1): Fix test. (python-shell-get-or-create-process-2) (python-shell-get-or-create-process-3): New tests. (python-shell-internal-get-or-create-process-1): Fix test. (python-shell-prompt-detect-1): New test. (python-shell-prompt-detect-2): New test. (Bug#17370) (python-shell-prompt-detect-3) (python-shell-prompt-detect-4) (python-shell-prompt-detect-5) (python-shell-prompt-detect-6) (python-shell-prompt-validate-regexps-1) (python-shell-prompt-validate-regexps-2) (python-shell-prompt-validate-regexps-3) (python-shell-prompt-validate-regexps-4) (python-shell-prompt-validate-regexps-5) (python-shell-prompt-validate-regexps-6) (python-shell-prompt-validate-regexps-7) (python-shell-prompt-set-calculated-regexps-1) (python-shell-prompt-set-calculated-regexps-2) (python-shell-prompt-set-calculated-regexps-3) (python-shell-prompt-set-calculated-regexps-4) (python-shell-prompt-set-calculated-regexps-5) (python-shell-prompt-set-calculated-regexps-6) (python-util-valid-regexp-p-1): New tests.
Diffstat (limited to 'test/automated/python-tests.el')
-rw-r--r--test/automated/python-tests.el486
1 files changed, 440 insertions, 46 deletions
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 3a4eda36bfe..a60da31e44c 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -1773,8 +1773,8 @@ Using `python-shell-interpreter' and
1773 (proc-name (python-shell-get-process-name nil)) 1773 (proc-name (python-shell-get-process-name nil))
1774 (shell-buffer 1774 (shell-buffer
1775 (python-tests-with-temp-buffer 1775 (python-tests-with-temp-buffer
1776 "" (python-shell-make-comint 1776 "" (python-shell-make-comint
1777 (python-shell-parse-command) proc-name))) 1777 (python-shell-parse-command) proc-name)))
1778 (process (get-buffer-process shell-buffer))) 1778 (process (get-buffer-process shell-buffer)))
1779 (unwind-protect 1779 (unwind-protect
1780 (progn 1780 (progn
@@ -1794,8 +1794,8 @@ Using `python-shell-interpreter' and
1794 (proc-name (python-shell-internal-get-process-name)) 1794 (proc-name (python-shell-internal-get-process-name))
1795 (shell-buffer 1795 (shell-buffer
1796 (python-tests-with-temp-buffer 1796 (python-tests-with-temp-buffer
1797 "" (python-shell-make-comint 1797 "" (python-shell-make-comint
1798 (python-shell-parse-command) proc-name nil t))) 1798 (python-shell-parse-command) proc-name nil t)))
1799 (process (get-buffer-process shell-buffer))) 1799 (process (get-buffer-process shell-buffer)))
1800 (unwind-protect 1800 (unwind-protect
1801 (progn 1801 (progn
@@ -1806,6 +1806,79 @@ Using `python-shell-interpreter' and
1806 (should (string= (buffer-name) (format " *%s*" proc-name))))) 1806 (should (string= (buffer-name) (format " *%s*" proc-name)))))
1807 (kill-buffer shell-buffer)))) 1807 (kill-buffer shell-buffer))))
1808 1808
1809(ert-deftest python-shell-make-comint-3 ()
1810 "Check comint creation with overriden python interpreter and args.
1811The command passed to `python-shell-make-comint' as argument must
1812locally override global values set in `python-shell-interpreter'
1813and `python-shell-interpreter-args' in the new shell buffer."
1814 (skip-unless (executable-find python-tests-shell-interpreter))
1815 (let* ((python-shell-setup-codes nil)
1816 (python-shell-interpreter "interpreter")
1817 (python-shell-interpreter-args "--some-args")
1818 (proc-name (python-shell-get-process-name nil))
1819 (interpreter-override
1820 (concat (executable-find python-tests-shell-interpreter) " " "-i"))
1821 (shell-buffer
1822 (python-tests-with-temp-buffer
1823 "" (python-shell-make-comint interpreter-override proc-name nil)))
1824 (process (get-buffer-process shell-buffer)))
1825 (unwind-protect
1826 (progn
1827 (set-process-query-on-exit-flag process nil)
1828 (should (process-live-p process))
1829 (with-current-buffer shell-buffer
1830 (should (eq major-mode 'inferior-python-mode))
1831 (should (string= python-shell-interpreter
1832 (executable-find python-tests-shell-interpreter)))
1833 (should (string= python-shell-interpreter-args "-i"))))
1834 (kill-buffer shell-buffer))))
1835
1836(ert-deftest python-shell-make-comint-4 ()
1837 "Check shell calculated prompts regexps are set."
1838 (skip-unless (executable-find python-tests-shell-interpreter))
1839 (let* ((process-environment process-environment)
1840 (python-shell-setup-codes nil)
1841 (python-shell-interpreter
1842 (executable-find python-tests-shell-interpreter))
1843 (python-shell-interpreter-args "-i")
1844 (python-shell--prompt-calculated-input-regexp nil)
1845 (python-shell--prompt-calculated-output-regexp nil)
1846 (python-shell-prompt-detect-enabled t)
1847 (python-shell-prompt-input-regexps '("extralargeinputprompt" "sml"))
1848 (python-shell-prompt-output-regexps '("extralargeoutputprompt" "sml"))
1849 (python-shell-prompt-regexp "in")
1850 (python-shell-prompt-block-regexp "block")
1851 (python-shell-prompt-pdb-regexp "pdf")
1852 (python-shell-prompt-output-regexp "output")
1853 (startup-code (concat "import sys\n"
1854 "sys.ps1 = 'py> '\n"
1855 "sys.ps2 = '..> '\n"
1856 "sys.ps3 = 'out '\n"))
1857 (startup-file (python-shell--save-temp-file startup-code))
1858 (proc-name (python-shell-get-process-name nil))
1859 (shell-buffer
1860 (progn
1861 (setenv "PYTHONSTARTUP" startup-file)
1862 (python-tests-with-temp-buffer
1863 "" (python-shell-make-comint
1864 (python-shell-parse-command) proc-name nil))))
1865 (process (get-buffer-process shell-buffer)))
1866 (unwind-protect
1867 (progn
1868 (set-process-query-on-exit-flag process nil)
1869 (should (process-live-p process))
1870 (with-current-buffer shell-buffer
1871 (should (eq major-mode 'inferior-python-mode))
1872 (should (string=
1873 python-shell--prompt-calculated-input-regexp
1874 (concat "^\\(extralargeinputprompt\\|\\.\\.> \\|"
1875 "block\\|py> \\|pdf\\|sml\\|in\\)")))
1876 (should (string=
1877 python-shell--prompt-calculated-output-regexp
1878 "^\\(extralargeoutputprompt\\|output\\|out \\|sml\\)"))))
1879 (delete-file startup-file)
1880 (kill-buffer shell-buffer))))
1881
1809(ert-deftest python-shell-get-process-1 () 1882(ert-deftest python-shell-get-process-1 ()
1810 "Check dedicated shell process preference over global." 1883 "Check dedicated shell process preference over global."
1811 (skip-unless (executable-find python-tests-shell-interpreter)) 1884 (skip-unless (executable-find python-tests-shell-interpreter))
@@ -1840,54 +1913,370 @@ Using `python-shell-interpreter' and
1840 (ignore-errors (kill-buffer dedicated-shell-buffer)))))) 1913 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1841 1914
1842(ert-deftest python-shell-get-or-create-process-1 () 1915(ert-deftest python-shell-get-or-create-process-1 ()
1843 "Check shell process creation fallback." 1916 "Check shell dedicated process creation."
1844 :expected-result :failed 1917 (skip-unless (executable-find python-tests-shell-interpreter))
1845 (python-tests-with-temp-file 1918 (python-tests-with-temp-file
1846 "" 1919 ""
1847 ;; XXX: Break early until we can skip stuff. We need to mimic 1920 (let* ((python-shell-interpreter
1848 ;; user interaction because `python-shell-get-or-create-process' 1921 (executable-find python-tests-shell-interpreter))
1849 ;; asks for all arguments interactively when a shell process 1922 (use-dialog-box)
1850 ;; doesn't exist. 1923 (dedicated-process-name (python-shell-get-process-name t))
1851 (should nil) 1924 (dedicated-process
1852 (let* ((python-shell-interpreter 1925 (python-shell-get-or-create-process python-shell-interpreter t))
1853 (executable-find python-tests-shell-interpreter)) 1926 (dedicated-shell-buffer (process-buffer dedicated-process)))
1854 (use-dialog-box) 1927 (unwind-protect
1855 (dedicated-process-name (python-shell-get-process-name t)) 1928 (progn
1856 (dedicated-process (python-shell-get-or-create-process)) 1929 (set-process-query-on-exit-flag dedicated-process nil)
1857 (dedicated-shell-buffer (process-buffer dedicated-process))) 1930 ;; should be dedicated.
1858 (unwind-protect 1931 (should (equal (process-name dedicated-process)
1859 (progn 1932 dedicated-process-name))
1860 (set-process-query-on-exit-flag dedicated-process nil) 1933 (kill-buffer dedicated-shell-buffer)
1861 ;; Prefer dedicated if not buffer exist. 1934 ;; Check there are no processes for current buffer.
1862 (should (equal (process-name dedicated-process) 1935 (should (not (python-shell-get-process))))
1863 dedicated-process-name)) 1936 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1864 (kill-buffer dedicated-shell-buffer) 1937
1865 ;; No buffer available. 1938(ert-deftest python-shell-get-or-create-process-2 ()
1866 (should (not (python-shell-get-process)))) 1939 "Check shell global process creation."
1867 (ignore-errors (kill-buffer dedicated-shell-buffer)))))) 1940 (skip-unless (executable-find python-tests-shell-interpreter))
1941 (python-tests-with-temp-file
1942 ""
1943 (let* ((python-shell-interpreter
1944 (executable-find python-tests-shell-interpreter))
1945 (use-dialog-box)
1946 (process-name (python-shell-get-process-name nil))
1947 (process
1948 (python-shell-get-or-create-process python-shell-interpreter))
1949 (shell-buffer (process-buffer process)))
1950 (unwind-protect
1951 (progn
1952 (set-process-query-on-exit-flag process nil)
1953 ;; should be global.
1954 (should (equal (process-name process) process-name))
1955 (kill-buffer shell-buffer)
1956 ;; Check there are no processes for current buffer.
1957 (should (not (python-shell-get-process))))
1958 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1959
1960(ert-deftest python-shell-get-or-create-process-3 ()
1961 "Check shell dedicated/global process preference."
1962 (skip-unless (executable-find python-tests-shell-interpreter))
1963 (python-tests-with-temp-file
1964 ""
1965 (let* ((python-shell-interpreter
1966 (executable-find python-tests-shell-interpreter))
1967 (use-dialog-box)
1968 (dedicated-process-name (python-shell-get-process-name t))
1969 (global-process)
1970 (dedicated-process))
1971 (unwind-protect
1972 (progn
1973 ;; Create global process
1974 (run-python python-shell-interpreter nil)
1975 (setq global-process (get-buffer-process "*Python*"))
1976 (should global-process)
1977 (set-process-query-on-exit-flag global-process nil)
1978 ;; Create dedicated process
1979 (run-python python-shell-interpreter t)
1980 (setq dedicated-process (get-process dedicated-process-name))
1981 (should dedicated-process)
1982 (set-process-query-on-exit-flag dedicated-process nil)
1983 ;; Prefer dedicated.
1984 (should (equal (python-shell-get-or-create-process)
1985 dedicated-process))
1986 ;; Kill the dedicated so the global takes over.
1987 (kill-buffer (process-buffer dedicated-process))
1988 ;; Detect global.
1989 (should (equal (python-shell-get-or-create-process) global-process))
1990 ;; Kill the global.
1991 (kill-buffer (process-buffer global-process))
1992 ;; Check there are no processes for current buffer.
1993 (should (not (python-shell-get-process))))
1994 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1868 1995
1869(ert-deftest python-shell-internal-get-or-create-process-1 () 1996(ert-deftest python-shell-internal-get-or-create-process-1 ()
1870 "Check internal shell process creation fallback." 1997 "Check internal shell process creation fallback."
1871 (skip-unless (executable-find python-tests-shell-interpreter)) 1998 (skip-unless (executable-find python-tests-shell-interpreter))
1872 (python-tests-with-temp-file 1999 (python-tests-with-temp-file
1873 "" 2000 ""
1874 (should (not (process-live-p (python-shell-internal-get-process-name)))) 2001 (should (not (process-live-p (python-shell-internal-get-process-name))))
1875 (let* ((python-shell-interpreter 2002 (let* ((python-shell-interpreter
1876 (executable-find python-tests-shell-interpreter)) 2003 (executable-find python-tests-shell-interpreter))
1877 (internal-process-name (python-shell-internal-get-process-name)) 2004 (internal-process-name (python-shell-internal-get-process-name))
1878 (internal-process (python-shell-internal-get-or-create-process)) 2005 (internal-process (python-shell-internal-get-or-create-process))
1879 (internal-shell-buffer (process-buffer internal-process))) 2006 (internal-shell-buffer (process-buffer internal-process)))
1880 (unwind-protect 2007 (unwind-protect
1881 (progn 2008 (progn
1882 (set-process-query-on-exit-flag internal-process nil) 2009 (set-process-query-on-exit-flag internal-process nil)
1883 (should (equal (process-name internal-process) 2010 (should (equal (process-name internal-process)
1884 internal-process-name)) 2011 internal-process-name))
1885 (should (equal internal-process 2012 (should (equal internal-process
1886 (python-shell-internal-get-or-create-process))) 2013 (python-shell-internal-get-or-create-process)))
1887 ;; No user buffer available. 2014 ;; Assert the internal process is not a user process
1888 (should (not (python-shell-get-process))) 2015 (should (not (python-shell-get-process)))
1889 (kill-buffer internal-shell-buffer)) 2016 (kill-buffer internal-shell-buffer))
1890 (ignore-errors (kill-buffer internal-shell-buffer)))))) 2017 (ignore-errors (kill-buffer internal-shell-buffer))))))
2018
2019(ert-deftest python-shell-prompt-detect-1 ()
2020 "Check prompt autodetection."
2021 (skip-unless (executable-find python-tests-shell-interpreter))
2022 (let ((process-environment process-environment))
2023 ;; Ensure no startup file is enabled
2024 (setenv "PYTHONSTARTUP" "")
2025 (should python-shell-prompt-detect-enabled)
2026 (should (equal (python-shell-prompt-detect) '(">>> " "... " "")))))
2027
2028(ert-deftest python-shell-prompt-detect-2 ()
2029 "Check prompt autodetection with startup file. Bug#17370."
2030 (skip-unless (executable-find python-tests-shell-interpreter))
2031 (let* ((process-environment process-environment)
2032 (startup-code (concat "import sys\n"
2033 "sys.ps1 = 'py> '\n"
2034 "sys.ps2 = '..> '\n"
2035 "sys.ps3 = 'out '\n"))
2036 (startup-file (python-shell--save-temp-file startup-code)))
2037 (unwind-protect
2038 (progn
2039 ;; Ensure startup file is enabled
2040 (setenv "PYTHONSTARTUP" startup-file)
2041 (should python-shell-prompt-detect-enabled)
2042 (should (equal (python-shell-prompt-detect) '("py> " "..> " "out "))))
2043 (ignore-errors (delete-file startup-file)))))
2044
2045(ert-deftest python-shell-prompt-detect-3 ()
2046 "Check prompts are not autodetected when feature is disabled."
2047 (skip-unless (executable-find python-tests-shell-interpreter))
2048 (let ((process-environment process-environment)
2049 (python-shell-prompt-detect-enabled nil))
2050 ;; Ensure no startup file is enabled
2051 (should (not python-shell-prompt-detect-enabled))
2052 (should (not (python-shell-prompt-detect)))))
2053
2054(ert-deftest python-shell-prompt-detect-4 ()
2055 "Check warning is shown when detection fails."
2056 (skip-unless (executable-find python-tests-shell-interpreter))
2057 (let* ((process-environment process-environment)
2058 ;; Trigger failure by removing prompts in the startup file
2059 (startup-code (concat "import sys\n"
2060 "sys.ps1 = ''\n"
2061 "sys.ps2 = ''\n"
2062 "sys.ps3 = ''\n"))
2063 (startup-file (python-shell--save-temp-file startup-code)))
2064 (unwind-protect
2065 (progn
2066 (kill-buffer (get-buffer-create "*Warnings*"))
2067 (should (not (get-buffer "*Warnings*")))
2068 (setenv "PYTHONSTARTUP" startup-file)
2069 (should python-shell-prompt-detect-failure-warning)
2070 (should python-shell-prompt-detect-enabled)
2071 (should (not (python-shell-prompt-detect)))
2072 (should (get-buffer "*Warnings*")))
2073 (ignore-errors (delete-file startup-file)))))
2074
2075(ert-deftest python-shell-prompt-detect-5 ()
2076 "Check disabled warnings are not shown when detection fails."
2077 (skip-unless (executable-find python-tests-shell-interpreter))
2078 (let* ((process-environment process-environment)
2079 (startup-code (concat "import sys\n"
2080 "sys.ps1 = ''\n"
2081 "sys.ps2 = ''\n"
2082 "sys.ps3 = ''\n"))
2083 (startup-file (python-shell--save-temp-file startup-code))
2084 (python-shell-prompt-detect-failure-warning nil))
2085 (unwind-protect
2086 (progn
2087 (kill-buffer (get-buffer-create "*Warnings*"))
2088 (should (not (get-buffer "*Warnings*")))
2089 (setenv "PYTHONSTARTUP" startup-file)
2090 (should (not python-shell-prompt-detect-failure-warning))
2091 (should python-shell-prompt-detect-enabled)
2092 (should (not (python-shell-prompt-detect)))
2093 (should (not (get-buffer "*Warnings*"))))
2094 (ignore-errors (delete-file startup-file)))))
2095
2096(ert-deftest python-shell-prompt-detect-6 ()
2097 "Warnings are not shown when detection is disabled."
2098 (skip-unless (executable-find python-tests-shell-interpreter))
2099 (let* ((process-environment process-environment)
2100 (startup-code (concat "import sys\n"
2101 "sys.ps1 = ''\n"
2102 "sys.ps2 = ''\n"
2103 "sys.ps3 = ''\n"))
2104 (startup-file (python-shell--save-temp-file startup-code))
2105 (python-shell-prompt-detect-failure-warning t)
2106 (python-shell-prompt-detect-enabled nil))
2107 (unwind-protect
2108 (progn
2109 (kill-buffer (get-buffer-create "*Warnings*"))
2110 (should (not (get-buffer "*Warnings*")))
2111 (setenv "PYTHONSTARTUP" startup-file)
2112 (should python-shell-prompt-detect-failure-warning)
2113 (should (not python-shell-prompt-detect-enabled))
2114 (should (not (python-shell-prompt-detect)))
2115 (should (not (get-buffer "*Warnings*"))))
2116 (ignore-errors (delete-file startup-file)))))
2117
2118(ert-deftest python-shell-prompt-validate-regexps-1 ()
2119 "Check `python-shell-prompt-input-regexps' are validated."
2120 (let* ((python-shell-prompt-input-regexps '("\\("))
2121 (error-data (should-error (python-shell-prompt-validate-regexps)
2122 :type 'user-error)))
2123 (should
2124 (string= (cadr error-data)
2125 "Invalid regexp \\( in `python-shell-prompt-input-regexps'"))))
2126
2127(ert-deftest python-shell-prompt-validate-regexps-2 ()
2128 "Check `python-shell-prompt-output-regexps' are validated."
2129 (let* ((python-shell-prompt-output-regexps '("\\("))
2130 (error-data (should-error (python-shell-prompt-validate-regexps)
2131 :type 'user-error)))
2132 (should
2133 (string= (cadr error-data)
2134 "Invalid regexp \\( in `python-shell-prompt-output-regexps'"))))
2135
2136(ert-deftest python-shell-prompt-validate-regexps-3 ()
2137 "Check `python-shell-prompt-regexp' is validated."
2138 (let* ((python-shell-prompt-regexp "\\(")
2139 (error-data (should-error (python-shell-prompt-validate-regexps)
2140 :type 'user-error)))
2141 (should
2142 (string= (cadr error-data)
2143 "Invalid regexp \\( in `python-shell-prompt-regexp'"))))
2144
2145(ert-deftest python-shell-prompt-validate-regexps-4 ()
2146 "Check `python-shell-prompt-block-regexp' is validated."
2147 (let* ((python-shell-prompt-block-regexp "\\(")
2148 (error-data (should-error (python-shell-prompt-validate-regexps)
2149 :type 'user-error)))
2150 (should
2151 (string= (cadr error-data)
2152 "Invalid regexp \\( in `python-shell-prompt-block-regexp'"))))
2153
2154(ert-deftest python-shell-prompt-validate-regexps-5 ()
2155 "Check `python-shell-prompt-pdb-regexp' is validated."
2156 (let* ((python-shell-prompt-pdb-regexp "\\(")
2157 (error-data (should-error (python-shell-prompt-validate-regexps)
2158 :type 'user-error)))
2159 (should
2160 (string= (cadr error-data)
2161 "Invalid regexp \\( in `python-shell-prompt-pdb-regexp'"))))
2162
2163(ert-deftest python-shell-prompt-validate-regexps-6 ()
2164 "Check `python-shell-prompt-output-regexp' is validated."
2165 (let* ((python-shell-prompt-output-regexp "\\(")
2166 (error-data (should-error (python-shell-prompt-validate-regexps)
2167 :type 'user-error)))
2168 (should
2169 (string= (cadr error-data)
2170 "Invalid regexp \\( in `python-shell-prompt-output-regexp'"))))
2171
2172(ert-deftest python-shell-prompt-validate-regexps-7 ()
2173 "Check default regexps are valid."
2174 ;; should not signal error
2175 (python-shell-prompt-validate-regexps))
2176
2177(ert-deftest python-shell-prompt-set-calculated-regexps-1 ()
2178 "Check regexps are validated."
2179 (let* ((python-shell-prompt-output-regexp '("\\("))
2180 (python-shell--prompt-calculated-input-regexp nil)
2181 (python-shell--prompt-calculated-output-regexp nil)
2182 (python-shell-prompt-detect-enabled nil)
2183 (error-data (should-error (python-shell-prompt-set-calculated-regexps)
2184 :type 'user-error)))
2185 (should
2186 (string= (cadr error-data)
2187 "Invalid regexp \\( in `python-shell-prompt-output-regexp'"))))
2188
2189(ert-deftest python-shell-prompt-set-calculated-regexps-2 ()
2190 "Check `python-shell-prompt-input-regexps' are set."
2191 (let* ((python-shell-prompt-input-regexps '("my" "prompt"))
2192 (python-shell-prompt-output-regexps '(""))
2193 (python-shell-prompt-regexp "")
2194 (python-shell-prompt-block-regexp "")
2195 (python-shell-prompt-pdb-regexp "")
2196 (python-shell-prompt-output-regexp "")
2197 (python-shell--prompt-calculated-input-regexp nil)
2198 (python-shell--prompt-calculated-output-regexp nil)
2199 (python-shell-prompt-detect-enabled nil))
2200 (python-shell-prompt-set-calculated-regexps)
2201 (should (string= python-shell--prompt-calculated-input-regexp
2202 "^\\(prompt\\|my\\|\\)"))))
2203
2204(ert-deftest python-shell-prompt-set-calculated-regexps-3 ()
2205 "Check `python-shell-prompt-output-regexps' are set."
2206 (let* ((python-shell-prompt-input-regexps '(""))
2207 (python-shell-prompt-output-regexps '("my" "prompt"))
2208 (python-shell-prompt-regexp "")
2209 (python-shell-prompt-block-regexp "")
2210 (python-shell-prompt-pdb-regexp "")
2211 (python-shell-prompt-output-regexp "")
2212 (python-shell--prompt-calculated-input-regexp nil)
2213 (python-shell--prompt-calculated-output-regexp nil)
2214 (python-shell-prompt-detect-enabled nil))
2215 (python-shell-prompt-set-calculated-regexps)
2216 (should (string= python-shell--prompt-calculated-output-regexp
2217 "^\\(prompt\\|my\\|\\)"))))
2218
2219(ert-deftest python-shell-prompt-set-calculated-regexps-4 ()
2220 "Check user defined prompts are set."
2221 (let* ((python-shell-prompt-input-regexps '(""))
2222 (python-shell-prompt-output-regexps '(""))
2223 (python-shell-prompt-regexp "prompt")
2224 (python-shell-prompt-block-regexp "block")
2225 (python-shell-prompt-pdb-regexp "pdb")
2226 (python-shell-prompt-output-regexp "output")
2227 (python-shell--prompt-calculated-input-regexp nil)
2228 (python-shell--prompt-calculated-output-regexp nil)
2229 (python-shell-prompt-detect-enabled nil))
2230 (python-shell-prompt-set-calculated-regexps)
2231 (should (string= python-shell--prompt-calculated-input-regexp
2232 "^\\(prompt\\|block\\|pdb\\|\\)"))
2233 (should (string= python-shell--prompt-calculated-output-regexp
2234 "^\\(output\\|\\)"))))
2235
2236(ert-deftest python-shell-prompt-set-calculated-regexps-5 ()
2237 "Check order of regexps (larger first)."
2238 (let* ((python-shell-prompt-input-regexps '("extralargeinputprompt" "sml"))
2239 (python-shell-prompt-output-regexps '("extralargeoutputprompt" "sml"))
2240 (python-shell-prompt-regexp "in")
2241 (python-shell-prompt-block-regexp "block")
2242 (python-shell-prompt-pdb-regexp "pdf")
2243 (python-shell-prompt-output-regexp "output")
2244 (python-shell--prompt-calculated-input-regexp nil)
2245 (python-shell--prompt-calculated-output-regexp nil)
2246 (python-shell-prompt-detect-enabled nil))
2247 (python-shell-prompt-set-calculated-regexps)
2248 (should (string= python-shell--prompt-calculated-input-regexp
2249 "^\\(extralargeinputprompt\\|block\\|pdf\\|sml\\|in\\)"))
2250 (should (string= python-shell--prompt-calculated-output-regexp
2251 "^\\(extralargeoutputprompt\\|output\\|sml\\)"))))
2252
2253(ert-deftest python-shell-prompt-set-calculated-regexps-6 ()
2254 "Check detected prompts are included `regexp-quote'd."
2255 (skip-unless (executable-find python-tests-shell-interpreter))
2256 (let* ((python-shell-prompt-input-regexps '(""))
2257 (python-shell-prompt-output-regexps '(""))
2258 (python-shell-prompt-regexp "")
2259 (python-shell-prompt-block-regexp "")
2260 (python-shell-prompt-pdb-regexp "")
2261 (python-shell-prompt-output-regexp "")
2262 (python-shell--prompt-calculated-input-regexp nil)
2263 (python-shell--prompt-calculated-output-regexp nil)
2264 (python-shell-prompt-detect-enabled t)
2265 (process-environment process-environment)
2266 (startup-code (concat "import sys\n"
2267 "sys.ps1 = 'p.> '\n"
2268 "sys.ps2 = '..> '\n"
2269 "sys.ps3 = 'o.t '\n"))
2270 (startup-file (python-shell--save-temp-file startup-code)))
2271 (unwind-protect
2272 (progn
2273 (setenv "PYTHONSTARTUP" startup-file)
2274 (python-shell-prompt-set-calculated-regexps)
2275 (should (string= python-shell--prompt-calculated-input-regexp
2276 "^\\(\\.\\.> \\|p\\.> \\|\\)"))
2277 (should (string= python-shell--prompt-calculated-output-regexp
2278 "^\\(o\\.t \\|\\)")))
2279 (ignore-errors (delete-file startup-file)))))
1891 2280
1892 2281
1893;;; Shell completion 2282;;; Shell completion
@@ -3269,6 +3658,11 @@ def foo(a, b, c):
3269 (python-util-forward-comment -1) 3658 (python-util-forward-comment -1)
3270 (should (= (point) (point-min))))) 3659 (should (= (point) (point-min)))))
3271 3660
3661(ert-deftest python-util-valid-regexp-p-1 ()
3662 (should (python-util-valid-regexp-p ""))
3663 (should (python-util-valid-regexp-p python-shell-prompt-regexp))
3664 (should (not (python-util-valid-regexp-p "\\("))))
3665
3272 3666
3273;;; Electricity 3667;;; Electricity
3274 3668