Example #1
0
 def test_unknown(self):
     """
     None or messages with no identifiable information are rendered as
     ``<unnamed>``.
     """
     self.assertThat(message_name(colors, no_formatting, None),
                     ExactlyEquals(u'<unnamed>'))
     message = WrittenMessage.from_dict({u'timestamp': 0})
     self.assertThat(message_name(colors, no_formatting, message),
                     ExactlyEquals(u'<unnamed>'))
Example #2
0
 def test_bytes(self):
     """
     Decode ``bytes`` values as the specified encoding.
     """
     format_value = _default_value_formatter(human_readable=False,
                                             field_limit=0,
                                             encoding='utf-8')
     self.assertThat(format_value(b'foo'), ExactlyEquals(u'foo'))
     self.assertThat(format_value(b'\xe2\x98\x83'),
                     ExactlyEquals(u'\N{SNOWMAN}'))
Example #3
0
 def test_text(self):
     """
     Text leaves are their own name.
     """
     get_name = get_name_factory(None)
     self.assertThat(
         get_name(u'hello'),
         ExactlyEquals(u'hello'))
     self.assertThat(
         get_name(u'hello\x1b'),
         ExactlyEquals(u'hello\u241b'))
Example #4
0
 def test_not_eliot_timestamp_field(self):
     """
     Do not format user fields named ``timestamp``.
     """
     format_value = _default_value_formatter(human_readable=True,
                                             field_limit=0)
     now = 1433631432
     self.assertThat(format_value(now, u'timestamp'),
                     ExactlyEquals(text_type(now)))
     self.assertThat(format_value(text_type(now), u'timestamp'),
                     ExactlyEquals(text_type(now)))
Example #5
0
    def test_anything(self):
        """
        Convert values to Unicode via `repr`.
        """
        class _Foo(object):
            def __repr__(self):
                return 'hello'

        self.assertThat(
            format.anything('utf-8')(_Foo()), ExactlyEquals(u'hello'))
        self.assertThat(format.anything('utf-8')(42), ExactlyEquals(u'42'))
Example #6
0
 def test_timestamp_field(self):
     """
     Format Eliot ``timestamp`` fields as human-readable if the feature was
     requested.
     """
     format_value = _default_value_formatter(human_readable=True,
                                             field_limit=0)
     # datetime(2015, 6, 6, 22, 57, 12)
     now = 1433631432
     self.assertThat(format_value(now, eliot_ns(u'timestamp')),
                     ExactlyEquals(u'2015-06-06 22:57:12Z'))
     self.assertThat(format_value(str(now), eliot_ns(u'timestamp')),
                     ExactlyEquals(u'2015-06-06 22:57:12Z'))
Example #7
0
    def test_tuple_other(self):
        """
        Tuples can be a key and string, number, etc. rendered inline.
        """
        node = (u'a\nb\x1bc', u'hello')
        self.assertThat(
            self.format_node(node, colors=colors),
            ExactlyEquals(u'{}: {}'.format(colors.prop_key(u'a\u240ab\u241bc'),
                                           colors.prop_value(u'hello'))))

        node = (u'a\nb\x1bc', 42)
        self.assertThat(
            self.format_node(node, colors=colors),
            ExactlyEquals(u'{}: {}'.format(colors.prop_key(u'a\u240ab\u241bc'),
                                           colors.prop_value(u'42'))))
Example #8
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')))
Example #9
0
 def test_replace(self):
     """
     Replace decoding errors with the Unicode replacement character.
     """
     self.assertThat(
         format.binary('utf-32')(u'\N{SNOWMAN}'.encode('utf-8')),
         ExactlyEquals(u'\ufffd'))
Example #10
0
 def test_over(self):
     """
     Truncate values whose length is above the limit.
     """
     self.assertThat(
         format.truncate_value(10, u'abcdefghijklmnopqrstuvwxyz'),
         ExactlyEquals(u'abcdefghij\u2026'))
Example #11
0
 def test_multiple_lines(self):
     """
     Truncate values that have more than a single line of text by only
     showing the first line.
     """
     self.assertThat(format.truncate_value(10, u'abc\ndef'),
                     ExactlyEquals(u'abc\u2026'))
Example #12
0
 def test_under(self):
     """
     No truncation occurs if the length of the value is below the limit.
     """
     self.assertThat(
         format.truncate_value(10, u'abcdefghijklmnopqrstuvwxyz'[:5]),
         ExactlyEquals(u'abcde'))
Example #13
0
 def test_task(self):
     """
     `Task`'s UUID is rendered.
     """
     node = next(tasks_from_iterable([action_task]))
     self.assertThat(self.format_node(node),
                     ExactlyEquals(node.root().task_uuid))
Example #14
0
 def test_encoding(self):
     """
     Binary values are decoded with the given encoding.
     """
     self.assertThat(
         format.binary('utf-8')(u'\N{SNOWMAN}'.encode('utf-8')),
         ExactlyEquals(u'\u2603'))
Example #15
0
 def test_exact(self):
     """
     No truncation occurs if the length of the value is exactly at the
     limit.
     """
     self.assertThat(
         format.truncate_value(10, u'abcdefghijklmnopqrstuvwxyz'[:10]),
         ExactlyEquals(u'abcdefghij'))
