def test_blank_list(self): # Blank list to start with l = [] utils.multiple_insert(l, [1, 2, 3]) self.assertSequenceEqual(l, [3, 2, 1])
def test_blank_addition(self): # Blank list to start with l = [1, 2, 3] utils.multiple_insert(l, []) self.assertSequenceEqual(l, [1, 2, 3])
def test_standard_usage(self): # Standard usage l = ['a', 'b', 'c'] utils.multiple_insert(l, ['second', 'first']) self.assertSequenceEqual(l, ['first', 'second', 'a', 'b', 'c'])
class PatchSKImage(PatchSimple): modulename = 'skimage' input_functions = ['io.imread', 'io.load_sift', 'io.load_surf', 'external.tifffile.imread'] output_functions = ['io.imsave', 'external.tifffile.imsave'] input_wrapper = create_wrapper(log_input, 0, 'sklearn') output_wrapper = create_wrapper(log_output, 0, 'sklearn') class PatchPillow(PatchSimple): modulename = 'skimage' input_functions = ['Image.open'] output_functions = ['Image.save'] input_wrapper = create_wrapper(log_input, 0, 'Pillow') output_wrapper = create_wrapper(log_output, 0, 'Pillow') class PatchNIBabel(PatchSimple): modulename = 'nibabel' images = ['nifti1.Nifti1Image', 'nifti2.Nifti2Image', 'freesurfer.mghformat.MGHImage', 'spm99analyze.Spm99AnalyzeImage', 'minc1.Minc1Image', 'minc2.Minc2Image', 'analyze.AnalyzeImage', 'parrec.PARRECImage', 'spm2analyze.Spm2AnalyzeImage'] input_functions = [image_name + '.from_filename' for image_name in images] output_functions = [image_name + '.to_filename' for image_name in images] input_wrapper = create_wrapper(log_input, 0, 'nibabel') output_wrapper = create_wrapper(log_output, 0, 'nibabel') multiple_insert(sys.meta_path, [PatchGDAL(), PatchSKLearn(), PatchSKImage(), PatchPillow(), PatchNIBabel()])
add_module_to_db(modulename, input_functions, output_functions) class PatchLXML(PatchSimple): modulename = 'lxml.etree' input_functions = ['parse', 'iterparse'] output_functions = [] input_wrapper = create_wrapper(log_input, 0, 'lxml') output_wrapper = create_wrapper(log_output, 0, 'lxml') add_module_to_db(modulename, input_functions, output_functions) class PatchBS4(PatchSimple): modulename = 'bs4' input_functions = ['BeautifulSoup'] output_functions = [] input_wrapper = create_wrapper(log_input, 0, 'bs4') output_wrapper = create_wrapper(log_output, 0, 'bs4') add_module_to_db(modulename, input_functions, output_functions) multiple_insert(sys.meta_path, [PatchNumpy(), PatchPandas(), PatchMPL(), PatchBS4(), PatchLXML()])
input_functions = ['Image.open'] output_functions = ['Image.save'] input_wrapper = create_wrapper(log_input, 0, 'Pillow') output_wrapper = create_wrapper(log_output, 0, 'Pillow') class PatchNIBabel(PatchSimple): modulename = 'nibabel' images = [ 'nifti1.Nifti1Image', 'nifti2.Nifti2Image', 'freesurfer.mghformat.MGHImage', 'spm99analyze.Spm99AnalyzeImage', 'minc1.Minc1Image', 'minc2.Minc2Image', 'analyze.AnalyzeImage', 'parrec.PARRECImage', 'spm2analyze.Spm2AnalyzeImage' ] input_functions = [image_name + '.from_filename' for image_name in images] output_functions = [image_name + '.to_filename' for image_name in images] input_wrapper = create_wrapper(log_input, 0, 'nibabel') output_wrapper = create_wrapper(log_output, 0, 'nibabel') multiple_insert(sys.meta_path, [ PatchGDAL(), PatchSKLearn(), PatchSKImage(), PatchPillow(), PatchNIBabel() ])
input_functions = [image_name + '.from_filename' for image_name in images] output_functions = [image_name + '.to_filename' for image_name in images] input_wrapper = create_wrapper(log_input, 0, 'nibabel') output_wrapper = create_wrapper(log_output, 0, 'nibabel') add_module_to_db(modulename, input_functions, output_functions) class PatchTifffile(PatchSimple): modulename = 'tifffile' input_functions = ['imread'] output_functions = ['imsave'] input_wrapper = create_wrapper(log_input, 0, 'tifffile') output_wrapper = create_wrapper(log_output, 0, 'tifffile') class PatchImageio(PatchSimple): modulename = 'imageio' input_functions = ['core.functions.get_reader', 'core.functions.read'] output_functions = ['core.functions.get_writer'] input_wrapper = create_wrapper(log_input, 0, 'imageio') output_wrapper = create_wrapper(log_output, 0, 'imageio') multiple_insert(sys.meta_path, [PatchGDAL(), PatchSKLearn(), PatchNIBabel(), PatchTifffile(), PatchImageio()])
# The `load` function is *deliberately* not included here # as it calls fromfile internally, and then we get two duplicate # entries recorded in the log input_functions = ['genfromtxt', 'loadtxt', 'fromfile'] output_functions = ['save', 'savez', 'savez_compressed', 'savetxt'] input_wrapper = create_wrapper(log_input, 0, 'numpy') output_wrapper = create_wrapper(log_output, 0, 'numpy') class PatchLXML(PatchSimple): modulename = 'lxml.etree' input_functions = ['parse', 'iterparse'] output_functions = [] input_wrapper = create_wrapper(log_input, 0, 'lxml') output_wrapper = create_wrapper(log_output, 0, 'lxml') class PatchBS4(PatchSimple): modulename = 'bs4' input_functions = ['BeautifulSoup'] output_functions = [] input_wrapper = create_wrapper(log_input, 0, 'bs4') output_wrapper = create_wrapper(log_output, 0, 'bs4') multiple_insert(sys.meta_path, [PatchNumpy(), PatchPandas(), PatchMPL(), PatchBS4(), PatchLXML()])
import sys from .PatchImporter import PatchImporter from .PatchSimple import PatchSimple from .PatchMultipleWrappers import PatchMultipleWrappers, WrapperList from .log import log_input, log_output, add_module_to_db from recipyCommon.utils import create_wrapper, multiple_insert class PatchKeras(PatchMultipleWrappers): modulename = 'keras' wrappers = WrapperList() input_functions = ['Model.load_weights', 'models.load_model'] input_functions += ['preprocessing.image.ImageDataGenerator.flow_from_directory'] output_functions = ['Model.save_weights', 'Model.save'] wrappers.add_inputs(input_functions, log_input, 0, modulename) wrappers.add_outputs(output_functions, log_output, 0, modulename) wrappers.add_outputs('utils.plot_model', log_output, 1, modulename) add_module_to_db(modulename, input_functions, output_functions) multiple_insert(sys.meta_path, [PatchKeras()])
def test_standard_usage(self): # Standard usage l = ["a", "b", "c"] utils.multiple_insert(l, ["second", "first"]) self.assertSequenceEqual(l, ["first", "second", "a", "b", "c"])
modulename = 'nibabel' images = ['nifti1.Nifti1Image', 'nifti2.Nifti2Image', 'freesurfer.mghformat.MGHImage', 'spm99analyze.Spm99AnalyzeImage', 'minc1.Minc1Image', 'minc2.Minc2Image', 'analyze.AnalyzeImage', 'parrec.PARRECImage', 'spm2analyze.Spm2AnalyzeImage'] input_functions = [image_name + '.from_filename' for image_name in images] output_functions = [image_name + '.to_filename' for image_name in images] input_wrapper = create_wrapper(log_input, 0, 'nibabel') output_wrapper = create_wrapper(log_output, 0, 'nibabel') class PatchTifffile(PatchSimple): modulename = 'tifffile' input_functions = ['imread'] output_functions = ['imsave'] input_wrapper = create_wrapper(log_input, 0, 'tifffile') output_wrapper = create_wrapper(log_output, 0, 'tifffile') class PatchImageio(PatchSimple): modulename = 'imageio' input_functions = ['core.functions.get_reader', 'core.functions.read'] output_functions = ['core.functions.get_writer'] input_wrapper = create_wrapper(log_input, 0, 'imageio') output_wrapper = create_wrapper(log_output, 0, 'imageio') multiple_insert(sys.meta_path, [PatchGDAL(), PatchSKLearn(), PatchNIBabel(), PatchTifffile(), PatchImageio()])