How to use test_unimportable method in green

Best Python code snippet using green

test_connections.py

Source:test_connections.py Github

copy

Full Screen

...34 )35 tor_provider = create_tor_provider(reactor, config)36 h = tor_provider.get_tor_handler()37 self.assertEqual(h, None)38 def test_unimportable(self):39 with mock.patch("allmydata.util.tor_provider._import_tor",40 return_value=None):41 config = config_from_string("fake.port", "no-basedir", BASECONFIG)42 tor_provider = create_tor_provider(reactor, config)43 h = tor_provider.get_tor_handler()44 self.assertEqual(h, None)45 def test_default(self):46 h1 = mock.Mock()47 with mock.patch("foolscap.connections.tor.default_socks",48 return_value=h1) as f:49 config = config_from_string("fake.port", "no-basedir", BASECONFIG)50 tor_provider = create_tor_provider(reactor, config)51 h = tor_provider.get_tor_handler()52 self.assertEqual(f.mock_calls, [mock.call()])53 self.assertIdentical(h, h1)54 def _do_test_launch(self, executable):55 # the handler is created right away56 config = BASECONFIG+"[tor]\nlaunch = true\n"57 if executable:58 config += "tor.executable = %s\n" % executable59 h1 = mock.Mock()60 with mock.patch("foolscap.connections.tor.control_endpoint_maker",61 return_value=h1) as f:62 config = config_from_string("fake.port", ".", config)63 tp = create_tor_provider("reactor", config)64 h = tp.get_tor_handler()65 private_dir = config.get_config_path("private")66 exp = mock.call(tp._make_control_endpoint,67 takes_status=True)68 self.assertEqual(f.mock_calls, [exp])69 self.assertIdentical(h, h1)70 # later, when Foolscap first connects, Tor should be launched71 reactor = "reactor"72 tcp = object()73 tcep = object()74 launch_tor = mock.Mock(return_value=defer.succeed(("ep_desc", tcp)))75 cfs = mock.Mock(return_value=tcep)76 with mock.patch("allmydata.util.tor_provider._launch_tor", launch_tor):77 with mock.patch("allmydata.util.tor_provider.clientFromString", cfs):78 d = tp._make_control_endpoint(reactor,79 update_status=lambda status: None)80 cep = self.successResultOf(d)81 launch_tor.assert_called_with(reactor, executable,82 os.path.abspath(private_dir),83 tp._txtorcon)84 cfs.assert_called_with(reactor, "ep_desc")85 self.assertIs(cep, tcep)86 def test_launch(self):87 self._do_test_launch(None)88 def test_launch_executable(self):89 self._do_test_launch("/special/tor")90 def test_socksport_unix_endpoint(self):91 h1 = mock.Mock()92 with mock.patch("foolscap.connections.tor.socks_endpoint",93 return_value=h1) as f:94 config = config_from_string(95 "fake.port",96 "no-basedir",97 BASECONFIG + "[tor]\nsocks.port = unix:/var/lib/fw-daemon/tor_socks.socket\n",98 )99 tor_provider = create_tor_provider(reactor, config)100 h = tor_provider.get_tor_handler()101 self.assertTrue(IStreamClientEndpoint.providedBy(f.mock_calls[0]))102 self.assertIdentical(h, h1)103 def test_socksport_endpoint(self):104 h1 = mock.Mock()105 with mock.patch("foolscap.connections.tor.socks_endpoint",106 return_value=h1) as f:107 config = config_from_string(108 "fake.port",109 "no-basedir",110 BASECONFIG + "[tor]\nsocks.port = tcp:127.0.0.1:1234\n",111 )112 tor_provider = create_tor_provider(reactor, config)113 h = tor_provider.get_tor_handler()114 self.assertTrue(IStreamClientEndpoint.providedBy(f.mock_calls[0]))115 self.assertIdentical(h, h1)116 def test_socksport_endpoint_otherhost(self):117 h1 = mock.Mock()118 with mock.patch("foolscap.connections.tor.socks_endpoint",119 return_value=h1) as f:120 config = config_from_string(121 "no-basedir",122 "fake.port",123 BASECONFIG + "[tor]\nsocks.port = tcp:otherhost:1234\n",124 )125 tor_provider = create_tor_provider(reactor, config)126 h = tor_provider.get_tor_handler()127 self.assertTrue(IStreamClientEndpoint.providedBy(f.mock_calls[0]))128 self.assertIdentical(h, h1)129 def test_socksport_bad_endpoint(self):130 config = config_from_string(131 "fake.port",132 "no-basedir",133 BASECONFIG + "[tor]\nsocks.port = meow:unsupported\n",134 )135 with self.assertRaises(ValueError) as ctx:136 tor_provider = create_tor_provider(reactor, config)137 tor_provider.get_tor_handler()138 self.assertIn(139 "Unknown endpoint type: 'meow'",140 str(ctx.exception)141 )142 def test_socksport_not_integer(self):143 config = config_from_string(144 "fake.port",145 "no-basedir",146 BASECONFIG + "[tor]\nsocks.port = tcp:localhost:kumquat\n",147 )148 with self.assertRaises(ValueError) as ctx:149 tor_provider = create_tor_provider(reactor, config)150 tor_provider.get_tor_handler()151 self.assertIn(152 "invalid literal for int() with base 10: 'kumquat'",153 str(ctx.exception)154 )155 def test_controlport(self):156 h1 = mock.Mock()157 with mock.patch("foolscap.connections.tor.control_endpoint",158 return_value=h1) as f:159 config = config_from_string(160 "fake.port",161 "no-basedir",162 BASECONFIG + "[tor]\ncontrol.port = tcp:localhost:1234\n",163 )164 tor_provider = create_tor_provider(reactor, config)165 h = tor_provider.get_tor_handler()166 self.assertEqual(len(f.mock_calls), 1)167 ep = f.mock_calls[0][1][0]168 self.assertIsInstance(ep, endpoints.TCP4ClientEndpoint)169 self.assertIdentical(h, h1)170class I2P(unittest.TestCase):171 def test_disabled(self):172 config = config_from_string(173 "fake.port",174 "no-basedir",175 BASECONFIG + "[i2p]\nenabled = false\n",176 )177 i2p_provider = create_i2p_provider(None, config)178 h = i2p_provider.get_i2p_handler()179 self.assertEqual(h, None)180 def test_unimportable(self):181 config = config_from_string(182 "fake.port",183 "no-basedir",184 BASECONFIG,185 )186 with mock.patch("allmydata.util.i2p_provider._import_i2p",187 return_value=None):188 i2p_provider = create_i2p_provider(reactor, config)189 h = i2p_provider.get_i2p_handler()190 self.assertEqual(h, None)191 def test_default(self):192 config = config_from_string("fake.port", "no-basedir", BASECONFIG)193 h1 = mock.Mock()194 with mock.patch("foolscap.connections.i2p.default",...

Full Screen

Full Screen

test_runner.py

Source:test_runner.py Github

copy

Full Screen

...52 nothing.53 """54 initializer = InitializerOrFinalizer('')55 initializer()56 def test_unimportable(self):57 """58 Given an unimportable module, an InitializerOrFinalizerError is raised.59 """60 initializer = InitializerOrFinalizer('garbagejunk.nonexistant')61 self.assertRaises(InitializerOrFinalizerError, initializer)62 def test_importable(self):63 """64 Given an actual importable module and function, the function is run.65 """66 global importable_function_worked67 importable_function_worked = False68 InitializerOrFinalizer('hma.test.test_runner._importableFunction')()69 self.assertTrue(importable_function_worked)70 def test_not_callable(self):...

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 green 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