Best Python code snippet using autotest_python
subcommand_unittest.py
Source:subcommand_unittest.py
...64 def test_fork_start_parent(self):65 cmd = self._setup_fork_start_parent()66 self.assertEquals(cmd.pid, 1000)67 self.god.check_playback()68 def _setup_fork_start_child(self):69 self.god.stub_function(subcommand.os, 'pipe')70 self.god.stub_function(subcommand.os, 'fork')71 self.god.stub_function(subcommand.os, 'close')72 self.god.stub_function(subcommand.os, 'write')73 self.god.stub_function(subcommand.cPickle, 'dumps')74 self.god.stub_function(subcommand.os, '_exit')75 def test_fork_start_child(self):76 self._setup_fork_start_child()77 func = self.god.create_mock_function('func')78 fork_hook = self.god.create_mock_function('fork_hook')79 join_hook = self.god.create_mock_function('join_hook')80 subcommand.subcommand.register_fork_hook(fork_hook)81 subcommand.subcommand.register_join_hook(join_hook)82 cmd = _create_subcommand(func, (1, 2))83 subcommand.os.pipe.expect_call().and_return((10, 20))84 subcommand.os.fork.expect_call().and_return(0)85 subcommand.os.close.expect_call(10)86 fork_hook.expect_call(cmd)87 func.expect_call(1, 2).and_return(True)88 subcommand.cPickle.dumps.expect_call(True,89 subcommand.cPickle.HIGHEST_PROTOCOL).and_return('True')90 subcommand.os.write.expect_call(20, 'True')91 subcommand.os.close.expect_call(20)92 join_hook.expect_call(cmd)93 subcommand.os._exit.expect_call(0)94 cmd.fork_start()95 self.god.check_playback()96 def test_fork_start_child_error(self):97 self._setup_fork_start_child()98 self.god.stub_function(subcommand.logging, 'exception')99 func = self.god.create_mock_function('func')100 cmd = _create_subcommand(func, (1, 2))101 error = Exception('some error')102 subcommand.os.pipe.expect_call().and_return((10, 20))103 subcommand.os.fork.expect_call().and_return(0)104 subcommand.os.close.expect_call(10)105 func.expect_call(1, 2).and_raises(error)106 subcommand.logging.exception.expect_call('function failed')107 subcommand.cPickle.dumps.expect_call(error,108 subcommand.cPickle.HIGHEST_PROTOCOL).and_return('error')109 subcommand.os.write.expect_call(20, 'error')110 subcommand.os.close.expect_call(20)111 subcommand.os._exit.expect_call(1)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!