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


Python Command.set_aggregators方法代码示例

本文整理汇总了Python中ripe.atlas.tools.commands.probes.Command.set_aggregators方法的典型用法代码示例。如果您正苦于以下问题:Python Command.set_aggregators方法的具体用法?Python Command.set_aggregators怎么用?Python Command.set_aggregators使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ripe.atlas.tools.commands.probes.Command的用法示例。


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

示例1: test_get_aggregators

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import set_aggregators [as 别名]
 def test_get_aggregators(self):
     """User passed --aggregate-by args"""
     cmd = Command()
     cmd.init_args([
         "--aggregate-by", "asn_v4",
         "--aggregate-by", "country",
         "--aggregate-by", "prefix_v4"
     ])
     expected_output = [
         ValueKeyAggregator(key="asn_v4"),
         ValueKeyAggregator(key="country_code"),
         ValueKeyAggregator(key="prefix_v4")
     ]
     cmd.set_aggregators()
     for index, v in enumerate(cmd.aggregators):
         self.assertTrue(isinstance(v, ValueKeyAggregator))
         self.assertEquals(
             v.aggregation_keys,
             expected_output[index].aggregation_keys
         )
开发者ID:johanterbeest,项目名称:ripe-atlas-tools,代码行数:22,代码来源:probes.py

示例2: TestProbesCommand

# 需要导入模块: from ripe.atlas.tools.commands.probes import Command [as 别名]
# 或者: from ripe.atlas.tools.commands.probes.Command import set_aggregators [as 别名]

#.........这里部分代码省略.........

    def test_render_ids_only_with_aggr(self):
        """
        User passed ids_only arg together with aggregate, testing rendering
        """
        self.cmd.init_args([
            "--ids-only",
            "--country", "GR",
            "--aggregate-by", "country"
        ])

        old_stdout = sys.stdout
        sys.stdout = mystdout = StringIO()
        path = 'ripe.atlas.tools.commands.probes.ProbeRequest'
        with mock.patch(path) as mock_get:
            mock_get.return_value = FakeGen()
            self.cmd.run()
            self.assertEquals(mystdout.getvalue(), "1\n2\n3\n4\n5\n")

        sys.stdout = old_stdout

    def test_get_aggregators(self):
        """User passed --aggregate-by args"""
        self.cmd.init_args([
            "--aggregate-by", "asn_v4",
            "--aggregate-by", "country",
            "--aggregate-by", "prefix_v4"
        ])
        expected_output = [
            ValueKeyAggregator(key="asn_v4"),
            ValueKeyAggregator(key="country_code"),
            ValueKeyAggregator(key="prefix_v4")
        ]
        self.cmd.set_aggregators()
        for index, v in enumerate(self.cmd.aggregators):
            self.assertTrue(isinstance(v, ValueKeyAggregator))
            self.assertEquals(
                v.aggregation_keys,
                expected_output[index].aggregation_keys
            )

    def test_render_without_aggregation(self):
        """Tests rendering of results without aggregation"""
        self.cmd.init_args([
            "--country", "GR"
        ])

        old_stdout = sys.stdout
        sys.stdout = mystdout = StringIO()
        path = 'ripe.atlas.tools.commands.probes.ProbeRequest'
        with mock.patch(path) as mock_get:
            mock_get.return_value = FakeGen()
            self.cmd.run()
            expected_output = (
                "\n"
                "Filters:\n"
                "  Country: GR\n"
                "\n"
                "ID    Asn_v4 Asn_v6 Country Status      \n"
                "========================================\n"
                "1     3333            gr    None        \n"
                "2     3333            de    None        \n"
                "3     3332            de    None        \n"
                "4     3333            nl    None        \n"
                "5     3333            gr    None        \n"
                "========================================\n"
开发者ID:becha42,项目名称:ripe-atlas-tools,代码行数:70,代码来源:probes.py


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