当前位置: 首页>>代码示例>>Python>>正文


Python _output.OutputProducer类代码示例

本文整理汇总了Python中azure.cli.core._output.OutputProducer的典型用法代码示例。如果您正苦于以下问题:Python OutputProducer类的具体用法?Python OutputProducer怎么用?Python OutputProducer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OutputProducer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_out_json_byte_empty

    def test_out_json_byte_empty(self):
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'contents': b''}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """{
  "active": true,
  "contents": ""
}
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:9,代码来源:test_output.py

示例2: test_out_list_valid_none_val

    def test_out_list_valid_none_val(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem({'active': None, 'id': '0b1f6472'}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""Active : None
Id     : 0b1f6472


"""))
开发者ID:Azure,项目名称:azure-cli,代码行数:9,代码来源:test_output.py

示例3: test_out_list_valid_caps

    def test_out_list_valid_caps(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'TESTStuff': 'blah'}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""Test Stuff : blah
Active     : True


"""))
开发者ID:Azure,项目名称:azure-cli,代码行数:9,代码来源:test_output.py

示例4: test_out_table_list_of_lists

    def test_out_table_list_of_lists(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        obj = [['a', 'b'], ['c', 'd']]
        output_producer.out(CommandResultItem(obj))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """Column1    Column2
---------  ---------
a          b
c          d
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:10,代码来源:test_output.py

示例5: test_out_json_from_ordered_dict

    def test_out_json_from_ordered_dict(self):
        # The JSON output when the input is OrderedDict should be serialized to JSON
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(CommandResultItem(OrderedDict({'active': True, 'id': '0b1f6472'})))
        self.assertEqual(normalize_newlines(self.io.getvalue()), normalize_newlines(
            """{
  "active": true,
  "id": "0b1f6472"
}
"""))
开发者ID:derekbekoe,项目名称:azure-cli,代码行数:10,代码来源:test_output.py

示例6: test_out_table_no_query_no_transformer_order

    def test_out_table_no_query_no_transformer_order(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        obj = {'name': 'qwerty', 'val': '0b1f6472qwerty', 'active': True, 'sub': '0b1f6472'}
        result_item = CommandResultItem(obj, table_transformer=None, is_query_active=False)
        output_producer.out(result_item)
        # Should be alphabetical order as no table transformer and query is not active.
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """  Active  Name    Sub       Val
--------  ------  --------  --------------
       1  qwerty  0b1f6472  0b1f6472qwerty
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:11,代码来源:test_output.py

示例7: test_out_table

    def test_out_table(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        obj = OrderedDict()
        obj['active'] = True
        obj['val'] = '0b1f6472'
        output_producer.out(CommandResultItem(obj))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """  Active  Val
--------  --------
       1  0b1f6472
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:11,代码来源:test_output.py

示例8: test_out_table_no_query_yes_jmespath_table_transformer

    def test_out_table_no_query_yes_jmespath_table_transformer(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        obj = {'name': 'qwerty', 'val': '0b1f6472qwerty', 'active': True, 'sub': '0b1f6472'}

        result_item = CommandResultItem(obj, table_transformer='{Name:name, Val:val, Active:active}', is_query_active=False)
        output_producer.out(result_item)
        # Should be table transformer order
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """Name    Val             Active
------  --------------  --------
qwerty  0b1f6472qwerty  True
"""))
开发者ID:akshaysngupta,项目名称:azure-cli,代码行数:12,代码来源:test_output.py

示例9: test_out_json_valid

    def test_out_json_valid(self):
        """
        The JSON output when the input is a dict should be the dict serialized to JSON
        """
        output_producer = OutputProducer(formatter=format_json, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'id': '0b1f6472'}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """{
  "active": true,
  "id": "0b1f6472"
}
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:12,代码来源:test_output.py

示例10: test_out_table_complex_obj

    def test_out_table_complex_obj(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        obj = OrderedDict()
        obj['name'] = 'qwerty'
        obj['val'] = '0b1f6472qwerty'
        obj['sub'] = {'1'}
        result_item = CommandResultItem(obj)
        output_producer.out(result_item)
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """Name    Val
------  --------------
qwerty  0b1f6472qwerty
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:13,代码来源:test_output.py

示例11: test_out_list_valid_str_array

    def test_out_list_valid_str_array(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem(['location', 'id', 'host', 'server']))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""location

