當前位置: 首頁>>代碼示例>>Python>>正文


Python Command._clean_render_args方法代碼示例

本文整理匯總了Python中ripe.atlas.tools.commands.probes.Command._clean_render_args方法的典型用法代碼示例。如果您正苦於以下問題:Python Command._clean_render_args方法的具體用法?Python Command._clean_render_args怎麽用?Python Command._clean_render_args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ripe.atlas.tools.commands.probes.Command的用法示例。


在下文中一共展示了Command._clean_render_args方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestProbesCommand

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import _clean_render_args [as 別名]

#.........這裏部分代碼省略.........
                "COUNTRY_CODE: DE\n"
                " ASN_V4: 3332\n"
                "  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    3     3332   None   DE None        \n"
                " ASN_V4: 3333\n  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    2     3333   None   DE None        \n"
                "Total probes found: 4\n"
            )
            expected_set = set(expected_blob.split("\n"))
            returned_set = set(mystdout.getvalue().split("\n"))
            self.assertEquals(returned_set, expected_set)

        sys.stdout = old_stdout

    def test_render_with_aggregation_with_limit(self):
        """Tests rendering of results with aggregation with limit"""
        self.cmd.init_args([
            "--country-code", "GR", "--aggregate-by", "country_code",
            "--aggregate-by", "asn_v4", "--aggregate-by", "prefix_v4",
            "--limit", "1"
        ])

        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"
                "COUNTRY_CODE: GR\n"
                " ASN_V4: 3333\n"
                "  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    1     3333   None   GR None        \n"
                "Total probes found: 4\n"
            )
            self.assertEquals(mystdout.getvalue(), expected_output)

        sys.stdout = old_stdout

    def test_render_with_aggregation_with_max_per_aggr(self):
        """
        Tests rendering of results with aggregation with max per aggr option
        """
        self.cmd.init_args([
            "--country-code", "GR", "--aggregate-by", "country_code",
            "--aggregate-by", "asn_v4", "--aggregate-by", "prefix_v4",
            "--max-per-aggregation", "1"
        ])

        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_blob = (
                "We found the following probes with the given criteria:\n"
                "COUNTRY_CODE: NL\n"
                " ASN_V4: 3333\n"
                "  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    4     3333   None   NL None        \n"
                "COUNTRY_CODE: GR\n"
                " ASN_V4: 3333\n"
                "  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    1     3333   None   GR None        \n"
                "COUNTRY_CODE: DE\n"
                " ASN_V4: 3332\n"
                "  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    3     3332   None   DE None        \n"
                " ASN_V4: 3333\n"
                "  PREFIX_V4: 193.0/22\n"
                "    ID    ASNv4  ASNv6  CC Status      \n"
                "    2     3333   None   DE None        \n"
                "Total probes found: 4\n"
            )
            expected_set = set(expected_blob.split("\n"))
            returned_set = set(mystdout.getvalue().split("\n"))
            self.assertEquals(returned_set, expected_set)

        sys.stdout = old_stdout

    def test_render_args(self):
        """User passed max_per_aggr and additional fields args"""
        self.cmd.init_args([
            "--max-per-aggregation",
            "3",
            "--additional-fields",
            "blaaaa, grrrrr"
        ])
        self.assertEquals(
            self.cmd._clean_render_args(),
            {"max_per_aggr": 3, "additional_fields": ["blaaaa", "grrrrr"]}
        )
開發者ID:OpenAbricot,項目名稱:ripe-atlas-tools,代碼行數:104,代碼來源:probes.py


注:本文中的ripe.atlas.tools.commands.probes.Command._clean_render_args方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。