def test_Dict(self): # Standard sink = six.moves.StringIO() CommonEnvironment.Describe( { "a": "one", "bee": 2, "c": True, "d": 1.0, }, sink) self.assertEqual( sink.getvalue(), textwrap.dedent("""\ a : one bee : 2 <class 'int'> c : True <class 'bool'> d : 1.0 <class 'float'> """)) # Nested sink = six.moves.StringIO() CommonEnvironment.Describe( { "nested": { "foo": "bar", "baz": "biz", "one": "more", }, "a": "one", "bee": 2, }, sink) self.assertEqual( sink.getvalue(), textwrap.dedent("""\ nested : foo : bar baz : biz one : more a : one bee : 2 <class 'int'> """)) # Empty sink = six.moves.StringIO() CommonEnvironment.Describe({}, sink) self.assertEqual( sink.getvalue(), textwrap.dedent("""\ -- empty dict -- """))
def test_List(self): # Standard sink = six.moves.StringIO() CommonEnvironment.Describe([ "one", 2, 3.0, ], sink) self.assertEqual( sink.getvalue(), textwrap.dedent("""\ 0) one 1) 2 <class 'int'> 2) 3.0 <class 'float'> """)) # Nested sink = six.moves.StringIO() CommonEnvironment.Describe([ "one", [ "foo", "bar", ], 2, 3.0, ], sink) self.assertEqual( sink.getvalue(), textwrap.dedent("""\ 0) one 1) 0) foo 1) bar 2) 2 <class 'int'> 3) 3.0 <class 'float'> """)) # Empty sink = six.moves.StringIO() CommonEnvironment.Describe([], sink) self.assertEqual( sink.getvalue(), textwrap.dedent("""\ -- empty list -- """))
def Execute(invoke_reason, context, status_stream, verbose_stream, verbose): # <unused argument> pylint: disable = W0613 assert len( context["output_filenames"]) == 1, context["output_filenames"] output_filename = context["output_filenames"][0] status_stream.write("Writing '{}'...".format(output_filename)) with status_stream.DoneManager(): sink = six.StringIO() CommonEnvironment.Describe( context, output_stream=sink, ) sink = sink.getvalue() with open(output_filename, "w") as f: f.write( textwrap.dedent( """\ # ---------------------------------------------------------------------- # | # | Debug Output - Execute # | # ---------------------------------------------------------------------- invoke_reason: {invoke_reason} context: {context} """, ).format( invoke_reason=invoke_reason, context=StringHelpers.LeftJustify(sink.strip(), 4), ), )