Example #16
0
 def test_unicode(self):
     """
     Pass ``unicode`` values straight through.
     """
     format_value = _default_value_formatter(human_readable=False,
                                             field_limit=0)
     self.assertThat(format_value(u'\N{SNOWMAN}'),
                     ExactlyEquals(u'\N{SNOWMAN}'))
Example #17
0
 def test_tuple_dict(self):
     """
     Tuples whose value is a dict use the name in the first position of the
     tuple.
     """
     get_name = get_name_factory(None)
     self.assertThat(
         get_name((u'key\x1bname', {})),
         ExactlyEquals(u'key\u241bname'))
Example #18
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'))))
Example #19
0
 def test_unicode_control_characters(self):
     """
     Translate control characters to their Unicode "control picture"
     equivalent, instead of destroying a terminal.
     """
     format_value = _default_value_formatter(human_readable=False,
                                             field_limit=0)
     self.assertThat(format_value(u'hello\001world'),
                     ExactlyEquals(u'hello\u2401world'))
Example #20
0
 def test_mapping(self):
     """
     Values for known field names are passed through their processor.
     """
     fields = {
         u'a': format.binary('utf-8'),
     }
     self.assertThat(
         format.fields(fields)(u'\N{SNOWMAN}'.encode('utf-8'), u'a'),
         ExactlyEquals(u'\N{SNOWMAN}'))
Example #21
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')))
Example #22
0
 def test_tuple_list(self):
     """
     Tuples can be a key and list, in which case the value is not rendered
     here.
     """
     node = (u'a\nb\x1bc', [u'x\n', u'y\x1b', u'z'])
     self.assertThat(
         self.format_node(node, colors=colors),
         ExactlyEquals(u'{}: '.format(
             colors.prop(u'a\u240ab\u241bc'))))
Example #23
0
 def test_tuple_dict(self):
     """
     Tuples can be a key and dict, in which case the value is not rendered
     here.
     """
     node = (u'a\nb\x1bc', {u'x\n': u'y\x1b', u'z': u'zz'})
     self.assertThat(
         self.format_node(node, colors=colors),
         ExactlyEquals(u'{}: {}'.format(colors.prop_key(u'a\u240ab\u241bc'),
                                        colors.prop_value(u''))))
Example #24
0
 def test_local(self):
     """
     Timestamps can be converted to local time.
     """
     timestamp = 1433631432.0
     utc = format.timestamp(utc_timestamps=True)(timestamp)
     local = format.timestamp(utc_timestamps=False)(timestamp +
                                                    time.timezone)
     # Strip the "Z" off the end.
     self.assertThat(utc[:-1], ExactlyEquals(local))
Example #25
0
 def test_timestamp_field_not_human(self):
     """
     Do not format ``timestamp`` fields as human-readable if the feature was
     not requested.
     """
     format_value = _default_value_formatter(human_readable=False,
                                             field_limit=0)
     # datetime(2015, 6, 6, 22, 57, 12)
     now = 1433631432
     self.assertThat(format_value(now, u'timestamp'),
                     ExactlyEquals(text_type(now)))
Example #26
0
 def test_field_limit(self):
     """
     Truncate task values that are longer than the field_limit if specified.
     """
     self.assertThat(
         self.render_tasks([message_task], field_limit=5),
         ExactlyEquals(u'cdeb220d-7605-4d5f-8341-1a170222e308\n'
                       u'\u2514\u2500\u2500 twisted:log/1 '
                       u'14253\u2026\n'
                       u'    \u251c\u2500\u2500 error: False\n'
                       u'    \u2514\u2500\u2500 message: Main \u2026\n\n'))
Example #27
0
 def test_dict_data(self):
     """
     Task values that are ``dict``s are rendered as tree elements.
     """
     self.assertThat(
         self.render_tasks([dict_action_task]),
         ExactlyEquals(u'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4\n'
                       u'\u2514\u2500\u2500 app:action/1 \u21d2 started '
                       u'1425356800\n'
                       u'    \u2514\u2500\u2500 some_data: \n'
                       u'        \u2514\u2500\u2500 a: 42\n\n'))
Example #28
0
    def test_anything(self):
        """
        Pass unknown values to ``repr``.
        """
        class _Thing(object):
            def __repr__(self):
                return 'Hello'

        format_value = _default_value_formatter(human_readable=False,
                                                field_limit=0)
        self.assertThat(format_value(_Thing()), ExactlyEquals(u'Hello'))
Example #29
0
 def test_ignored_keys(self):
     """
     Task keys can be ignored.
     """
     self.assertThat(
         self.render_tasks([action_task], ignored_fields={u'action_type'}),
         ExactlyEquals(
             u'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4\n'
             u'\u2514\u2500\u2500 app:action/1 \u21d2 started '
             u'1425356800\n'
             u'    \u2514\u2500\u2500 action_status: started\n\n'))
Example #30
0
 def test_nested(self):
     """
     Render nested tasks in a way that visually represents that nesting.
     """
     self.assertThat(
         self.render_tasks([action_task, nested_action_task]),
         ExactlyEquals(
             u'f3a32bb3-ea6b-457c-aa99-08a3d0491ab4\n'
             u'\u2514\u2500\u2500 app:action/1 \u21d2 started '
             u'1425356800\n'
             u'    \u2514\u2500\u2500 app:action:nest/1/1 \u21d2 started '
             u'1425356900\n\n'))