Skip to content

CYGWIN doesn't support text mode in POSIX functions like MinGW. #149946

@carlo-bramini

Description

@carlo-bramini

Bug report

Bug description:

This is one of the errors printed by make test on CYGWIN:

FAIL: test_textmode (test.test_tempfile.TestMkstempInner.test_textmode)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/carlo/packages/python/cpython/Lib/test/test_tempfile.py", line 522, in test_textmode
    self.assertEqual(os.read(f.fd, 20), b"blat")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: b'blat\x1aextra\n' != b'blat'

For explaining this issue, some information must be listed about the CTRL-Z (0x1A):

On CYGWIN:

  • Opening with open() in binary mode, it handles it as a clean flow of data without translations.
  • Opening with open() in text mode, it translates all 0xA to 0xD 0xA and the read() function ignores the CTRL-Z character as EOF.
  • Opening with fopen() in text mode, it also accepts the CTRL-Z as the EOF condition and this stops receiving data from fread().

On native WIN32:

  • both open() and fopen() work in the same way if they open the file in text mode and CTRL-Z is treated as End-Of-File at both high and low levels, so read() and fread() give you the same results.

So, that's why this test is failing here.

In short, this kind of test cannot be executed on CYGWIN because read() never blocks on CTRL-Z by design.
I would like to suggest to avoid it, if it happens.
The patch itself is simple, I think that it is just need to write this before test_textmode:

@unittest.skipUnless(sys.platform != "cygwin" and has_textmode, "text mode not available")

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-unsupportedtestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions