Best Python code snippet using locust
test_cli.py
Source:test_cli.py  
...35            except SystemExit:36                ret = True37            sys.argv.pop()38            self.assertEqual(True, ret)39    def test_parse_options(self):40        exp_vals = ['dummy.ext', self.src_path_pens, 'dummy.ext', 'dummy.ext', 'dummy.ext', 'dummy.ext', METHODS[0], True]41        usr_cmds = ["-s ", "--src=", '-l ', '--left=', '-r ', '--right=', "--method=", "--win"]42        par_keys = ('src_path', 'src_path', 'l_path', 'l_path', 'r_path', 'r_path', 'method', 'win')43        for cmd, kw, exp_val in zip(usr_cmds, par_keys, exp_vals):44            # get rid of arguments from previous usage45            sys.argv = sys.argv[:1]46            # pass CLI argument47            exp_str = exp_val #'"' + exp_val + '"' if isinstance(exp_val, str) else exp_val48            cli_str = cmd + str(exp_str) if type(exp_val) in (str, int, list) else cmd49            sys.argv.append(cli_str)50            print(kw, cli_str)51            try:52                self.cfg = parse_options(sys.argv[1:])53            except SystemExit:54                pass55            val = self.cfg[kw]56            sys.argv.pop()57            # check if typed method is valid58            if kw == 'method':59                self.assertTrue(val in METHODS)60            self.assertEqual(exp_val, val)61    def test_cli_run(self):62        usr_cmds = [63                    ["--src="+self.src_path_pens],64                    ['--left='+self.lr_path_cones[0], '--right='+self.lr_path_cones[1]]65                    ]66        for cmds in usr_cmds:67            # get rid of arguments from previous usage68            sys.argv = sys.argv[:1]69            # pass CLI argument70            for cmd in cmds:71                sys.argv.append(cmd)72            print(sys.argv[1:])73            # run CLI script74            ret = main()75            # check if main returned True76            self.assertTrue(ret, msg='CLI test failed for command %s' % sys.argv[1:])77    def test_cli_select_win(self):78        # initialize tkinter object79        self.root = tk.Tk()80        from depthy.misc.io_functions import select_path81        select_path(root=self.root)82        #self.wid.btn.event_generate('<Return>')83        #self.root.84        self.root.setvar()85        self.root.focus_set()86        self.pump_events()87    def pump_events(self):88        while self.root.dooneevent(tk._tkinter.ALL_EVENTS | tk._tkinter.DONT_WAIT):89            pass90    def test_all(self):91        self.test_cli_help()92        self.test_parse_options()93        self.test_cli_run()94if __name__ == '__main__':...test_product_deps_graph.py
Source:test_product_deps_graph.py  
...5from product_deps_graph import parse_options, Product6TEST_BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))7TEST_DATA_DIR = os.path.join(TEST_BASE_DIR, 'data')8class TestParseOptions(unittest.TestCase):9    def test_parse_options(self):10        '''11        test_parse_options: $ANDROID_PRODUCT_OUT or -c must be provided12        '''13        with captured_output() as (_, err):14            with self.assertRaises(SystemExit) as cm:15                parse_options([])16            exception = cm.exception17            err_msg = err.getvalue()18            self.assertIn(19                'Environment variable $ANDROID_PRODUCT_OUT or parameter "-c" should be provided.', err_msg)20            self.assertEquals(2, exception.code)21    def test_parse_options_2(self):22        '''23        test_parse_options: -c whatever/path/...test_config.py
Source:test_config.py  
...14    assert options.ignore == {"E"}15    options = parse_options("-o dummy dummy.py".split())16    assert set(options.linters) == set(["pycodestyle", "mccabe", "pyflakes"])17    assert options.skip == []18def test_parse_options(parse_options):19    options = parse_options()20    assert not options.select21def test_from_stdin(parse_options):22    options = parse_options("--from-stdin dummy.py".split())23    assert options24    assert options.from_stdin is True...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!!
