emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Retrieve comint-process output from ert test.


From: Fabian Ezequiel Gallina
Subject: Retrieve comint-process output from ert test.
Date: Thu, 21 Feb 2013 18:18:54 -0300

As I'm moving forward into getting most of python.el covered by tests
I got to a road block I can't solve.

I'm trying to send some arbitrary stuff via python-shell-send-region
(which ends up calling comint-send-string) and retrieve the resulting
output from it.

>From my understanding accept-process-output should do the trick, but I
cannot make it work reliably and I ended up trying things till it
worked, the result is that I needed to call "(sleep-for 1)" two times
in order to get the output I wanted (surprisingly "(sleep-for 2)"
wouldn't help).

This is totally error prone, but it's the only solution I found, so
the question is: what's the good, reliable way to do this?.

Here's the code snippet I'm using to test this behavior in
test/automated/python-tests.el:

    (ert-deftest python-shell-internal-send-region-1 ()
      "Check `python-shell-send-region'."
      :expected-result (if (executable-find python-tests-shell-interpreter)
                           :passed
                         :failed)
      (python-tests-with-temp-buffer
       "

    import inspect
    def hello():
        '''prints hello'''
        print ('hello')
    hello()
    print ('world')
    print (inspect.getsourcelines(hello))
    "
       (let* ((python-shell-interpreter
               (executable-find python-tests-shell-interpreter))
              (shell-buffer
               (python-shell-make-comint
                (python-shell-parse-command)
                (python-shell-get-process-name nil)))
              (process (get-buffer-process shell-buffer)))
         (dotimes (i 3)
           (sleep-for 2)
           (python-shell-send-region
            (point-min)
            (python-tests-look-at "print ('world')" 1 t))
           (accept-process-output process)
           (with-current-buffer shell-buffer
             (should (string=
                      (buffer-substring-no-properties
                       comint-last-output-start
                       (overlay-start comint-last-prompt-overlay))
                      "hello\n")))))))


Regards,
-- 
Fabián E. Gallina
http://www.from-the-cloud.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]