id

host

server


"""))
开发者ID:Azure,项目名称:azure-cli,代码行数:14,代码来源:test_output.py

示例12: test_out_list_valid_complex_array

    def test_out_list_valid_complex_array(self):
        output_producer = OutputProducer(formatter=format_list, file=self.io)
        output_producer.out(CommandResultItem({'active': True, 'id': '0b1f6472',
                                        'myarray': ['1', '2', '3', '4']}))
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
"""Active  : True
Id      : 0b1f6472
Myarray :
   1
   2
   3
   4


"""))
开发者ID:Azure,项目名称:azure-cli,代码行数:15,代码来源:test_output.py

示例13: test_out_table_no_query_yes_transformer_order

    def test_out_table_no_query_yes_transformer_order(self):
        output_producer = OutputProducer(formatter=format_table, file=self.io)
        obj = {'name': 'qwerty', 'val': '0b1f6472qwerty', 'active': True, 'sub': '0b1f6472'}

        def transformer(r):
            return OrderedDict([('Name', r['name']), ('Val', r['val']),
                                ('Active', r['active']), ('Sub', r['sub'])])

        result_item = CommandResultItem(obj, table_transformer=transformer, is_query_active=False)
        output_producer.out(result_item)
        # Should be table transformer order
        self.assertEqual(util.normalize_newlines(self.io.getvalue()), util.normalize_newlines(
            """Name    Val               Active  Sub
------  --------------  --------  --------
qwerty  0b1f6472qwerty         1  0b1f6472
"""))
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:16,代码来源:test_output.py

示例14: main

def main(args, file=sys.stdout):  # pylint: disable=redefined-builtin
    azlogging.configure_logging(args)
    logger.debug('Command arguments %s', args)

    if len(args) > 0 and args[0] == '--version':
        show_version_info_exit(file)

    azure_folder = get_config_dir()
    if not os.path.exists(azure_folder):
        os.makedirs(azure_folder)
    ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
    CONFIG.load(os.path.join(azure_folder, 'az.json'))
    SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)

    APPLICATION.initialize(Configuration())

    try:
        cmd_result = APPLICATION.execute(args)

        # Commands can return a dictionary/list of results
        # If they do, we print the results.
        if cmd_result and cmd_result.result is not None:
            from azure.cli.core._output import OutputProducer
            formatter = OutputProducer.get_formatter(APPLICATION.configuration.output_format)
            OutputProducer(formatter=formatter, file=file).out(cmd_result)

    except Exception as ex:  # pylint: disable=broad-except

        # TODO: include additional details of the exception in telemetry
        telemetry.set_exception(ex, 'outer-exception',
                                'Unexpected exception caught during application execution.')
        telemetry.set_failure()

        error_code = handle_exception(ex)
        return error_code
开发者ID:Visual-Studio-China,项目名称:azure-cli-int,代码行数:35,代码来源:main.py

示例15: main

def main(args, file=sys.stdout): #pylint: disable=redefined-builtin
    _logging.configure_logging(args)

    if len(args) > 0 and args[0] == '--version':
        show_version_info_exit(file)

    azure_folder = os.path.expanduser('~/.azure')
    if not os.path.exists(azure_folder):
        os.makedirs(azure_folder)
    ACCOUNT.load(os.path.join(azure_folder, 'azureProfile.json'))
    CONFIG.load(os.path.join(azure_folder, 'az.json'))
    SESSION.load(os.path.join(azure_folder, 'az.sess'), max_age=3600)

    config = Configuration(args)
    APPLICATION.initialize(config)

    try:
        cmd_result = APPLICATION.execute(args)
        # Commands can return a dictionary/list of results
        # If they do, we print the results.
        if cmd_result and cmd_result.result:
            from azure.cli.core._output import OutputProducer
            formatter = OutputProducer.get_formatter(APPLICATION.configuration.output_format)
            OutputProducer(formatter=formatter, file=file).out(cmd_result)
    except Exception as ex: # pylint: disable=broad-except
        from azure.cli.core.telemetry import log_telemetry
        log_telemetry('Error', log_type='trace')
        error_code = handle_exception(ex)
        return error_code
开发者ID:Azure,项目名称:azure-cli,代码行数:29,代码来源:main.py


注:本文中的azure.cli.core._output.OutputProducer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。