How to use run_mock method in toolium

Best Python code snippet using toolium_python

test_run.py

Source:test_run.py Github

copy

Full Screen

1import os2import pathlib3import subprocess4import unittest5from unittest.mock import patch6from jgo.jgo import (7 _jgo_main,8 Endpoint,9 executable_path_or_raise,10 ExecutableNotFound,11 HelpRequested,12 InvalidEndpoint,13 jgo_parser,14 NoEndpointProvided,15 NoMainClassInManifest,16 run,17)18from jgo.util import main_from_endpoint19class TestExceptions(unittest.TestCase):20 def test_find_tool(self):21 with self.assertRaises(ExecutableNotFound):22 executable_path_or_raise("does not exist")23 def test_help_without_endpoint(self):24 parser = jgo_parser()25 argv = ["--help"]26 with self.assertRaises(HelpRequested):27 run(parser, argv)28 def test_no_endpoint(self):29 parser = jgo_parser()30 argv = []31 with self.assertRaises(NoEndpointProvided):32 run(parser, argv)33 def _test_help_before_endpoint(self):34 # Does not work yet35 parser = jgo_parser()36 argv = ["--help", "org.codehaus.groovy:groovy-groovysh"]37 with self.assertRaises(HelpRequested):38 run(parser, argv)39 def _test_help_after_endpoint(self):40 # Does not work yet41 parser = jgo_parser()42 argv = ["org.codehaus.groovy:groovy-groovysh", "--help"]43 with self.assertRaises(HelpRequested):44 run(parser, argv)45 def test_too_many_colons(self):46 parser = jgo_parser()47 argv = ["invalid:endpoint:syntax:too:many:colons"]48 with self.assertRaises(NoEndpointProvided):49 run(parser, argv)50 def test_extra_endpoint_elements(self):51 parser = jgo_parser()52 argv = [53 "io.netty:netty-transport-native-epoll:4.1.79.Final:linux-x86_64:FakeMainClass:SomethingElse"54 ]55 with self.assertRaises(NoEndpointProvided):56 run(parser, argv)57 def test_additional_endpoint_too_many_colons(self):58 parser = jgo_parser()59 argv = [60 "--additional-endpoints",61 "invalid:endpoint:syntax:too:many:colons",62 "mvxcvi:cljstyle",63 ]64 with self.assertRaisesRegex(InvalidEndpoint, "Too many elements"):65 run(parser, argv)66 def test_too_few_colons(self):67 parser = jgo_parser()68 argv = ["invalid:"]69 with self.assertRaises(subprocess.CalledProcessError):70 run(parser, argv)71 def test_additional_endpoint_too_few_colons(self):72 parser = jgo_parser()73 argv = ["--additional-endpoints", "invalid", "mvxcvi:cljstyle"]74 with self.assertRaisesRegex(InvalidEndpoint, "Not enough artifacts specified"):75 run(parser, argv)76 def test_invalid_primary_endpoint_managed(self):77 parser = jgo_parser()78 argv = [79 "--manage-dependencies",80 "org.scijava:scijava-optional:MANAGED+org.scijava:scijava-common:MANAGED",81 ]82 with self.assertRaisesRegex(InvalidEndpoint, "version=MANAGED"):83 run(parser, argv)84 def test_unresolvable_endpoint(self):85 parser = jgo_parser()86 argv = ["unresolvable:endpoint"]87 with self.assertRaises(subprocess.CalledProcessError):88 run(parser, argv)89 def test_no_main_class_in_manifest(self):90 parser = jgo_parser()91 argv = ["org.codehaus.groovy:groovy-groovysh"]92 with self.assertRaises(NoMainClassInManifest):93 run(parser, argv)94class TestMainCaughtExceptions(unittest.TestCase):95 def test_help_without_endpoint(self):96 argv = ["--help"]97 rv = _jgo_main(argv)98 self.assertEqual(rv, 0, "Expected return code zero.")99 def test_without_endpoint(self):100 argv = []101 rv = _jgo_main(argv)102 self.assertEqual(rv, 254, "Expected return code 254.")103 def test_too_few_colons(self):104 argv = ["invalid:"]105 rv = _jgo_main(argv)106 self.assertEqual(rv, 1, "Expected return code one.")107class TestRun(unittest.TestCase):108 @patch("jgo.jgo._run")109 def test_basic(self, run_mock):110 parser = jgo_parser()111 argv = ["com.pinterest:ktlint", "-F", "/c/path/to/file.kt"]112 run(parser, argv)113 self.assertTrue(run_mock.called)114 workspace = run_mock.call_args.args[0]115 primary_endpoint: Endpoint = run_mock.call_args.args[1]116 jvm_args = run_mock.call_args.args[2]117 program_args = run_mock.call_args.args[3]118 additional_jars = run_mock.call_args.args[4]119 stdout = run_mock.call_args.args[5]120 stderr = run_mock.call_args.args[6]121 self.assertIsInstance(workspace, str)122 self.assertIsInstance(primary_endpoint, Endpoint)123 self.assertEqual(primary_endpoint.groupId, "com.pinterest")124 self.assertEqual(primary_endpoint.artifactId, "ktlint")125 self.assertEqual(jvm_args, [])126 self.assertEqual(program_args, ["-F", "/c/path/to/file.kt"])127 self.assertEqual(additional_jars, [])128 self.assertIsNone(stdout)129 self.assertIsNone(stderr)130 @patch("jgo.jgo._run")131 def test_jvm_args(self, run_mock):132 parser = jgo_parser()133 argv = [134 "-Xms1G",135 "--add-opens",136 "java.base/java.lang=ALL-UNNAMED",137 "com.pinterest:ktlint",138 "-F",139 "/c/path/to/file.kt",140 ]141 run(parser, argv)142 self.assertTrue(run_mock.called)143 workspace = run_mock.call_args.args[0]144 primary_endpoint: Endpoint = run_mock.call_args.args[1]145 jvm_args = run_mock.call_args.args[2]146 program_args = run_mock.call_args.args[3]147 additional_jars = run_mock.call_args.args[4]148 stdout = run_mock.call_args.args[5]149 stderr = run_mock.call_args.args[6]150 self.assertIsInstance(workspace, str)151 self.assertIsInstance(primary_endpoint, Endpoint)152 self.assertEqual(primary_endpoint.groupId, "com.pinterest")153 self.assertEqual(primary_endpoint.artifactId, "ktlint")154 self.assertEqual(155 jvm_args, ["-Xms1G", "--add-opens", "java.base/java.lang=ALL-UNNAMED"]156 )157 self.assertEqual(program_args, ["-F", "/c/path/to/file.kt"])158 self.assertEqual(additional_jars, [])159 self.assertIsNone(stdout)160 self.assertIsNone(stderr)161 @patch("jgo.jgo._run")162 def test_double_hyphen(self, run_mock):163 parser = jgo_parser()164 argv = [165 "--add-opens",166 "java.base/java.lang=ALL-UNNAMED",167 "com.pinterest:ktlint",168 "--",169 "-F",170 "/c/path/to/file.kt",171 ]172 run(parser, argv)173 self.assertTrue(run_mock.called)174 workspace = run_mock.call_args.args[0]175 primary_endpoint: Endpoint = run_mock.call_args.args[1]176 jvm_args = run_mock.call_args.args[2]177 program_args = run_mock.call_args.args[3]178 additional_jars = run_mock.call_args.args[4]179 stdout = run_mock.call_args.args[5]180 stderr = run_mock.call_args.args[6]181 self.assertIsInstance(workspace, str)182 self.assertIsInstance(primary_endpoint, Endpoint)183 self.assertEqual(primary_endpoint.groupId, "com.pinterest")184 self.assertEqual(primary_endpoint.artifactId, "ktlint")185 self.assertEqual(jvm_args, ["--add-opens", "java.base/java.lang=ALL-UNNAMED"])186 self.assertEqual(program_args, ["--", "-F", "/c/path/to/file.kt"])187 self.assertEqual(additional_jars, [])188 self.assertIsNone(stdout)189 self.assertIsNone(stderr)190 @patch("jgo.jgo._run")191 def test_additional_endpoints(self, run_mock):192 parser = jgo_parser()193 argv = [194 "-q",195 "--additional-endpoints",196 "io.netty:netty-transport-native-epoll",197 "org.clojure:clojure",198 "org.scijava:parsington",199 "-F",200 "/c/path/to/file.kt",201 ]202 run(parser, argv)203 self.assertTrue(run_mock.called)204 workspace = run_mock.call_args.args[0]205 primary_endpoint: Endpoint = run_mock.call_args.args[1]206 jvm_args = run_mock.call_args.args[2]207 program_args = run_mock.call_args.args[3]208 additional_jars = run_mock.call_args.args[4]209 stdout = run_mock.call_args.args[5]210 stderr = run_mock.call_args.args[6]211 self.assertIsInstance(workspace, str)212 self.assertIsInstance(primary_endpoint, Endpoint)213 self.assertEqual(primary_endpoint.groupId, "org.scijava")214 self.assertEqual(primary_endpoint.artifactId, "parsington")215 self.assertEqual(jvm_args, [])216 self.assertEqual(program_args, ["-F", "/c/path/to/file.kt"])217 self.assertEqual(additional_jars, [])218 self.assertIsNone(stdout)219 self.assertIsNone(stderr)220 with open("{}/{}".format(workspace, "coordinates.txt")) as fh:221 coordinates = fh.read()222 self.assertIn("io.netty:netty-transport-native-epoll", coordinates)223 self.assertIn("org.clojure:clojure", coordinates)224 @patch("jgo.jgo._run")225 def test_additional_endpoints_with_jvm_args(self, run_mock):226 parser = jgo_parser()227 argv = [228 "-q",229 "--additional-endpoints",230 "io.netty:netty-transport-native-epoll",231 "org.clojure:clojure",232 "--add-opens",233 "java.base/java.lang=ALL-UNNAMED",234 "org.scijava:parsington",235 "-F",236 "/c/path/to/file.kt",237 ]238 run(parser, argv)239 self.assertTrue(run_mock.called)240 workspace = run_mock.call_args.args[0]241 primary_endpoint: Endpoint = run_mock.call_args.args[1]242 jvm_args = run_mock.call_args.args[2]243 program_args = run_mock.call_args.args[3]244 additional_jars = run_mock.call_args.args[4]245 stdout = run_mock.call_args.args[5]246 stderr = run_mock.call_args.args[6]247 self.assertIsInstance(workspace, str)248 self.assertIsInstance(primary_endpoint, Endpoint)249 self.assertEqual(primary_endpoint.groupId, "org.scijava")250 self.assertEqual(primary_endpoint.artifactId, "parsington")251 self.assertEqual(jvm_args, ["--add-opens", "java.base/java.lang=ALL-UNNAMED"])252 self.assertEqual(program_args, ["-F", "/c/path/to/file.kt"])253 self.assertEqual(additional_jars, [])254 self.assertIsNone(stdout)255 self.assertIsNone(stderr)256 with open("{}/{}".format(workspace, "coordinates.txt")) as fh:257 coordinates = fh.read()258 self.assertIn("io.netty:netty-transport-native-epoll", coordinates)259 self.assertIn("org.clojure:clojure", coordinates)260 @patch("jgo.jgo.default_config")261 @patch("jgo.jgo._run")262 def test_shortcut(self, run_mock, config_mock):263 parser = jgo_parser()264 argv = ["--ignore-jgorc", "ktlint"]265 config_mock.return_value = {266 "settings": {"cacheDir": os.path.join(str(pathlib.Path.home()), ".jgo")},267 "repositories": {},268 "shortcuts": {"ktlint": "com.pinterest:ktlint"},269 }270 run(parser, argv)271 self.assertTrue(config_mock.called)272 self.assertTrue(run_mock.called)273 workspace = run_mock.call_args.args[0]274 primary_endpoint: Endpoint = run_mock.call_args.args[1]275 jvm_args = run_mock.call_args.args[2]276 program_args = run_mock.call_args.args[3]277 additional_jars = run_mock.call_args.args[4]278 stdout = run_mock.call_args.args[5]279 stderr = run_mock.call_args.args[6]280 self.assertIsInstance(workspace, str)281 self.assertIsInstance(primary_endpoint, Endpoint)282 self.assertEqual(primary_endpoint.groupId, "com.pinterest")283 self.assertEqual(primary_endpoint.artifactId, "ktlint")284 self.assertEqual(jvm_args, [])285 self.assertEqual(program_args, [])286 self.assertEqual(additional_jars, [])287 self.assertIsNone(stdout)288 self.assertIsNone(stderr)289 @patch("jgo.jgo._run")290 def test_classifier(self, run_mock):291 parser = jgo_parser()292 argv = [293 "io.netty:netty-transport-native-epoll:4.1.79.Final:linux-x86_64:FakeMainClass"294 ]295 run(parser, argv)296 self.assertTrue(run_mock.called)297 workspace = run_mock.call_args.args[0]298 primary_endpoint: Endpoint = run_mock.call_args.args[1]299 jvm_args = run_mock.call_args.args[2]300 program_args = run_mock.call_args.args[3]301 additional_jars = run_mock.call_args.args[4]302 stdout = run_mock.call_args.args[5]303 stderr = run_mock.call_args.args[6]304 self.assertIsInstance(workspace, str)305 self.assertIsInstance(primary_endpoint, Endpoint)306 self.assertEqual(primary_endpoint.groupId, "io.netty")307 self.assertEqual(primary_endpoint.artifactId, "netty-transport-native-epoll")308 self.assertEqual(primary_endpoint.classifier, "linux-x86_64")309 self.assertEqual(jvm_args, [])310 self.assertEqual(program_args, [])311 self.assertEqual(additional_jars, [])312 self.assertIsNone(stdout)313 self.assertIsNone(stderr)314 @patch("jgo.jgo.launch_java")315 def test_explicit_main_class(self, launch_java_mock):316 parser = jgo_parser()317 argv = ["org.jruby:jruby-complete:@jruby.Main"]318 run(parser, argv)319 self.assertTrue(launch_java_mock.called)320 workspace = launch_java_mock.call_args.args[0]321 jvm_args = launch_java_mock.call_args.args[1]322 program_args = launch_java_mock.call_args.args[2:]323 additional_jars = launch_java_mock.call_args.kwargs["additional_jars"]324 stdout = launch_java_mock.call_args.kwargs["stdout"]325 stderr = launch_java_mock.call_args.kwargs["stderr"]326 check = launch_java_mock.call_args.kwargs["check"]327 self.assertIsInstance(workspace, str)328 self.assertEqual(jvm_args, [])329 self.assertEqual(program_args, ("org.jruby.Main",))330 self.assertEqual(additional_jars, [])331 self.assertIsNone(stdout)332 self.assertIsNone(stderr)333 self.assertFalse(check)334class TestUtil(unittest.TestCase):335 @patch("jgo.jgo._run")336 def test_main_from_endpoint(self, run_mock):337 main_from_endpoint(338 "org.janelia.saalfeldlab:paintera",339 argv=[],340 primary_endpoint_version="0.8.1",341 secondary_endpoints=("org.slf4j:slf4j-simple:1.7.25",),342 )343 self.assertTrue(run_mock.called)344 workspace = run_mock.call_args.args[0]345 primary_endpoint: Endpoint = run_mock.call_args.args[1]346 jvm_args = run_mock.call_args.args[2]347 program_args = run_mock.call_args.args[3]348 additional_jars = run_mock.call_args.args[4]349 stdout = run_mock.call_args.args[5]350 stderr = run_mock.call_args.args[6]351 self.assertIsInstance(workspace, str)352 self.assertIsInstance(primary_endpoint, Endpoint)353 self.assertEqual(primary_endpoint.groupId, "org.janelia.saalfeldlab")354 self.assertEqual(primary_endpoint.artifactId, "paintera")355 self.assertEqual(len(jvm_args), 2)356 self.assertIn("-Xmx", jvm_args[0])357 self.assertEqual(jvm_args[1], "-XX:+UseConcMarkSweepGC")358 self.assertEqual(program_args, [])359 self.assertEqual(additional_jars, [])360 self.assertIsNone(stdout)361 self.assertIsNone(stderr)362 with open("{}/{}".format(workspace, "coordinates.txt")) as fh:363 coordinates = fh.read()364 self.assertIn("org.slf4j:slf4j-simple", coordinates)365 @patch("jgo.jgo._run")366 def test_main_from_endpoint_with_jvm_args(self, run_mock):367 main_from_endpoint(368 "org.janelia.saalfeldlab:paintera",369 argv=["-Xmx1024m", "--"],370 primary_endpoint_version="0.8.1",371 secondary_endpoints=("org.slf4j:slf4j-simple:1.7.25",),372 )373 self.assertTrue(run_mock.called)374 workspace = run_mock.call_args.args[0]375 primary_endpoint: Endpoint = run_mock.call_args.args[1]376 jvm_args = run_mock.call_args.args[2]377 program_args = run_mock.call_args.args[3]378 additional_jars = run_mock.call_args.args[4]379 stdout = run_mock.call_args.args[5]380 stderr = run_mock.call_args.args[6]381 self.assertIsInstance(workspace, str)382 self.assertIsInstance(primary_endpoint, Endpoint)383 self.assertEqual(primary_endpoint.groupId, "org.janelia.saalfeldlab")384 self.assertEqual(primary_endpoint.artifactId, "paintera")385 self.assertEqual(jvm_args, ["-Xmx1024m", "-XX:+UseConcMarkSweepGC"])386 self.assertEqual(program_args, [])387 self.assertEqual(additional_jars, [])388 self.assertIsNone(stdout)389 self.assertIsNone(stderr)390 with open("{}/{}".format(workspace, "coordinates.txt")) as fh:391 coordinates = fh.read()392 self.assertIn("org.slf4j:slf4j-simple", coordinates)393if __name__ == "__main__":...

