| 1 |
# coding: utf-8 |
| 2 |
"""Test suite for our color utilities. |
| 3 |
|
| 4 |
Authors |
| 5 |
------- |
| 6 |
|
| 7 |
* Min RK |
| 8 |
""" |
| 9 |
# ----------------------------------------------------------------------------- |
| 10 |
# Copyright (C) 2011 The IPython Development Team |
| 11 |
# |
| 12 |
# Distributed under the terms of the BSD License. The full license is in |
| 13 |
# the file COPYING.txt, distributed as part of this software. |
| 14 |
# ----------------------------------------------------------------------------- |
| 15 |
|
| 16 |
# ----------------------------------------------------------------------------- |
| 17 |
# Imports |
| 18 |
# ----------------------------------------------------------------------------- |
| 19 |
|
| 20 |
# our own |
| 21 |
import sys |
| 22 |
from IPython.utils.PyColorize import Parser |
| 23 |
import io |
| 24 |
import pytest |
| 25 |
|
| 26 |
|
| 27 |
@pytest.fixture(scope="module", params=("linux", "nocolor", "lightbg", "neutral")) |
| 28 |
def theme_name(request): |
| 29 |
yield request.param |
| 30 |
|
| 31 |
|
| 32 |
# ----------------------------------------------------------------------------- |
| 33 |
# Test functions |
| 34 |
# ----------------------------------------------------------------------------- |
| 35 |
|
| 36 |
sample = """ |
| 37 |
def function(arg, *args, kwarg=True, **kwargs): |
| 38 |
''' |
| 39 |
this is docs |
| 40 |
''' |
| 41 |
pass is True |
| 42 |
False == None |
| 43 |
|
| 44 |
with io.open(rf'unicode {1}', encoding='utf-8'): |
| 45 |
raise ValueError("escape \r sequence") |
| 46 |
|
| 47 |
print("wěird ünicoðe") |
| 48 |
|
| 49 |
class Bar(Super): |
| 50 |
|
| 51 |
def __init__(self): |
| 52 |
super(Bar, self).__init__(1**2, 3^4, 5 or 6) |
| 53 |
""" |
| 54 |
|
| 55 |
|
| 56 |
def test_parse_sample(theme_name): |
| 57 |
"""and test writing to a buffer""" |
| 58 |
buf = io.StringIO() |
| 59 |
p = Parser(theme_name=theme_name) |
| 60 |
p.format(sample, buf) |
| 61 |
buf.seek(0) |
| 62 |
f1 = buf.read() |
| 63 |
|
| 64 |
assert "ERROR" not in f1 |
| 65 |
|
| 66 |
|
| 67 |
def test_parse_error(theme_name): |
| 68 |
p = Parser(theme_name=theme_name) |
| 69 |
f1 = p.format(r"\ " if sys.version_info >= (3, 12) else ")", "str") |
| 70 |
if theme_name != "nocolor": |
| 71 |
assert "ERROR" in f1 |