blessings icon indicating copy to clipboard operation
blessings copied to clipboard

test suite fails when run without a tty

Open danc86 opened this issue 12 years ago • 8 comments

If the tests are run with stdout redirected to something that isn't a tty (for example to a log file) there are some failures:

$ python setup.py test | cat
[...]

======================================================================
ERROR: blessings.tests.test_capability
Check that a capability lookup works.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/dcallagh/work/blessings/blessings/tests.py", line 47, in test_capability
    sc = unicode_cap('sc')
  File "/home/dcallagh/work/blessings/blessings/tests.py", line 31, in unicode_cap
    return tigetstr(cap).decode('utf-8')
error: must call (at least) setupterm() first

======================================================================
ERROR: blessings.tests.test_parametrization
Test parametrizing a capability.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/dcallagh/work/blessings/blessings/tests.py", line 67, in test_parametrization
    eq_(TestTerminal().cup(3, 4), unicode_parm('cup', 3, 4))
TypeError: __call__() takes exactly 2 arguments (3 given)

======================================================================
FAIL: blessings.tests.test_mnemonic_colors
Make sure color shortcuts work.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/dcallagh/work/blessings/blessings/tests.py", line 147, in test_mnemonic_colors
    eq_(t.white, color(7))
  File "/usr/lib/python2.7/site-packages/nose/tools.py", line 31, in eq_
    assert a == b, msg or "%r != %r" % (a, b)
AssertionError: u'' != u'\x1b[37m'

======================================================================
FAIL: blessings.tests.test_init_descriptor_always_initted
We should be able to get a height and width even on no-tty Terminals.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/dcallagh/work/blessings/blessings/tests.py", line 250, in test_init_descriptor_always_initted
    eq_(type(t.height), int)
  File "/usr/lib/python2.7/site-packages/nose/tools.py", line 31, in eq_
    assert a == b, msg or "%r != %r" % (a, b)
AssertionError: <type 'NoneType'> != <type 'int'>

----------------------------------------------------------------------
Ran 21 tests in 0.011s

FAILED (failures=2, errors=2, skipped=1)

danc86 avatar Nov 30 '12 04:11 danc86

I'll note that I've spent the better part of an afternoon trying to mock a real terminal—using subprocess and shell scripts and script and anything else I could muster—to the point where isatty returns true, all to no avail. So the only way to get the tests to pass like this would be to mock out Terminal.is_a_tty or something that leads to it.

erikrose avatar Nov 30 '12 06:11 erikrose

At least the 2nd crash is probably fixed by #31.

erikrose avatar Aug 30 '13 04:08 erikrose

I think you could get "isatty" to succeed if you used a pseudo-terminal. Perhaps i'll take a knock at this on the weekend

jquast avatar Aug 30 '13 13:08 jquast

I did knock it out, the as_subproces decorator proposed in the fix-tests branch ensures that stdout is always a tty, even when it isn't. these test cases now pass in that branch when piped to |cat, |tee, etc.

jquast avatar Sep 25 '13 03:09 jquast

closed by pull request #48

jquast avatar Nov 05 '13 16:11 jquast

(Going through old issues here, looking at what's going on with them) This is still broken, it appears. Presumably because #49 never landed.

fwenzel avatar Apr 29 '14 22:04 fwenzel

resolved by branch 'blessed-integration'

jquast avatar Apr 08 '15 00:04 jquast

That patched tests.py uses nose which should not be used with python 3.x https://nose.readthedocs.io/en/latest/

kloczek avatar Dec 30 '21 07:12 kloczek