Full Screen

Full Screen

test_reboot_command.py

Source:test_reboot_command.py Github

copy

Full Screen

1# This Source Code Form is subject to the terms of the Mozilla Public2# License, v. 2.0. If a copy of the MPL was not distributed with this3# file, you can obtain one at http://mozilla.org/MPL/2.0/.4from mock import patch5from django.core.management import call_command6from django.core.management.base import CommandError7def test_reboot_skips_ssh_reboot_when_ping_fails(settings):8 settings.DOWN_TIMEOUT = 19 settings.UP_TIMEOUT = 110 settings.REBOOT_METHODS = ['ssh_reboot']11 with patch('subprocess.run') as run_mock, \12 patch('subprocess.check_output') as check_output_mock, \13 patch('time.sleep'):14 run_mock.side_effect = CommandError() # i.e. ping fails15 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')16 run_mock.assert_called_once_with([17 'ping', '-c', '4', '-w', '5',18 'test_tc_worker_id.test.releng.dne-dc-1.mozilla.com'], check=True, timeout=5)19 assert not check_output_mock.called20def test_reboot_skips_ssh_reboot_when_missing_creds(settings):21 settings.DOWN_TIMEOUT = 122 settings.UP_TIMEOUT = 123 settings.REBOOT_METHODS = ['ssh_reboot']24 with patch('subprocess.run') as run_mock, \25 patch('subprocess.check_output') as check_output_mock, \26 patch('time.sleep'):27 run_mock.return_value = 0 # i.e. ping succeeds28 call_command('reboot', 'dne_test_tc_worker_id', 'dne-dc-1')29 assert not check_output_mock.called30# ping succeeds then fails then succeeds again31# to simulate machine going down and coming back up32ping_success_side_effects = [33 None,34 None,35 CommandError("Ping failed!"),36 CommandError("Ping failed!"),37 None,38]39def test_reboot_ssh_success(settings):40 settings.DOWN_TIMEOUT = 141 settings.UP_TIMEOUT = 142 settings.REBOOT_METHODS = ['ssh_reboot']43 with patch('subprocess.run') as run_mock, \44 patch('subprocess.check_output') as check_output_mock, \45 patch('time.sleep'):46 run_mock.side_effect = ping_success_side_effects47 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')48 assert run_mock.call_count == 549 check_output_mock.assert_called_once_with([50 'ssh',51 '-o', 'PasswordAuthentication=no',52 '-o', 'StrictHostKeyChecking=no',53 '-o', 'UserKnownHostsFile=/dev/null',54 '-i', '~/.ssh/test_ipmitool_pass.key',55 '-l', 'reboot-forcecommand-user',56 '-p', '22',57 'test_tc_worker_id.test.releng.dne-dc-1.mozilla.com', 'reboot'], stderr=-2, timeout=5)58def test_reboot_ipmi_success(settings):59 settings.DOWN_TIMEOUT = 160 settings.UP_TIMEOUT = 161 settings.REBOOT_METHODS = ['ipmi_reboot']62 with patch('subprocess.run') as run_mock, \63 patch('subprocess.check_output') as check_output_mock, \64 patch('time.sleep'):65 run_mock.side_effect = ping_success_side_effects66 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')67 assert run_mock.call_count == 568 # just check the last call since specifics tested in ipmi_reboot tests69 check_output_mock.assert_called_with([70 'ipmitool',71 '-H', 'test_tc_worker_id.test.releng.dne-dc-1.mozilla.com',72 '-I', 'lanplus',73 '-L', 'ADMINISTRATOR',74 '-p', '623',75 '-U', 'test_reboot_user',76 '-P', 'test_ipmitool_pass',77 'power', 'on'], stderr=-2, timeout=5)78def test_reboot_snmp_success(settings):79 settings.DOWN_TIMEOUT = 180 settings.UP_TIMEOUT = 181 settings.REBOOT_METHODS = ['snmp_reboot']82 with patch('subprocess.run') as run_mock, \83 patch('subprocess.check_output') as check_output_mock, \84 patch('time.sleep'):85 run_mock.side_effect = ping_success_side_effects86 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')87 assert run_mock.call_count == 588 # just check the last call since specifics tested in ipmi_reboot tests89 check_output_mock.assert_called_with([90 'snmpset',91 '-v', '1',92 '-c', 'private',93 'pdu1.r201-6.ops.releng.dne1.mozilla.com',94 "1.3.6.1.4.1.1718.3.2.3.1.11.1.1.['1']", 'i', '1'], stderr=-2, timeout=60)95def test_reboot_xenapi_success(settings):96 settings.DOWN_TIMEOUT = 197 settings.UP_TIMEOUT = 198 settings.REBOOT_METHODS = ['xenapi_reboot']99 with patch('subprocess.run') as run_mock, \100 patch('subprocess.check_output'), \101 patch('time.sleep'), \102 patch('relops_hardware_controller.api.management.commands'103 '.xenapi_reboot.XenAPI.Session') as mock_session_ctor:104 run_mock.side_effect = ping_success_side_effects105 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')106 # just check one call since specifics tested in xenapi_reboot tests107 mock_session_ctor.assert_called_once_with(uri='https://xenapiserver/')108 assert run_mock.call_count == 5109def test_reboot_ilo_success(settings):110 settings.DOWN_TIMEOUT = 1111 settings.UP_TIMEOUT = 1112 settings.REBOOT_METHODS = ['ilo_reboot']113 with patch('subprocess.run') as run_mock, \114 patch('subprocess.check_output'), \115 patch('time.sleep'), \116 patch('hpilo.Ilo') as mock_ilo_ctor:117 mock_ilo = mock_ilo_ctor.return_value118 mock_ilo.get_host_power_status.return_value = 'ON'119 mock_ilo.reset_server.side_effect = Exception('ilo.reset_server failed!')120 run_mock.side_effect = ping_success_side_effects121 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')122 # just check one call since specifics tested in ilo_reboot tests123 mock_ilo.reset_server.assert_called_once_with()124 assert run_mock.call_count == 5125def test_reboot_bugzilla_success(settings):126 settings.DOWN_TIMEOUT = 1127 settings.UP_TIMEOUT = 1128 settings.REBOOT_METHODS = ['file_bugzilla_bug']129 with patch('subprocess.run') as run_mock, \130 patch('subprocess.check_output'), \131 patch('time.sleep'), \132 patch('requests.post') as post_mock:133 run_mock.side_effect = ping_success_side_effects134 call_command('reboot', 'test_tc_worker_id', 'dne-dc-1')135 # just check one call since specifics tested in file_bugzilla_bug tests136 assert post_mock.called...

