mirror of
https://github.com/clearml/wexpect-venv
synced 2025-06-26 18:15:52 +00:00
[CLN] ADD more deprecation warning; [ADD] readline testcase
This commit is contained in:
parent
2cca9aa5f2
commit
a338f1fad7
13
README.md
13
README.md
@ -41,6 +41,19 @@ child.sendline('exit')
|
|||||||
|
|
||||||
For more information see [examples](./examples) folder.
|
For more information see [examples](./examples) folder.
|
||||||
|
|
||||||
|
## Code Clean up!
|
||||||
|
|
||||||
|
Wexpect works only on Windows platforms. There are handy tools for other platforms. Therefore I will
|
||||||
|
remove any non-windows code. If you see following warning in your console please contact me to
|
||||||
|
prevent the removal of that function.
|
||||||
|
|
||||||
|
```
|
||||||
|
################################## WARNING ##################################
|
||||||
|
<some func> is deprecated, and will be removed soon.
|
||||||
|
Please contact me and report it at github.com/raczben/wexpect if you use it.
|
||||||
|
################################## WARNING ##################################
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
## What is it?
|
## What is it?
|
||||||
|
|
||||||
|
|||||||
15
tests/lines_printer.py
Normal file
15
tests/lines_printer.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'''
|
||||||
|
This is is a very basic stdio handler script. This is used by python.py example.
|
||||||
|
'''
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Read an integer from the user:
|
||||||
|
print('Give a small integer: ', end='')
|
||||||
|
num = input()
|
||||||
|
|
||||||
|
# Wait the given time
|
||||||
|
for i in range(int(num)):
|
||||||
|
print('waiter ' + str(i))
|
||||||
|
time.sleep(0.2)
|
||||||
|
print('Bye!')
|
||||||
83
tests/test_readline.py
Normal file
83
tests/test_readline.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
'''
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2008 Noah Spurrier, Richard Holden, Marco Molteni, Kimberley Burchett, Robert Stone,
|
||||||
|
Hartmut Goebel, Chad Schroeder, Erick Tryzelaar, Dave Kirby, Ids vander Molen, George Todd,
|
||||||
|
Noel Taylor, Nicolas D. Cesar, Alexander Gattin, Geoffrey Marshall, Francisco Lourenco, Glen Mabey,
|
||||||
|
Karthik Gurusamy, Fernando Perez, Corey Minyard, Jon Cohen, Guillaume Chazarain, Andrew Ryan,
|
||||||
|
Nick Craig-Wood, Andrew Stone, Jorgen Grahn, Benedek Racz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
'''
|
||||||
|
import wexpect
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import unittest
|
||||||
|
from . import PexpectTestCase
|
||||||
|
|
||||||
|
here = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
sys.path.insert(0, here)
|
||||||
|
|
||||||
|
print(wexpect.__version__)
|
||||||
|
|
||||||
|
# With quotes (C:\Program Files\Python37\python.exe needs quotes)
|
||||||
|
python_executable = '"' + sys.executable + '" '
|
||||||
|
child_script = here + '\\lines_printer.py'
|
||||||
|
|
||||||
|
class ReadLineTestCase(PexpectTestCase.PexpectTestCase):
|
||||||
|
def testReadline(self):
|
||||||
|
fooPath = python_executable + ' ' + child_script
|
||||||
|
prompt = ': '
|
||||||
|
num = 5
|
||||||
|
|
||||||
|
# Start the child process
|
||||||
|
p = wexpect.spawn(fooPath)
|
||||||
|
# Wait for prompt
|
||||||
|
p.expect(prompt)
|
||||||
|
p.sendline(str(num))
|
||||||
|
p.expect('Bye!\r\n')
|
||||||
|
expected_lines = p.before.splitlines(True) # Keep the line end
|
||||||
|
expected_lines += [p.match.group()]
|
||||||
|
|
||||||
|
# Start the child process
|
||||||
|
p = wexpect.spawn(fooPath)
|
||||||
|
# Wait for prompt
|
||||||
|
p.expect(prompt)
|
||||||
|
|
||||||
|
p.sendline(str(num))
|
||||||
|
for i in range(num +2): # +1 the line of sendline +1: Bye
|
||||||
|
line = p.readline()
|
||||||
|
self.assertEqual(expected_lines[i], line)
|
||||||
|
|
||||||
|
# Start the child process
|
||||||
|
p = wexpect.spawn(fooPath)
|
||||||
|
# Wait for prompt
|
||||||
|
p.expect(prompt)
|
||||||
|
|
||||||
|
p.sendline(str(num))
|
||||||
|
readlines_lines = p.readlines()
|
||||||
|
self.assertEqual(expected_lines, readlines_lines)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
suite = unittest.makeSuite(ReadLineTestCase,'test')
|
||||||
@ -633,6 +633,8 @@ class spawn_unix (object):
|
|||||||
self.closed = False
|
self.closed = False
|
||||||
|
|
||||||
def __fork_pty(self):
|
def __fork_pty(self):
|
||||||
|
warnings.warn(no_unix_deprecation_warning.format("spawn_unix::__fork_pty"), DeprecationWarning)
|
||||||
|
|
||||||
|
|
||||||
"""This implements a substitute for the forkpty system call. This
|
"""This implements a substitute for the forkpty system call. This
|
||||||
should be more portable than the pty.fork() function. Specifically,
|
should be more portable than the pty.fork() function. Specifically,
|
||||||
@ -672,6 +674,7 @@ class spawn_unix (object):
|
|||||||
return pid, parent_fd
|
return pid, parent_fd
|
||||||
|
|
||||||
def __pty_make_controlling_tty(self, tty_fd):
|
def __pty_make_controlling_tty(self, tty_fd):
|
||||||
|
warnings.warn(no_unix_deprecation_warning.format("spawn_unix::__pty_make_controlling_tty"), DeprecationWarning)
|
||||||
|
|
||||||
"""This makes the pseudo-terminal the controlling tty. This should be
|
"""This makes the pseudo-terminal the controlling tty. This should be
|
||||||
more portable than the pty.fork() function. Specifically, this should
|
more portable than the pty.fork() function. Specifically, this should
|
||||||
@ -738,6 +741,7 @@ class spawn_unix (object):
|
|||||||
|
|
||||||
def flush (self): # File-like object.
|
def flush (self): # File-like object.
|
||||||
|
|
||||||
|
warnings.warn(no_unix_deprecation_warning.format("spawn_unix::flush"), DeprecationWarning)
|
||||||
"""This does nothing. It is here to support the interface for a
|
"""This does nothing. It is here to support the interface for a
|
||||||
File-like object. """
|
File-like object. """
|
||||||
|
|
||||||
@ -835,6 +839,7 @@ class spawn_unix (object):
|
|||||||
termios.tcsetattr(self.child_fd, termios.TCSANOW, attr)
|
termios.tcsetattr(self.child_fd, termios.TCSANOW, attr)
|
||||||
|
|
||||||
def read_nonblocking (self, size = 1, timeout = -1):
|
def read_nonblocking (self, size = 1, timeout = -1):
|
||||||
|
warnings.warn(no_unix_deprecation_warning.format("spawn_unix::read_nonblocking"), DeprecationWarning)
|
||||||
|
|
||||||
"""This reads at most size characters from the child application. It
|
"""This reads at most size characters from the child application. It
|
||||||
includes a timeout. If the read does not complete within the timeout
|
includes a timeout. If the read does not complete within the timeout
|
||||||
@ -1006,6 +1011,8 @@ class spawn_unix (object):
|
|||||||
self.write (s)
|
self.write (s)
|
||||||
|
|
||||||
def send(self, s):
|
def send(self, s):
|
||||||
|
warnings.warn(no_unix_deprecation_warning.format("spawn_unix::send"), DeprecationWarning)
|
||||||
|
|
||||||
|
|
||||||
"""This sends a string to the child process. This returns the number of
|
"""This sends a string to the child process. This returns the number of
|
||||||
bytes written. If a log file was set then the data is also written to
|
bytes written. If a log file was set then the data is also written to
|
||||||
@ -1178,6 +1185,7 @@ class spawn_unix (object):
|
|||||||
return self.exitstatus
|
return self.exitstatus
|
||||||
|
|
||||||
def isalive(self):
|
def isalive(self):
|
||||||
|
warnings.warn(no_unix_deprecation_warning.format("spawn_unix::isalive"), DeprecationWarning)
|
||||||
|
|
||||||
"""This tests if the child process is running or not. This is
|
"""This tests if the child process is running or not. This is
|
||||||
non-blocking. If the child was terminated then this will read the
|
non-blocking. If the child was terminated then this will read the
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user