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


Python Command.run方法代碼示例

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


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

示例1: test_with_random_args

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_with_random_args(self):
     """User passes random args, should fail with SystemExit"""
     with capture_sys_output():
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["blaaaaaaa"])
             cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:9,代碼來源:probes.py

示例2: test_arg_with_no_value

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_arg_with_no_value(self):
     """User passed not boolean arg but no value"""
     with capture_sys_output():
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["--asn"])
             cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:9,代碼來源:probes.py

示例3: test_render_with_aggregation_with_limit

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
    def test_render_with_aggregation_with_limit(self):
        """Tests rendering of results with aggregation with limit"""
        cmd = Command()
        cmd.init_args([
            "--country", "GR",
            "--aggregate-by", "country",
            "--aggregate-by", "asn_v4",
            "--aggregate-by", "prefix_v4",
            "--limit", "1"
        ])

        with capture_sys_output() as (stdout, stderr):
            path = 'ripe.atlas.tools.commands.probes.ProbeRequest'
            with mock.patch(path) as mock_get:
                mock_get.return_value = FakeGen()
                cmd.run()
                expected_output = (
                    "\n"
                    "Filters:\n"
                    "  Country: GR\n"
                    "\n"
                    "   ID    Asn_v4 Asn_v6 Country Status      \n"
                    "===========================================\n"
                    "Country: GR\n"
                    " ASN_V4: 3333\n"
                    "  PREFIX_V4: 193.0/22\n"
                    "   1     3333            gr    None        \n"
                    "===========================================\n"
                    "                Showing 1 of 4 total probes\n"
                    "\n"
                )
                expected_set = set(expected_output.split("\n"))
                returned_set = set(stdout.getvalue().split("\n"))
                self.assertEquals(returned_set, expected_set)
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:36,代碼來源:probes.py

示例4: test_render_without_aggregation_with_limit

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
    def test_render_without_aggregation_with_limit(self):
        """Tests rendering of results without aggregation but with limit"""
        cmd = Command()
        cmd.init_args([
            "--country", "GR",
            "--limit", "2"
        ])

        with capture_sys_output() as (stdout, stderr):
            path = 'ripe.atlas.tools.commands.probes.ProbeRequest'
            with mock.patch(path) as mock_get:
                mock_get.return_value = FakeGen()
                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"
                    "========================================\n"
                    "             Showing 2 of 4 total probes\n"
                    "\n"
                )
                self.assertEquals(stdout.getvalue(), expected_output)
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:29,代碼來源:probes.py

示例5: test_location_google_wrong_output

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_location_google_wrong_output(self):
     """User passed location arg but google api gave not expected format"""
     with mock.patch('requests.get') as mock_get:
         mock_get.return_value = requests.Response()
         with mock.patch('requests.Response.json') as mock_json:
             mock_json.return_value = {"blaaa": "bla"}
             with self.assertRaises(RipeAtlasToolsException):
                 cmd = Command()
                 cmd.init_args(["--location", "blaaaa"])
                 cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:12,代碼來源:probes.py

示例6: test_asn_args

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
    def test_asn_args(self):
        """User passed asn arg together with asnv4 or asnv6"""
        with self.assertRaises(RipeAtlasToolsException):
            cmd = Command()
            cmd.init_args(["--asn", "3333", "--asnv4", "3333"])
            cmd.run()

        with self.assertRaises(RipeAtlasToolsException):
            cmd = Command()
            cmd.init_args(["--asn", "3333", "--asnv6", "3333"])
            cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:13,代碼來源:probes.py

示例7: test_render_ids_only

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
    def test_render_ids_only(self):
        """User passed ids_only arg, testing rendiring"""

        cmd = Command()
        cmd.init_args([
            "--ids-only", "--country", "GR"
        ])

        with capture_sys_output() as (stdout, stderr):
            path = 'ripe.atlas.tools.commands.probes.ProbeRequest'
            with mock.patch(path) as mock_get:
                mock_get.return_value = FakeGen()
                cmd.run()
                self.assertEquals(stdout.getvalue(), "1\n2\n3\n4\n5\n")
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:16,代碼來源:probes.py

示例8: test_location_google_breaks

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_location_google_breaks(self):
     """User passed location arg but google api gave error"""
     caught_exceptions = [
         requests.ConnectionError, requests.HTTPError, requests.Timeout]
     with mock.patch('requests.get') as mock_get:
         for exception in caught_exceptions:
             mock_get.side_effect = exception
             with capture_sys_output():
                 with self.assertRaises(RipeAtlasToolsException):
                     cmd = Command()
                     cmd.init_args(["--location", "blaaaa"])
                     cmd.run()
         mock_get.side_effect = Exception()
         with self.assertRaises(Exception):
             cmd = Command()
             cmd.init_args(["--location", "blaaaa"])
             cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:19,代碼來源:probes.py

示例9: test_prefix_args

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
    def test_prefix_args(self):
        """User passed prefix arg together with prefixv4 or prefixv6"""
        with self.assertRaises(RipeAtlasToolsException):
            cmd = Command()
            cmd.init_args([
                "--prefix", "193.0.0.0/21",
                "--prefixv4", "193.0.0.0/21"
            ])
            cmd.run()

        with self.assertRaises(RipeAtlasToolsException):
            cmd = Command()
            cmd.init_args([
                "--prefix", "2001:67c:2e8::/48",
                "--prefixv6", "2001:67c:2e8::/48"
            ])
            cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:19,代碼來源:probes.py

