def test_can_raise_timeouts(self): async_echo = Function('async_echo') async_echo.timeout = 0.2 self.assertRaises( FunctionTimeout, async_echo.call, )
def test_functions_validate_the_hosts_config(self): function = Function('test') function.host = spawn_managed_host(config_file=ConfigFiles.NO_FUNCTIONS, manager=manager) self.assertEqual(function.host.get_config()['functions'], []) self.assertRaises(ConfigError, function.send_request) function.host.get_config()['functions'].append({'name': 'test'})
def test_host_is_bound_lazily(self): function = Function(name='test') self.assertIsNone(function.host) self.assertEqual(function.get_host(), host) self.assertEqual(function.host, host)
def test_is_instantiated_properly(self): function = Function(name='foo') self.assertEqual(function.name, 'foo') self.assertEqual(function.host, None) self.assertEqual(function.timeout, None)
def setUpClass(cls): cls.echo = Function('echo') cls.echo_data = Function('echo_data') cls.async_echo = Function('async_echo') cls.error = Function('error')
import os from optional_django import six from js_host.function import Function import js_host.conf js_host.conf.settings.configure(USE_MANAGER=True) greet = Function('greet') double = Function('double') read_file = Function('read_file') if __name__ == '__main__': print('') if six.PY2: name = raw_input('Enter your name: ') else: name = input('Enter your name: ') print('Response: ' + greet.call(name=name) + '\n') number = input('Enter a number to double: ') if not six.PY2: number = int(number) print('Response: ' + double.call(number=number) + '\n') print('Asking the host to read the host.config.js file...\n') print('Response: ' +
""" return [asset['url'] for asset in self.get_assets() if asset['url']] def get_config(self): if self.stats: return self.stats.get('webpackConfig', None) def get_library(self): config = self.get_config() if config and 'output' in config: return config['output'].get('library', None) get_var = get_library # Convenience alias js_host_function = Function(settings.JS_HOST_FUNCTION) def webpack(config_file, watch_config=None, watch_source=None): if not settings.BUNDLE_ROOT: raise ImproperlyConfigured( 'webpack.conf.settings.BUNDLE_ROOT has not been defined.') if not settings.BUNDLE_URL: raise ImproperlyConfigured( 'webpack.conf.settings.BUNDLE_URL has not been defined.') if not os.path.isabs(config_file): abs_path = staticfiles.find(config_file) if not abs_path: raise ConfigFileNotFound(config_file)
import sys from optional_django import six from js_host.function import Function from js_host.exceptions import FunctionError js_host_function = Function('autoprefixer') class AutoprefixerError(Exception): pass def autoprefixer(css, is_file=None, options=None): if is_file: with open(css, 'r') as content_file: css = content_file.read() try: return js_host_function.call(css=css, options=options) except FunctionError as e: six.reraise(AutoprefixerError, AutoprefixerError(*e.args), sys.exc_info()[2])