Closed yurivict closed 2 years ago
Thanks for reporting!
The first two I can reproduce with pytest. I don't use pytest, but the tests should still run clean. You shouldn't see the errors if you use the standard test runner, python -m unittest discover
.
The rest look they are related to test_util.TestHTMLConverter
. It seems it's at least partially caused because it can't find terminal info for xterm-256color. On Linux, the terminfo data gets installed with ncurses, not sure if it's the same with FreeBSD. On my system it's under /usr/share/terminfo, but the FreeBSD man page says /usr/share/misc/terminfo. Can you see if you can find the files and let me know what xterm variations you have available?
It does look like Lookahead doesn't handle a case where the buffer is empty. Not sure how it's getting to that state, but it should handle it regardless.
First two fixed in af10a76e49d60f461f8dffaa99f008422d8eb46b. Still need to look into the rest.
For TestHTMLConverter
, I removed the specific terminal kind in 400233d5cb0b428c915e3b41e37356e065986005. It shouldn't be necessary because styling and number of colors is being forced. We're also not using subprocesses, so the same terminal kind will be used for all tests anyway. For now, we'll just use the default for the environment, but if that becomes an issue we'll need to specify it for all tests.
Still need to look at Lookahead
Refactored Lookahead
in 79d6b2023bca181cb7e678156c592659feec4e22 so it takes slice notation. That should avoid that type of IndexError
, though it will may rise somewhere else under those conditions.
@yurivict would you mind testing main to see if any of the issues still persist?
========================================================================================== FAILURES ==========================================================================================
__________________________________________________________________________ TestHTMLConverter.test_class_not_unique ___________________________________________________________________________
self = <tests.test_util.TestHTMLConverter testMethod=test_class_not_unique>
def test_class_not_unique(self):
"""Repeated classes are dropped within the same span"""
out = self.converter.to_html(self.term.blue_on_aquamarine(self.term.blue('blue_on_aquam')))
> self.assertEqual(
out,
'<pre><span class="enlighten-fg-blue enlighten-bg-7fffd4">blue_on_aquam</span></pre>'
)
E AssertionError: '<pre[19 chars]hten-fg-0000ee enlighten-bg-7fffd4">blue_on_aquam</span></pre>' != '<pre[19 chars]hten-fg-blue enlighten-bg-7fffd4">blue_on_aquam</span></pre>'
E - <pre><span class="enlighten-fg-0000ee enlighten-bg-7fffd4">blue_on_aquam</span></pre>
E ? ^^^^ -
E + <pre><span class="enlighten-fg-blue enlighten-bg-7fffd4">blue_on_aquam</span></pre>
E ? ^^^
tests/test_util.py:261: AssertionError
________________________________________________________________________________ TestHTMLConverter.test_color ________________________________________________________________________________
self = <tests.test_util.TestHTMLConverter testMethod=test_color>
def test_color(self):
"""Verify color conversion"""
# CGA color on RGB color
out = self.converter.to_html(self.term.blue_on_aquamarine('blue_on_aquam'))
> self.assertEqual(
out,
'<pre><span class="enlighten-fg-blue enlighten-bg-7fffd4">blue_on_aquam</span></pre>'
)
E AssertionError: '<pre[19 chars]hten-fg-0000ee enlighten-bg-7fffd4">blue_on_aquam</span></pre>' != '<pre[19 chars]hten-fg-blue enlighten-bg-7fffd4">blue_on_aquam</span></pre>'
E - <pre><span class="enlighten-fg-0000ee enlighten-bg-7fffd4">blue_on_aquam</span></pre>
E ? ^^^^ -
E + <pre><span class="enlighten-fg-blue enlighten-bg-7fffd4">blue_on_aquam</span></pre>
E ? ^^^
tests/test_util.py:131: AssertionError
_____________________________________________________________________________ TestHTMLConverter.test_empty_span ______________________________________________________________________________
self = <tests.test_util.TestHTMLConverter testMethod=test_empty_span>
def test_empty_span(self):
"""Empty Spans are ignored"""
out = self.converter.to_html(self.term.underline('') + 'empty')
> self.assertEqual(out, '<pre>empty</pre>')
E AssertionError: '<pre><span class="enlighten-underline">empty</span></pre>' != '<pre>empty</pre>'
E - <pre><span class="enlighten-underline">empty</span></pre>
E + <pre>empty</pre>
tests/test_util.py:255: AssertionError
________________________________________________________________________________ TestHTMLConverter.test_style ________________________________________________________________________________
self = <tests.test_util.TestHTMLConverter testMethod=test_style>
def test_style(self):
"""Verify style conversion"""
# Italics
out = self.converter.to_html(self.term.italic('italic'))
self.assertEqual(out, '<pre><span class="enlighten-italic">italic</span></pre>')
self.assertEqual(self.converter._styles['enlighten-italic'], {'font-style': 'italic'})
# Bold
out = self.converter.to_html(self.term.bold('bold'))
self.assertEqual(out, '<pre><span class="enlighten-bold">bold</span></pre>')
self.assertEqual(self.converter._styles['enlighten-bold'], {'font-weight': 'bold'})
# Underline
out = self.converter.to_html(self.term.underline('underline'))
self.assertEqual(out, '<pre><span class="enlighten-underline">underline</span></pre>')
self.assertEqual(
self.converter._styles['enlighten-underline'], {'text-decoration': 'underline'}
)
# Blink
out = self.converter.to_html(self.term.blink('blink'))
> self.assertEqual(out, '<pre><span class="enlighten-blink">blink</span></pre>')
E AssertionError: '<pre>blink</pre>' != '<pre><span class="enlighten-blink">blink</span></pre>'
E - <pre>blink</pre>
E + <pre><span class="enlighten-blink">blink</span></pre>
tests/test_util.py:217: AssertionError
____________________________________________________________________________ TestHTMLConverter.test_style_output _____________________________________________________________________________
self = <tests.test_util.TestHTMLConverter testMethod=test_style_output>
def test_style_output(self):
"""Verify style section output"""
out = self.converter.to_html(self.term.red_on_slategrey('red_on_slategrey'))
> self.assertEqual(
out,
'<pre><span class="enlighten-fg-red enlighten-bg-708090">red_on_slategrey</span></pre>'
)
E AssertionError: '<pre[22 chars]n-fg-cd0000 enlighten-bg-708090">red_on_slategrey</span></pre>' != '<pre[22 chars]n-fg-red enlighten-bg-708090">red_on_slategrey</span></pre>'
E - <pre><span class="enlighten-fg-cd0000 enlighten-bg-708090">red_on_slategrey</span></pre>
E ? ^ ----
E + <pre><span class="enlighten-fg-red enlighten-bg-708090">red_on_slategrey</span></pre>
E ? ^^
tests/test_util.py:271: AssertionError
_______________________________________________________________________ TestHTMLConverter.test_style_output_additional _______________________________________________________________________
self = <tests.test_util.TestHTMLConverter testMethod=test_style_output_additional>
def test_style_output_additional(self):
"""Verify style section output with additional sections"""
out = self.converter.to_html(self.term.blink('blink'))
> self.assertEqual(out, '<pre><span class="enlighten-blink">blink</span></pre>')
E AssertionError: '<pre>blink</pre>' != '<pre><span class="enlighten-blink">blink</span></pre>'
E - <pre>blink</pre>
E + <pre><span class="enlighten-blink">blink</span></pre>
tests/test_util.py:293: AssertionError
====================================================================================== warnings summary ======================================================================================
../../../../../../usr/local/lib/python3.9/site-packages/pytest_asyncio/plugin.py:191
/usr/local/lib/python3.9/site-packages/pytest_asyncio/plugin.py:191: DeprecationWarning: The 'asyncio_mode' default value will change to 'strict' in future, please explicitly use 'asyncio_mode=strict' or 'asyncio_mode=auto' in pytest configuration file.
config.issue_config_time_warning(LEGACY_MODE, stacklevel=2)
tests/test_util.py::TestHTMLConverter::test_class_not_unique
tests/test_util.py::TestHTMLConverter::test_color
tests/test_util.py::TestHTMLConverter::test_empty_span
tests/test_util.py::TestHTMLConverter::test_style
tests/test_util.py::TestHTMLConverter::test_style_output
tests/test_util.py::TestHTMLConverter::test_style_output_additional
/usr/local/lib/python3.9/site-packages/pytest_trio/plugin.py:62: TrioDeprecationWarning: trio.MultiError is deprecated since Trio 0.22.0; use BaseExceptionGroup (on Python 3.11 and later) or exceptiongroup.BaseExceptionGroup (earlier versions) instead (https://github.com/python-trio/trio/issues/2211)
if issubclass(call.excinfo.type, trio.MultiError):
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ===================================================================================
SKIPPED [1] tests/test_notebook_manager.py:58: Notebook testing packages not installed
=================================================================== 6 failed, 124 passed, 1 skipped, 7 warnings in 20.42s ====================================================================
It seems this platform doesn't support some of the formatting escape codes. Looking over the tests, the TERM
environment variable is set to xterm-256color
before any tests are run. I can get similar, though not exact, failures if I set this to a more limited xterm spec.
Are you seeing anything like:
/lib/python3.9/site-packages/blessed/terminal.py:186: UserWarning: Failed to setupterm(kind='xterm-256color'): setupterm: could not find terminal
I spun up a VM and got the same output as you. It looks like this is related to FreeBSD's use of termcap vs terminfo and some missing capabilities in the termcap file. I can't tell if it's intentional or not. In any case, maybe these tests should just get skipped on FreeBSD. They only affect the Jupyter implementation which is only available if ipython is available.
Longer term, I think Blessed (One of enlighten's dependencies) probably needs to be modified to optionally use an alternative source for terminfo. It uses curses, but we talked about using jinxed like we do on Windows. The main problem is it's less flexible, but for cases like the Jupyter manager, it's actually only using those values for translation, so jinxed would actually be better.
Any thoughts?
I looked at it again and realized FreeBSD was using 256 color syntax for CGA colors rather than the simplified format that xterm uses. This meant the colors were not getting referenced to their names. So I added some logic to always attempt to get a name for colors regardless of how they are specified, only falling back to RGB if it can't. Previously only CGA colors referenced names.
This resolved half of the remaining failures. One was a bug that didn't handle sgr0 when it was a single termcap. And the other two were because blink is not supported in FreeBSD's termcap file, so I moved all the blink tests together and put a guard to skip if blink isn't defined.
It looks like everything is passing now. @yurivict can you confirm main is passing for you?
Fixes are in 1.11.1. Thanks for reporting and please let me you if you have any other issues.
All tests pass now. Thank you for fixing them!
Describe the bug
To Reproduce run pytest
Environment (please complete the following information):