def test_load_extension(self): sys.modules['ipython_environment'] = MockIpythonEnvironment load_ipython_extension(None) self.assertEqual(MockIpythonEnvironment.environment, Environment.current_env()) unload_ipython_extension(None) with self.assertRaises(NoEnvironment): Environment.current_env() sys.modules['ipython_environment'] = None
def test_context_manager(self): e = Environment() with e: self.assertIs(Environment.current_env(), e) with self.assertRaises(NoEnvironment): Environment.current_env()