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


Python Command.get_aggregators方法代码示例

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


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

示例1: TestProbesCommand

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

#.........这里部分代码省略.........
            "--country-code", "GR",
            "--limit", "2"
        ])

        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,2")

        sys.stdout = old_stdout

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

        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,2,3,4,5")

        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_code",
            "--aggregate-by", "prefix_v4"
        ])
        expected_output = [
            ValueKeyAggregator(key="asn_v4"),
            ValueKeyAggregator(key="country_code"),
            ValueKeyAggregator(key="prefix_v4")
        ]
        output = self.cmd.get_aggregators()
        for index, v in enumerate(output):
            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(["--limit", "4"])

        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 = (
                "We found the following probes with the given criteria:\n"
                "ID    ASNv4  ASNv6  CC Status      \n"
开发者ID:OpenAbricot,项目名称:ripe-atlas-tools,代码行数:70,代码来源:probes.py


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