Repository: RustPython/RustPython
File: Lib/test/test_tty.py (Python)

Code before:
        mode = termios.tcgetattr(self.fd)
        self.assertEqual(mode, self.mode)
        tty.cfmakeraw(mode)
        self.check_raw(mode)
        self.assertEqual(mode[4], self.mode[4])
        self.assertEqual(mode[5], self.mode[5])

    def test_cfmakecbreak(self):
        mode = termios.tcgetattr(self.fd)
        self.assertEqual(mode, self.mode)
        tty.cfmakecbreak(mode)
        self.check_cbreak(mode)
        self.assertEqual(mode[1], self.mode[1])
        self.assertEqual(mode[2], self.mode[2])
        self.assertEqual(mode[4], self.mode[4])
        self.assertEqual(mode[5], self.mode[5])
        mode[tty.IFLAG] |= termios.ICRNL
        tty.cfmakecbreak(mode)
        self.assertEqual(mode[tty.IFLAG] & termios.ICRNL, termios.ICRNL,
                         msg="ICRNL should not be cleared by cbreak")
        mode[tty.IFLAG] &= ~termios.ICRNL
        tty.cfmakecbreak(mode)
        self.assertEqual(mode[tty.IFLAG] & termios.ICRNL, 0,
                         msg="ICRNL should not be set by cbreak")

    @unittest.skip('TODO: RUSTPYTHON; TypeError: Expected type "int" but "FileIO" found.')
    def test_setraw(self):
        mode0 = termios.tcgetattr(self.fd)
        mode1 = tty.setraw(self.fd)
        self.assertEqual(mode1, mode0)
        mode2 = termios.tcgetattr(self.fd)
        self.check_raw(mode2)
        mode3 = tty.setraw(self.fd, termios.TCSANOW)
        self.assertEqual(mode3, mode2)
        tty.setraw(self.stream)
        tty.setraw(fd=self.fd, when=termios.TCSANOW)

    @unittest.skip('TODO: RUSTPYTHON; TypeError: Expected type "int" but "FileIO" found.')
    def test_setcbreak(self):
        mode0 = termios.tcgetattr(self.fd)
        mode1 = tty.setcbreak(self.fd)
        self.assertEqual(mode1, mode0)
        mode2 = termios.tcgetattr(self.fd)
        self.check_cbreak(mode2)
        ICRNL = termios.ICRNL
        self.assertEqual(mode2[tty.IFLAG] & ICRNL, mode0[tty.IFLAG] & ICRNL,
                         msg="ICRNL should not be altered by cbreak")
        mode3 = tty.setcbreak(self.fd, termios.TCSANOW)
        self.assertEqual(mode3, mode2)
        tty.setcbreak(self.stream)
        tty.setcbreak(fd=self.fd, when=termios.TCSANOW)

Review comment (bug):
Unless tests are flaky or they crash, don't skip it. please mark them as expectedFailure. 
Actually, `scripts/fix_test.py` automatically mark failing tests as expectedFailure. This is a good default behavior. (the format is not compatible though)

Code after:
        mode = termios.tcgetattr(self.fd)
        self.assertEqual(mode, self.mode)
        tty.cfmakeraw(mode)
        self.check_raw(mode)
        self.assertEqual(mode[4], self.mode[4])
        self.assertEqual(mode[5], self.mode[5])

    def test_cfmakecbreak(self):
        mode = termios.tcgetattr(self.fd)
        self.assertEqual(mode, self.mode)
        tty.cfmakecbreak(mode)
        self.check_cbreak(mode)
        self.assertEqual(mode[1], self.mode[1])
        self.assertEqual(mode[2], self.mode[2])
        self.assertEqual(mode[4], self.mode[4])
        self.assertEqual(mode[5], self.mode[5])
        mode[tty.IFLAG] |= termios.ICRNL
        tty.cfmakecbreak(mode)
        self.assertEqual(mode[tty.IFLAG] & termios.ICRNL, termios.ICRNL,
                         msg="ICRNL should not be cleared by cbreak")
        mode[tty.IFLAG] &= ~termios.ICRNL
        tty.cfmakecbreak(mode)
        self.assertEqual(mode[tty.IFLAG] & termios.ICRNL, 0,
                         msg="ICRNL should not be set by cbreak")

    @unittest.expectedFailure # TODO: RUSTPYTHON TypeError: Expected type "int" but "FileIO" found.
    def test_setraw(self):
        mode0 = termios.tcgetattr(self.fd)
        mode1 = tty.setraw(self.fd)
        self.assertEqual(mode1, mode0)
        mode2 = termios.tcgetattr(self.fd)
        self.check_raw(mode2)
        mode3 = tty.setraw(self.fd, termios.TCSANOW)
        self.assertEqual(mode3, mode2)
        tty.setraw(self.stream)
        tty.setraw(fd=self.fd, when=termios.TCSANOW)

    @unittest.expectedFailure # TODO: RUSTPYTHON TypeError: Expected type "int" but "FileIO" found.
    def test_setcbreak(self):
        mode0 = termios.tcgetattr(self.fd)
        mode1 = tty.setcbreak(self.fd)
        self.assertEqual(mode1, mode0)
        mode2 = termios.tcgetattr(self.fd)
        self.check_cbreak(mode2)
        ICRNL = termios.ICRNL
        self.assertEqual(mode2[tty.IFLAG] & ICRNL, mode0[tty.IFLAG] & ICRNL,
                         msg="ICRNL should not be altered by cbreak")
        mode3 = tty.setcbreak(self.fd, termios.TCSANOW)
        self.assertEqual(mode3, mode2)
        tty.setcbreak(self.stream)
        tty.setcbreak(fd=self.fd, when=termios.TCSANOW)