def test_withSavedTerminalSettings(self):
        CFLAG = 2
        LFLAG = 3
        leader, follower = makeTerminal(self)
        def attributesEqual(a, b):
            # lflags seem to change randomly, and I'm not sure why, so let's
            # exclude them from the test (we never change them in mangle()
            # anyway).
            a[LFLAG] = 0
            b[LFLAG] = 0
            self.assertEqual(a, b)

        attrs = termios.tcgetattr(follower)
        chattrs = attrs[:]
        # Change one flag, just to change it.
        chattrs[CFLAG] ^= termios.INLCR
        def mangle():
            os.write(follower, b"HELLO")
            termios.tcsetattr(follower, termios.TCSANOW, chattrs)
            mangle.attrs = termios.tcgetattr(follower)
            mangle.run = True
        mangle.run = False
        withSavedTerminalSettings(follower, mangle)
        self.assertEqual(mangle.run, True)
        # Sanity check: did the attributes change in the first place?
        attributesEqual(mangle.attrs, chattrs)
        newattrs = termios.tcgetattr(follower)
        attributesEqual(newattrs, attrs)
        self.assertEqual(os.read(leader, 1024), b"HELLO" + CLEAR_SCREEN)
L{withSavedTerminalSettings} saves and then restores the settings for
dataset/ETHPy150Open twisted/imaginary/imaginary/test/test_runner.py/WindowSizing.test_withSavedTerminalSettings