def evaluate_many(self, expr_list): """ Evaluate a given list of Wolfram Language expressions. The list is provided as an iterable object. """ # for consistency with the async version, return a list. return list(map(self.evaluate, expr_list))
def handle(self, *args, **opts): suite = unittest.TestSuite() for root in map(module_path, self.modules): for arg in args or ["*"]: suite.addTests( unittest.defaultTestLoader.discover(root, pattern=arg, top_level_dir=root)) # verbosity > 1 print test name verbosity = opts.get("verbosity") # for consistency with parser, set default to 2. This is only possible when calling test from setup.py if verbosity is None: verbosity = 2 xml_path = opts.get("xml_output_dir") # if opts.get('produce_xml'): if xml_path is not None or opts.get("produce_xml"): import xmlrunner runner = xmlrunner.XMLTestRunner(output=xml_path or "test-reports", verbosity=verbosity) else: runner = unittest.TextTestRunner(verbosity=verbosity) result = runner.run(suite) if not result.wasSuccessful(): sys.exit(1)
def chain_normalizer(self, func, encoder): if isinstance(encoder, WolframDispatch): encoder.update_dispatch() return composition( *map(safe_import_string, iterate(func or (), partial(encoder.as_method(), self))))
def encode(serializer, o): if is_iterable(o): return serializer.serialize_iterable(map(serializer.encode, o), length=safe_len(o)) if serializer.allow_external_objects: return serializer.serialize_external_object(o) raise NotImplementedError('Cannot serialize object of class %s' % o.__class__)
def encode_ndarray(serializer, o): try: wl_type, handler = NUMPY_MAPPING[o.dtype.type] except KeyError: raise NotImplementedError( 'NumPy serialization not implemented for %s. Choices are: %s' % (repr(o.dtype), ', '.join(map(repr, NUMPY_MAPPING.keys())))) o = to_little_endian(o) if hasattr(o, 'tobytes'): #Numpy 1.9+ support array.tobytes, but previous versions don't and use tostring instead. data = o.tobytes() else: data = o.tostring() return serializer.serialize_numeric_array(data, o.shape, wl_type)
def encode_packed_array(serializer, o): try: wl_type, cast_to = PACKEDARRAY_NUMPY_MAPPING[o.dtype.type] except KeyError: raise NotImplementedError( "Packed array serialization not implemented for %s. Choices are: %s" % (repr(o.dtype), ", ".join( map(repr, PACKEDARRAY_NUMPY_MAPPING.keys())))) o = to_little_endian(o) if cast_to is not None: o = numpy.array(o, dtype=cast_to) if hasattr(o, "tobytes"): # Numpy 1.9+ support array.tobytes, but previous versions don't and use tostring instead. data = o.tobytes() else: data = o.tostring() return serializer.serialize_packed_array(data, o.shape, wl_type)
def handle(self, *args, **opts): suite = unittest.TestSuite() for root in map(module_path, self.modules): for arg in args or ['*']: suite.addTests( unittest.defaultTestLoader.discover( root, pattern=arg, top_level_dir=root)) # verbosity > 1 print test name verbosity = opts.get('verbosity') xml_path = opts.get('xml_output_dir') # if opts.get('produce_xml'): if xml_path is not None or opts.get('produce_xml'): import xmlrunner runner = xmlrunner.XMLTestRunner(output=xml_path or 'test-reports', verbosity=verbosity) else: runner = unittest.TextTestRunner(verbosity=verbosity) result = runner.run(suite) if not result.wasSuccessful(): sys.exit(1)
def encode_function(serializer, o): return serializer.serialize_function(serializer.encode(o.head), map(serializer.encode, o.args), length=len(o.args))
def encode_iter(serializer, o): return serializer.serialize_iterable(map(serializer.encode, o), length=safe_len(o))
def concatenate_bytes(iterable): return b"".join(map(six.binary_type, iterable))
async def evaluate_many(self, expr_list): return await asyncio.gather(*map(self.evaluate, expr_list), loop=self._loop)