1edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep# Test to see if openpty works. (But don't worry if it isn't available.) 2edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 3edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepimport os, unittest 4edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepfrom test.test_support import run_unittest 5edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 6edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif not hasattr(os, "openpty"): 7edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep raise unittest.SkipTest, "No openpty() available." 8edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 9edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 10edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepclass OpenptyTest(unittest.TestCase): 11edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep def test(self): 12edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep master, slave = os.openpty() 13edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep if not os.isatty(slave): 14edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep self.fail("Slave-end of pty is not a terminal.") 15edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 16edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep os.write(slave, 'Ping!') 17edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep self.assertEqual(os.read(master, 1024), 'Ping!') 18edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 19edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepdef test_main(): 20edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep run_unittest(OpenptyTest) 21edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep 22edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoepif __name__ == '__main__': 23edbb763a2b63074cd468a5d33a17908b2cc0654Jeff Vander Stoep test_main() 24