Full Screen

Full Screen

test_commands_run.py

Source:test_commands_run.py Github

copy

Full Screen

1import json2from unittest import TestCase, mock3from fly import Fly4def patch_subprocess(return_value=None):5 def wraps(fn):6 @mock.patch('subprocess.run')7 @mock.patch('fly.Fly.get_fly')8 def test(self, get_fly_mock, run_mock):9 stdout_mock = mock.Mock()10 attrs = {'stdout': return_value}11 stdout_mock.configure_mock(**attrs)12 run_mock.return_value = stdout_mock13 return fn(self, run_mock)14 return test15 return wraps16class TestCommandsRun(TestCase):17 def setUp(self):18 self.fly = Fly(19 concourse_url='http://127.0.0.1:8080'20 )21 self.fly.get_fly()22 @patch_subprocess()23 def test_login(self, run_mock):24 self.fly.login(25 username='admin', password='admin', team_name='main')26 self.assertTrue(run_mock.called)27 run_mock.assert_called_with([28 '/usr/local/bin/fly',29 '-t', 'default',30 'login',31 '-c', 'http://127.0.0.1:8080',32 '-u', 'admin',33 '-p', 'admin',34 '-n', 'main'35 ], check=True, stdout=-1)36 @patch_subprocess(37 json.dumps([38 {39 'id': 1, 'name':40 'hello-world',41 'paused': False,42 'public': False,43 'team_name': 'main'44 }45 ])46 )47 def test_get_json(self, run_mock):48 pipelines = self.fly.get_json('pipelines')49 self.assertTrue(run_mock.called)50 run_mock.assert_called_with([51 '/usr/local/bin/fly',52 '-t', 'default',53 'pipelines',54 '--json'55 ], check=True, stdout=-1)56 self.assertListEqual(pipelines, [57 {58 'id': 1,59 'name': 'hello-world',60 'paused': False,61 'public': False,62 'team_name': 'main'63 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run toolium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful