~ubuntu-branches/ubuntu/trusty/pexpect/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/test_interact.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio, Thomas Kluyver, Jakub Wilk, Jackson Doak, Andrew Starr-Bochicchio
  • Date: 2013-12-06 20:20:26 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131206202026-9k9oixbv7e8ke30q
Tags: 3.0-1
* Team upload.

[ Thomas Kluyver ]
* New upstream release. Closes: #729518
* Add packaging for Python 3.
* Use pybuild for packaging.

[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Jackson Doak ]
* Create debian/python3-pexpect.docs

[ Andrew Starr-Bochicchio ]
* Remove empty debian/patches dir.
* Move documentation and examples into a new python-pexpect-doc
  package. They are shared between the Python 2 and Python 3 packages,
  so there is no need to install them with both.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
'''
 
4
PEXPECT LICENSE
 
5
 
 
6
    This license is approved by the OSI and FSF as GPL-compatible.
 
7
        http://opensource.org/licenses/isc-license.txt
 
8
 
 
9
    Copyright (c) 2012, Noah Spurrier <noah@noah.org>
 
10
    PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
 
11
    PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
 
12
    COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
 
13
    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
14
    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
15
    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
16
    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
17
    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
18
    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
19
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
20
 
 
21
'''
 
22
from __future__ import print_function
 
23
from __future__ import unicode_literals
 
24
 
 
25
import pexpect
 
26
import unittest
 
27
import PexpectTestCase
 
28
 
 
29
class InteractTestCase (PexpectTestCase.PexpectTestCase):
 
30
 
 
31
    def test_interact (self):
 
32
        p = pexpect.spawn(str('%s interact.py' % (self.PYTHONBIN,)))
 
33
        p.expect('<in >')
 
34
        p.sendline (b'Hello')
 
35
        p.sendline (b'there')
 
36
        p.sendline (b'Mr. Python')
 
37
        p.expect (b'<out>Hello')
 
38
        p.expect (b'<out>there')
 
39
        p.expect (b'<out>Mr. Python')
 
40
        assert p.isalive()
 
41
        p.sendeof ()
 
42
        p.expect (pexpect.EOF)
 
43
        assert not p.isalive()
 
44
        assert p.exitstatus == 0, (p.exitstatus, p.before)
 
45
 
 
46
    def test_interact_unicode (self):
 
47
        p = pexpect.spawnu(str('%s interact_unicode.py' % (self.PYTHONBIN,)))
 
48
        try:
 
49
            p.expect('<in >')
 
50
            p.sendline ('Hello')
 
51
            p.sendline ('theré')
 
52
            p.sendline ('Mr. Pyþon')
 
53
            p.expect ('<out>Hello')
 
54
            p.expect ('<out>theré')
 
55
            p.expect ('<out>Mr. Pyþon')
 
56
            assert p.isalive()
 
57
            p.sendeof ()
 
58
            p.expect (pexpect.EOF)
 
59
            assert not p.isalive()
 
60
            assert p.exitstatus == 0, (p.exitstatus, p.before)
 
61
        except:
 
62
            print(p.before)
 
63
            raise
 
64
 
 
65
 
 
66
if __name__ == '__main__':
 
67
    unittest.main()
 
68
 
 
69
suite = unittest.makeSuite(InteractTestCase, 'test')
 
70