Format: text/x-python
⬇ Download File (1.7 KB)
   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 style(request):
  29      yield request.param
  30  
  31  #-----------------------------------------------------------------------------
  32  # Test functions
  33  #-----------------------------------------------------------------------------
  34  
  35  sample = """
  36  def function(arg, *args, kwarg=True, **kwargs):
  37      '''
  38      this is docs
  39      '''
  40      pass is True
  41      False == None
  42  
  43      with io.open(ru'unicode', encoding='utf-8'):
  44          raise ValueError("escape \r sequence")
  45  
  46      print("wěird ünicoðe")
  47  
  48  class Bar(Super):
  49  
  50      def __init__(self):
  51          super(Bar, self).__init__(1**2, 3^4, 5 or 6)
  52  """
  53  
  54  
  55  def test_parse_sample(style):
  56      """and test writing to a buffer"""
  57      buf = io.StringIO()
  58      p = Parser(style=style)
  59      p.format(sample, buf)
  60      buf.seek(0)
  61      f1 = buf.read()
  62  
  63      assert "ERROR" not in f1
  64  
  65  
  66  def test_parse_error(style):
  67      p = Parser(style=style)
  68      f1 = p.format(r"\ " if sys.version_info >= (3, 12) else ")", "str")
  69      if style != "NoColor":
  70          assert "ERROR" in f1
  71