From a2ef749ffa317ca9fdf4accb8c70165907814cf8 Mon Sep 17 00:00:00 2001 From: Tapple Date: Tue, 21 Feb 2023 14:19:59 -0500 Subject: renamed module socket_spawn to socket_expect --- tests/test_socket_expect.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ tests/test_socketspawn.py | 72 --------------------------------------------- 2 files changed, 72 insertions(+), 72 deletions(-) create mode 100644 tests/test_socket_expect.py delete mode 100644 tests/test_socketspawn.py (limited to 'tests') diff --git a/tests/test_socket_expect.py b/tests/test_socket_expect.py new file mode 100644 index 0000000..8b22f3f --- /dev/null +++ b/tests/test_socket_expect.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' +import pexpect +from pexpect import socket_expect +import unittest +from . import PexpectTestCase +import socket + +def open_file_socket(filename): + read_socket, write_socket = socket.socketpair() + with open(filename, "rb") as file: + write_socket.sendall(file.read()) + write_socket.close() + return read_socket + +class ExpectTestCase(PexpectTestCase.PexpectTestCase): + def setUp(self): + print(self.id()) + PexpectTestCase.PexpectTestCase.setUp(self) + + def test_socket (self): + socket = open_file_socket('TESTDATA.txt') + s = socket_expect.SocketSpawn(socket) + s.expect(b'This is the end of test data:') + s.expect(pexpect.EOF) + self.assertEqual(s.before, b' END\n') + + def test_maxread (self): + socket = open_file_socket('TESTDATA.txt') + s = socket_expect.SocketSpawn(socket) + s.maxread = 100 + s.expect('2') + s.expect ('This is the end of test data:') + s.expect (pexpect.EOF) + self.assertEqual(s.before, b' END\n') + + def test_socket_isalive (self): + socket = open_file_socket('TESTDATA.txt') + s = socket_expect.SocketSpawn(socket) + assert s.isalive() + s.close() + assert not s.isalive(), "Should not be alive after close()" + + def test_socket_isatty (self): + socket = open_file_socket('TESTDATA.txt') + s = socket_expect.SocketSpawn(socket) + assert not s.isatty() + s.close() + + +if __name__ == '__main__': + unittest.main() + +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) diff --git a/tests/test_socketspawn.py b/tests/test_socketspawn.py deleted file mode 100644 index 2db5e79..0000000 --- a/tests/test_socketspawn.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -''' -PEXPECT LICENSE - - This license is approved by the OSI and FSF as GPL-compatible. - http://opensource.org/licenses/isc-license.txt - - Copyright (c) 2012, Noah Spurrier - PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY - PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE - COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -''' -import pexpect -from pexpect import socket_spawn -import unittest -from . import PexpectTestCase -import socket - -def open_file_socket(filename): - read_socket, write_socket = socket.socketpair() - with open(filename, "rb") as file: - write_socket.sendall(file.read()) - write_socket.close() - return read_socket - -class ExpectTestCase(PexpectTestCase.PexpectTestCase): - def setUp(self): - print(self.id()) - PexpectTestCase.PexpectTestCase.setUp(self) - - def test_socket (self): - socket = open_file_socket('TESTDATA.txt') - s = socket_spawn.SocketSpawn(socket) - s.expect(b'This is the end of test data:') - s.expect(pexpect.EOF) - self.assertEqual(s.before, b' END\n') - - def test_maxread (self): - socket = open_file_socket('TESTDATA.txt') - s = socket_spawn.SocketSpawn(socket) - s.maxread = 100 - s.expect('2') - s.expect ('This is the end of test data:') - s.expect (pexpect.EOF) - self.assertEqual(s.before, b' END\n') - - def test_socket_isalive (self): - socket = open_file_socket('TESTDATA.txt') - s = socket_spawn.SocketSpawn(socket) - assert s.isalive() - s.close() - assert not s.isalive(), "Should not be alive after close()" - - def test_socket_isatty (self): - socket = open_file_socket('TESTDATA.txt') - s = socket_spawn.SocketSpawn(socket) - assert not s.isatty() - s.close() - - -if __name__ == '__main__': - unittest.main() - -suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) -- cgit v1.2.1