Exemplo n.º 1
0
 def __getitem__(self, item):
     """Retrieve character."""
     try:
         color_pos = self.color_index[int(item)]
     except TypeError:  # slice
         return super(ColorStr, self).__getitem__(item)
     return self.__class__(find_char_color(self.value_colors, color_pos), keep_tags=True)
Exemplo n.º 2
0
 def __getitem__(self, item):
     """Retrieve character."""
     try:
         color_pos = self.color_index[int(item)]
     except TypeError:  # slice
         return super(ColorStr, self).__getitem__(item)
     return self.__class__(find_char_color(self.value_colors, color_pos),
                           keep_tags=True)
Exemplo n.º 3
0
def test_find_char_color(in_, pos, expected):
    """Test function.

    :param str in_: Input string to pass to function.
    :param int pos: Character position in non-color string to lookup.
    :param str expected: Expected return value.
    """
    index = build_color_index(in_)
    color_pos = index[pos]
    actual = find_char_color(in_, color_pos)
    assert actual == expected
Exemplo n.º 4
0
def test_find_char_color(in_, pos, expected):
    """Test function.

    :param str in_: Input string to pass to function.
    :param int pos: Character position in non-color string to lookup.
    :param str expected: Expected return value.
    """
    index = build_color_index(in_)
    color_pos = index[pos]
    actual = find_char_color(in_, color_pos)
    assert actual == expected
Exemplo n.º 5
0
 def __iter__(self):
     """Yield one color-coded character at a time."""
     for color_pos in self.color_index:
         yield self.__class__(find_char_color(self.value_colors, color_pos))
Exemplo n.º 6
0
 def __iter__(self):
     """Yield one color-coded character at a time."""
     for color_pos in self.color_index:
         yield self.__class__(find_char_color(self.value_colors, color_pos))