Best Python code snippet using molecule_python
test_user_commands.py
Source:test_user_commands.py
...12class NewCommandTest(unittest.TestCase):13 def test_name(self):14 self.assertEqual('new', NewCommand.name)15 @patch('taktyk.commands.user_commands.DB.ask_and_create')16 def test_execute(self, mock_create_new):17 NewCommand().execute()18 self.assertTrue(mock_create_new.call_count == 1)19class PdkCommandTest(unittest.TestCase):20 def test_name(self):21 self.assertEqual('pdk', PdkCommand.name)22 @patch('taktyk.commands.user_commands.Decision')23 def test_execute(self, mock_decision):24 instance = Mock()25 instance.run.return_value = 'userkey'26 mock_decision.return_value = instance27 PdkCommand().execute()28 self.assertEqual(settings.USERKEY, 'userkey')29class FileSourceCommandTest(unittest.TestCase):30 def test_name(self):31 self.assertEqual('file', FileSourceCommand.name)32 @patch('taktyk.commands.user_commands.Decision')33 def test_execute(self, mock_decision):34 instance = Mock()35 instance.run.return_value = {'file': 'source'}36 mock_decision.return_value = instance37 FileSourceCommand().execute()38 self.assertEqual(settings.SOURCE, {'file': 'source'})39 self.assertEqual(settings.STRATEGY, SourceStrategy)40class SeleniumCommandTest(unittest.TestCase):41 def test_name(self):42 self.assertEqual('selenium', SeleniumCommand.name)43 def test_execute(self):44 SeleniumCommand().execute('somebrowser')45 self.assertEqual(settings.STRATEGY, SeleniumStrategy)46 self.assertEqual(settings.BROWSER, 'somebrowser')47class SessionCommandTest(unittest.TestCase):48 def test_name(self):49 self.assertEqual('session', SessionCommand.name)50 def test_execute(self):51 SessionCommand().execute()52 self.assertEqual(settings.STRATEGY, SessionStrategy)53class HtmlCommandTest(unittest.TestCase):54 def test_name(self):55 self.assertEqual('html', HtmlCommand.name)56 @patch('taktyk.commands.user_commands.HtmlFile')57 def test_execute_when_arg_is_true(self, mock_html_file):58 with self.assertRaises(SystemExit):59 HtmlCommand().execute(arg=True)60 mock_html_file.assert_called_with(tag=None)61 @patch('taktyk.commands.user_commands.HtmlFile')62 def test_execute_when_arg_is_tag(self, mock_html_file):63 with self.assertRaises(SystemExit):64 HtmlCommand().execute(arg='programowanie')65 mock_html_file.assert_called_with(tag='programowanie')66 @patch('taktyk.commands.user_commands.HtmlFile.create')67 def test_execute_if_create_called(self, mock_create):68 with self.assertRaises(SystemExit):69 HtmlCommand().execute(arg=True)70 self.assertTrue(mock_create.called)71class CommentsCommandTest(unittest.TestCase):72 def test_name(self):73 self.assertEqual('comments', CommentsCommand.name)74 @patch('taktyk.DB.get_ids')75 def test_execute(self, mock_get_ids):76 mock_get_ids.return_value = [1, 2, 3, 4]77 CommentsCommand().execute()78 self.assertTrue(settings.FULL_UPDATE)79 self.assertEqual(settings.SOURCE, {'ids': [1, 2, 3, 4]})80 self.assertEqual(settings.STRATEGY, SourceStrategy)81 mock_get_ids.assert_called_with('entry')82class NsfwCommandTest(unittest.TestCase):83 def test_name(self):84 self.assertEqual('nsfw', NsfwCommand.name)85 def test_execute(self):86 NsfwCommand().execute()87 self.assertTrue(settings.NSFW_FILTER)88class SkipCommandTest(unittest.TestCase):89 def test_name(self):90 self.assertEqual('skip', SkipCommand.name)91 def test_execute_when_arg_is_true(self):92 SkipCommand().execute(arg=True)93 self.assertTrue(settings.SKIP_FILES is True)94 def test_execute_when_arg_is_com(self):95 SkipCommand().execute(arg='com')96 self.assertTrue(settings.SKIP_FILES == 'com')97class ScrapeCommandTest(unittest.TestCase):98 def test_name(self):99 self.assertEqual('scrape', ScrapeCommand.name)100 def test_execute(self):101 settings.STRATEGY = APIStrategy102 ScrapeCommand().execute()103 self.assertTrue(settings.SCRAPE)104 self.assertEqual(settings.STRATEGY, SessionStrategy)105 self.assertEqual(settings.METHOD, ScrapeMethod)106class IdsCommandTest(unittest.TestCase):107 def test_name(self):108 self.assertEqual('ids', IdsCommand.name)109 @patch('taktyk.commands.user_commands.Decision')110 def test_execute(self, mock_decision):111 instance = Mock()112 instance.run.return_value = (1, 2, 3, 44)113 mock_decision.return_value = instance114 IdsCommand().execute()115 self.assertEqual(settings.SOURCE, {'ids': (1, 2, 3, 44)})...
test_execute.py
Source:test_execute.py
...3from sandbox import Sandbox, HAVE_PYPY4from sandbox.test import createSandbox, createSandboxConfig, SkipTest5from sandbox.test.tools import capture_stdout6import os7def test_execute():8 config = createSandboxConfig()9 if HAVE_PYPY:10 # FIXME: is it really needed?11 config._builtins_whitelist.add('compile')12 if config.use_subprocess:13 globals_builtins = set()14 else:15 globals_builtins = set(( '__builtins__',))16 def test(*lines, **kw):17 code = "; ".join(lines)18 Sandbox(config).execute(code, **kw)19 test(20 "assert globals() is locals(), 'test_execute #1a'",21 "assert list(globals().keys()) == list(locals().keys()) == ['__builtins__'], 'test_execute #1b'",...
test_custom_backend.py
Source:test_custom_backend.py
...11 torch.ops.load_library(self.library_path)12 # Create an instance of the test Module and lower it for13 # the custom backend.14 self.model = to_custom_backend(torch.jit.script(Model()))15 def test_execute(self):16 """17 Test execution using the custom backend.18 """19 a = torch.randn(4)20 b = torch.randn(4)21 # The custom backend is hardcoded to compute f(a, b) = (a + b, a - b).22 expected = (a + b, a - b)23 out = self.model(a, b)24 self.assertTrue(expected[0].allclose(out[0]))25 self.assertTrue(expected[1].allclose(out[1]))26 def test_save_load(self):27 """28 Test that a lowered module can be executed correctly29 after saving and loading.30 """31 # Test execution before saving and loading to make sure32 # the lowered module works in the first place.33 self.test_execute()34 # Save and load.35 f = tempfile.NamedTemporaryFile(delete=False)36 try:37 f.close()38 torch.jit.save(self.model, f.name)39 loaded = torch.jit.load(f.name)40 finally:41 os.unlink(f.name)42 self.model = loaded43 # Test execution again.44 self.test_execute()45if __name__ == "__main__":...
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!!