colorama icon indicating copy to clipboard operation
colorama copied to clipboard

Test case failures on aarch64

Open ossdev07 opened this issue 4 years ago • 6 comments

Test Command: I am adding support for aarch64 in Colorama and executing the tests as per the Travis-ci script, below is the command I am using:

python -m unittest discover -p *_test.py

Test Failure: Two test cases are failing while running Colorama on aarch64 platform, Please have a look:

  • testInitDoesntWrapOnEmulatedWindows

  • testInitDoesntWrapOnNonWindows

Test Log: Below are the test logs from my local environment:

======================================================================
FAIL: testInitDoesntWrapOnEmulatedWindows (colorama.tests.initialise_test.InitTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.7.5/lib/python3.7/site-packages/mock/mock.py", line 1330, in patched
    return func(*args, **keywargs)
  File "/home/travis/build/ossdev07/colorama/colorama/tests/initialise_test.py", line 50, in testInitDoesntWrapOnEmulatedWindows
    self.assertNotWrapped()
  File "/home/travis/build/ossdev07/colorama/colorama/tests/initialise_test.py", line 35, in assertNotWrapped
    self.assertIs(sys.stdout, orig_stdout, 'stdout should not be wrapped')
AssertionError: <colorama.ansitowin32.StreamWrapper object at 0xffffb14dfdd0> is not <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'> : stdout should not be wrapped
======================================================================
FAIL: testInitDoesntWrapOnNonWindows (colorama.tests.initialise_test.InitTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ossdev07/colorama/colorama/tests/initialise_test.py", line 55, in testInitDoesntWrapOnNonWindows
    self.assertNotWrapped()
  File "/home/travis/build/ossdev07/colorama/colorama/tests/initialise_test.py", line 35, in assertNotWrapped
    self.assertIs(sys.stdout, orig_stdout, 'stdout should not be wrapped')
AssertionError: <colorama.ansitowin32.StreamWrapper object at 0xffffb14dfed0> is not <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'> : stdout should not be wrapped

@wiggin15 As per the discussion on #209 I have raised this issue, Please share your thoughts on this.

ossdev07 avatar Jan 30 '20 12:01 ossdev07

Ping @wiggin15 Please can you have a look and suggest what could be done.

ossdev07 avatar Mar 11 '20 12:03 ossdev07

@wiggin15 Could you please provide some pointers on this issue, it will be really helpful.

ossdev07 avatar Mar 17 '20 12:03 ossdev07

Hi @ossdev07 . My best guess is that "stdout" on your platform is not a "tty". Can you please specify which terminal and shell you are using?

Long explanation: The tests that fail try to simulate the variable conversion_supported (=on_windows and winapi_test()) to False, which normally causes the variables strip and convert to be False, which then cause the stream to not be wrapped. Since your tests fail because the stream is wrapped, it means that strip or convert are True, even though conversion_supported is False. Looking at the code, this can only happen if the stream (stdout) is not a tty (regular terminal), which can happen if the output is redirected, or the terminal's stdout doesn't identify as a tty correctly.

(It may be possible to add more patching to the tests to make sure the wrapped streams are identified as "not closed" and "tty")

wiggin15 avatar Mar 17 '20 15:03 wiggin15

Thanks, @wiggin15 for the suggestion.

Can you please specify which terminal and shell you are using?

I am trying to run the package on Travis itself and there I am facing this issue, Please have a look at my failed Travis-ci build for aarch64 ( python v3.7 ):

https://travis-ci.com/github/ossdev07/colorama/jobs/299395994

Also as per your comment https://github.com/tartley/colorama/issues/209#issuecomment-465119302 I have tried modifying the above two failed test cases by passing the wrap=False.

You can see the changes here https://github.com/ossdev07/colorama/commit/ec998213db7e3f4533eb1f1fe6df9adaba7f3edd

After this the test is getting passed in Travis-ci as well, https://travis-ci.com/github/ossdev07/colorama/jobs/299397980

It will be really helpful if you could have a look and suggest is this the expected behavior.

ossdev07 avatar Mar 18 '20 12:03 ossdev07

@ossdev07 the commit you added kind of disables the tests. If you pass wrap=False then testing for assertNotWrapped will of course pass. The tests try to see that the "defaults" in different simulated environments are correct. (we have a separate test, testInitWrapOffDoesntWrapOnWindows, that checks that wrap=False won't wrap).

The quickest workaround I can think of, which also disables the tests but only in environments with this problem, is to skip these tests by checking for "sys.stdout.isatty". Something like:

from unittest import TestCase, main, skipUnless
...
    @skipUnless(sys.stdout.isatty(), "sys.stdout is not a tty")

It may even be best to skip the entire class in this case (by putting the decorator on InitTest.setUp). This will make sure that the tests won't fail even when running with tools such as "pytest" / "nosetests".

wiggin15 avatar Mar 18 '20 15:03 wiggin15

@wiggin15 I am successfully able to skip the failing two test cases instead of disabling them for aarch64. Please have a look:

https://travis-ci.com/github/ossdev07/colorama/jobs/299823038

Also, will you be willing to accept the PR for aarch64 support in Travis-ci ( with the above two test cases being skipped ).

Please share your thoughts on this, I will be happy to raise a PR once you agree.

ossdev07 avatar Mar 19 '20 13:03 ossdev07