示例10: test_arg_with_wrong_type

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_arg_with_wrong_type(self):
     """User passed arg with wrong type. e.g string for asn"""
     with capture_sys_output():
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["--asn", "blaaaaa"])
             cmd.run()
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["--asnv4", "blaaaaa"])
             cmd.run()
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["--asnv6", "blaaaaa"])
             cmd.run()
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["--limit", "blaaaaa"])
             cmd.run()
         with self.assertRaises(SystemExit):
             cmd = Command()
             cmd.init_args(["--radius", "blaaaaa"])
             cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:25,代碼來源:probes.py

示例11: test_with_empty_args

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_with_empty_args(self):
     """User passes no args, should fail with RipeAtlasToolsException"""
     with self.assertRaises(RipeAtlasToolsException):
         cmd = Command()
         cmd.init_args([])
         cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:8,代碼來源:probes.py

示例12: test_center_arg_wrong_value

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
 def test_center_arg_wrong_value(self):
     """User passed center arg with wrong value"""
     with self.assertRaises(RipeAtlasToolsException):
         cmd = Command()
         cmd.init_args(["--center", "blaaaa"])
         cmd.run()
開發者ID:johanterbeest,項目名稱:ripe-atlas-tools,代碼行數:8,代碼來源:probes.py

示例13: TestProbesCommand

# 需要導入模塊: from ripe.atlas.tools.commands.probes import Command [as 別名]
# 或者: from ripe.atlas.tools.commands.probes.Command import run [as 別名]
class TestProbesCommand(unittest.TestCase):

    def setUp(self):
        self.cmd = Command()
        self.maxDiff = None

    def test_with_empty_args(self):
        """User passes no args, should fail with RipeAtlasToolsException"""
        with self.assertRaises(RipeAtlasToolsException):
            self.cmd.init_args([])
            self.cmd.run()

    def test_with_random_args(self):
        """User passes random args, should fail with SystemExit"""
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["blaaaaaaa"])
            self.cmd.run()

    def test_arg_with_no_value(self):
        """User passed not boolean arg but no value"""
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asn"])
            self.cmd.run()

    def test_arg_with_wrong_type(self):
        """User passed arg with wrong type. e.g string for asn"""
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asn", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asnv4", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--asnv6", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--limit", "blaaaaa"])
            self.cmd.run()
        with self.assertRaises(SystemExit):
            self.cmd.init_args(["--radius", "blaaaaa"])
            self.cmd.run()

    def test_location_google_breaks(self):
        """User passed location arg but google api gave error"""
        caught_exceptions = [
            requests.ConnectionError, requests.HTTPError, requests.Timeout]
        with mock.patch('requests.get') as mock_get:
            for exception in caught_exceptions:
                mock_get.side_effect = exception
                with self.assertRaises(RipeAtlasToolsException):
                    self.cmd.init_args(["--location", "blaaaa"])
                    self.cmd.run()
            mock_get.side_effect = Exception()
            with self.assertRaises(Exception):
                self.cmd.init_args(["--location", "blaaaa"])
                self.cmd.run()

    def test_location_google_wrong_output(self):
        """User passed location arg but google api gave not expected format"""
        with mock.patch('requests.get') as mock_get:
            mock_get.return_value = requests.Response()
            with mock.patch('requests.Response.json') as mock_json:
                mock_json.return_value = {"blaaa": "bla"}
                with self.assertRaises(RipeAtlasToolsException):
                    self.cmd.init_args(["--location", "blaaaa"])
                    self.cmd.run()

    def test_location_arg(self):
        """User passed location arg"""
        with mock.patch('requests.get') as mock_get:
            mock_get.return_value = requests.Response()
            with mock.patch('requests.Response.json') as mock_json:
                mock_json.return_value = {"results": [
                    {"geometry": {"location": {"lat": 1, "lng": 2}}}]}
                self.cmd.init_args(["--location", "blaaaa"])
                self.assertEquals(self.cmd.build_request_args(), {
                    "latitude": '1', "longitude": '2'})

    def test_location_arg_with_radius(self):
        """User passed location arg"""
        with mock.patch('requests.get') as mock_get:
            mock_get.return_value = requests.Response()
            with mock.patch('requests.Response.json') as mock_json:
                mock_json.return_value = {"results": [
                    {"geometry": {"location": {"lat": 1, "lng": 2}}}
                ]}
                self.cmd.init_args(["--location", "blaaaa", "--radius", "4"])
                self.assertEquals(
                    self.cmd.build_request_args(),
                    {"radius": "1,2:4"}
                )

    def test_asn_args(self):
        """User passed asn arg together with asnv4 or asnv6"""
        with self.assertRaises(RipeAtlasToolsException):
            self.cmd.init_args(["--asn", "3333", "--asnv4", "3333"])
            self.cmd.run()

        with self.assertRaises(RipeAtlasToolsException):
            self.cmd.init_args(["--asn", "3333", "--asnv6", "3333"])
#.........這裏部分代碼省略.........
開發者ID:becha42,項目名稱:ripe-atlas-tools,代碼行數:103,代碼來源:probes.py


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