Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestManager.test_autorefresh fails on macOS #44

Closed
veprbl opened this issue Jul 21, 2021 · 3 comments
Closed

TestManager.test_autorefresh fails on macOS #44

veprbl opened this issue Jul 21, 2021 · 3 comments
Labels

Comments

@veprbl
Copy link

veprbl commented Jul 21, 2021

Describe the bug
A following test fails on macOS, but not on linux (with the same dependency versions)

_________________________ TestManager.test_autorefresh _________________________

self = <tests.test_manager.TestManager testMethod=test_autorefresh>

    def test_autorefresh(self):
        """
        Ensure auto-refreshed counters are updated when others are
        """
    
        manager = enlighten.Manager(stream=self.tty.stdout)
        counter1 = manager.counter(count=1, total=0, counter_format=u'counter1', autorefresh=True)
        counter2 = manager.counter(count=1, total=0, counter_format=u'counter2')
        self.tty.clear()
    
        # Counter 1 in auto-refresh list
        self.assertIn(counter1, manager.autorefresh)
    
        # If auto-refreshed counter hasn't been refreshed recently refresh
        counter1.last_update = 0
        counter2.refresh()
        self.tty.stdout.write(u'X\n')
        output = self.tty.stdread.readline()
>       self.assertRegex(output, 'counter2.+counter1')
E       AssertionError: Regex didn't match: 'counter2.+counter1' not found in '\x1b[25;1H\n'

tests/test_manager.py:364: AssertionError

To Reproduce

  1. install enlighten
  2. run tests
git clone https://github.com/Rockhopper-Technologies/enlighten.git
cd enlighten
pytest

Environment (please complete the following information):

@veprbl veprbl added the bug label Jul 21, 2021
@avylove
Copy link
Contributor

avylove commented Jul 21, 2021

It looks like termios.tcflush(stream, termios.TCIFLUSH) is not behaving as expected on MacOS.

You can see here where self.tty.clear() is called after the counters are setup. This removes anything written to stdout on the mock TTY.

manager = enlighten.Manager(stream=self.tty.stdout)
counter1 = manager.counter(count=1, total=0, counter_format=u'counter1', autorefresh=True)
counter2 = manager.counter(count=1, total=0, counter_format=u'counter2')
self.tty.clear()

In tests.MockTTY.clear(), termios.tcflush() gets called

enlighten/tests/__init__.py

Lines 138 to 139 in d296133

def clear(self):
termios.tcflush(self.stdread, termios.TCIFLUSH)

According to the man page this should behave the same in MacOS, but, there are a lot of undocumented "features" on Macs.

I don't have a Mac to test with, so I'll need your help on this. Can you try changing it from TCIFLUSH to TCIOFLUSH and let me know if that works. It does more than necessary, but might provide the functionality we need.

If that doesn't work, I'm tempted just to skip this test on Macs. The alternative is to read the number of lines produced by the setup. This is done in other places in the code, but I'm trying to get away from that because it's harder to maintain.

@veprbl
Copy link
Author

veprbl commented Jul 22, 2021

I don't have a Mac to test with, so I'll need your help on this. Can you try changing it from TCIFLUSH to TCIOFLUSH and let me know if that works. It does more than necessary, but might provide the functionality we need.

That worked like a charm. Let me know if you need to try something else.

@avylove
Copy link
Contributor

avylove commented Jul 22, 2021

Fix is now in the master branch. So your original workflow should succeed now. Thanks for your help!

@veprbl veprbl closed this as completed Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants