Exemple #1
0
 def test_ctrl_z(self):
     with open('CONIN$', 'rb', buffering=0) as stdin:
         source = '\xC4\x1A\r\n'.encode('utf-16-le')
         expected = '\xC4'.encode('utf-8')
         write_input(stdin, source)
         a, b = stdin.read(1), stdin.readall()
         self.assertEqual(expected[0:1], a)
         self.assertEqual(expected[1:], b)
 def test_ctrl_z(self):
     with open('CONIN$', 'rb', buffering=0) as stdin:
         source = '\xC4\x1A\r\n'.encode('utf-16-le')
         expected = '\xC4'.encode('utf-8')
         write_input(stdin, source)
         a, b = stdin.read(1), stdin.readall()
         self.assertEqual(expected[0:1], a)
         self.assertEqual(expected[1:], b)
 def assertStdinRoundTrip(self, text):
     stdin = open('CONIN$', 'r')
     old_stdin = sys.stdin
     try:
         sys.stdin = stdin
         write_input(stdin.buffer.raw,
                     (text + '\r\n').encode('utf-16-le', 'surrogatepass'))
         actual = input()
     finally:
         sys.stdin = old_stdin
     self.assertEqual(actual, text)
 def test_partial_surrogate_reads(self):
     source = '\U00101fff\U00101001\r\n'.encode('utf-16-le')
     expected = '\U00101fff\U00101001\r\n'.encode('utf-8')
     for read_count in range(1, 16):
         with open('CONIN$', 'rb', buffering=0) as stdin:
             write_input(stdin, source)
             actual = b''
             while not actual.endswith(b'\n'):
                 b = stdin.read(read_count)
                 actual += b
             self.assertEqual(actual, expected, 'stdin.read({})'.format(
                 read_count))
Exemple #5
0
 def assertStdinRoundTrip(self, text):
     stdin = open('CONIN$', 'r')
     old_stdin = sys.stdin
     try:
         sys.stdin = stdin
         write_input(
             stdin.buffer.raw,
             (text + '\r\n').encode('utf-16-le', 'surrogatepass')
         )
         actual = input()
     finally:
         sys.stdin = old_stdin
     self.assertEqual(actual, text)
Exemple #6
0
    def test_partial_reads(self):
        # Test that reading less than 1 full character works when stdin
        # contains multibyte UTF-8 sequences
        source = 'ϼўТλФЙ\r\n'.encode('utf-16-le')
        expected = 'ϼўТλФЙ\r\n'.encode('utf-8')
        for read_count in range(1, 16):
            with open('CONIN$', 'rb', buffering=0) as stdin:
                write_input(stdin, source)

                actual = b''
                while not actual.endswith(b'\n'):
                    b = stdin.read(read_count)
                    actual += b

                self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
Exemple #7
0
    def test_partial_reads(self):
        # Test that reading less than 1 full character works when stdin
        # contains multibyte UTF-8 sequences
        source = 'ϼўТλФЙ\r\n'.encode('utf-16-le')
        expected = 'ϼўТλФЙ\r\n'.encode('utf-8')
        for read_count in range(1, 16):
            with open('CONIN$', 'rb', buffering=0) as stdin:
                write_input(stdin, source)

                actual = b''
                while not actual.endswith(b'\n'):
                    b = stdin.read(read_count)
                    actual += b

                self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
Exemple #8
0
    def test_partial_surrogate_reads(self):
        # Test that reading less than 1 full character works when stdin
        # contains surrogate pairs that cannot be decoded to UTF-8 without
        # reading an extra character.
        source = '\U00101FFF\U00101001\r\n'.encode('utf-16-le')
        expected = '\U00101FFF\U00101001\r\n'.encode('utf-8')
        for read_count in range(1, 16):
            with open('CONIN$', 'rb', buffering=0) as stdin:
                write_input(stdin, source)

                actual = b''
                while not actual.endswith(b'\n'):
                    b = stdin.read(read_count)
                    actual += b

                self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))
Exemple #9
0
    def test_partial_surrogate_reads(self):
        # Test that reading less than 1 full character works when stdin
        # contains surrogate pairs that cannot be decoded to UTF-8 without
        # reading an extra character.
        source = '\U00101FFF\U00101001\r\n'.encode('utf-16-le')
        expected = '\U00101FFF\U00101001\r\n'.encode('utf-8')
        for read_count in range(1, 16):
            with open('CONIN$', 'rb', buffering=0) as stdin:
                write_input(stdin, source)

                actual = b''
                while not actual.endswith(b'\n'):
                    b = stdin.read(read_count)
                    actual += b

                self.assertEqual(actual, expected, 'stdin.read({})'.format(read_count))