Exemple #1
0
 def test_tuple_unicode(self):
     """
     Tuples whose value is unicode are a key/value pair.
     """
     C = COLORS(colored)
     get_name = get_name_factory(C)
     self.assertThat(
         get_name((u'key\x1bname', u'hello')),
         ExactlyEquals(u'{}: hello'.format(C.prop(u'key\u241bname'))))
Exemple #2
0
 def test_tuple_root(self):
     """
     Tuples that are neither unicode nor a dict are assumed to be a root
     node.
     """
     C = COLORS(colored)
     get_name = get_name_factory(C)
     self.assertThat(
         get_name((u'key\x1bname', None)),
         ExactlyEquals(C.root(u'key\u241bname')))
Exemple #3
0
 def test_node_failure(self):
     """
     Task nodes indicating failure are colored.
     """
     tree = Tree()
     tree.merge_tasks([action_task])
     node = tree.nodes()[0][1].copy()
     node.success = False
     C = COLORS(colored)
     get_name = get_name_factory(C)
     self.assertThat(
         get_name(node),
         ExactlyEquals(C.failure(node.name)))
Exemple #4
0
 def test_colorize(self):
     """
     Passing ``colorize=True`` will colorize the output.
     """
     fd = BytesIO()
     tree = Tree()
     tree.merge_tasks([action_task, action_task_end])
     render_task_nodes(
         write=fd.write,
         nodes=tree.nodes(),
         field_limit=0,
         colorize=True)
     C = COLORS(colored)
     self.assertThat(
         fd.getvalue(),
         ExactlyEquals(
             u'\n'.join([
                 C.root(u'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4'),
                 u'\u2514\u2500\u2500 {}'.format(
                     C.success(u'app:action@1/started')),
                 u'    \u251c\u2500\u2500 {}: {}'.format(
                     C.prop(u'timestamp'), u'1425356800'),
                 u'    \u2514\u2500\u2500 {}'.format(
                     C.success(u'app:action@2/succeeded')),
                 u'        \u2514\u2500\u2500 {}: {}'.format(
                     C.prop('timestamp'), u'1425356802'),
                 u'\n',
             ]).encode('utf-8')))
Exemple #5
0
 def test_node(self):
     """
     Task nodes use their own name.
     """
     tree = Tree()
     tree.merge_tasks([action_task])
     node = tree.nodes()[0][1]
     C = COLORS(colored)
     get_name = get_name_factory(C)
     self.assertThat(
         get_name(node),
         ExactlyEquals(node.name))
Exemple #6
0
def render_task_nodes_unicode(write,
                              nodes,
                              field_limit,
                              ignored_task_keys=None,
                              human_readable=False,
                              colorize=False):
    """
    Render a tree of task nodes as an ``ASCII`` tree.

    :type write: ``callable`` taking a single ``text_type`` argument
    :param write: Callable to write the output.

    :type nodes: ``list`` of ``(text_type, _TaskNode)``.
    :param nodes: List of pairs of task UUID and task nodes, as obtained
        from ``Tree.nodes``.

    :type field_limit: ``int``
    :param field_limit: Length at which to begin truncating, ``0`` means no
        truncation.

    :type ignored_task_keys: ``set`` of ``text_type``
    :param ignored_task_keys: Set of task key names to ignore.

    :type human_readable: ``bool``
    :param human_readable: Should this be rendered as human-readable?

    :type colorize: ``bool``
    :param colorize: Should the output be colorized?
    """
    if ignored_task_keys is None:
        ignored_task_keys = DEFAULT_IGNORED_KEYS
    colors = COLORS(colored if colorize else _no_color)
    format_value = _default_value_formatter(human_readable=human_readable,
                                            field_limit=field_limit)
    get_children = get_children_factory(ignored_task_keys, format_value)
    get_name = get_name_factory(colors)
    for root in nodes:
        write(format_tree(root, get_name, get_children))
        write(u'\n')
Exemple #7
0
    def test_node_failure(self):
        """
        Task nodes indicating failure are colored.
        """
        tree = Tree()
        tree.merge_tasks([action_task])
        node = tree.nodes()[0][1].copy()
        node.success = False
        C = COLORS(colored)
        get_name = get_name_factory(C)
        self.assertThat(
            get_name(node),
            ExactlyEquals(C.failure(node.name)))


colors = COLORS(colored)
no_colors = COLORS(_no_color)


def no_formatting(value, field_name=None):
    return text_type(value)


class MessageNameTests(TestCase):
    """
    Tests for `eliottree.render.message_name`.
    """
    def test_action_type(self):
        """
        Action types include their type name.
        """