o
    :ήc                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZmZmZ dd Zd	d
 Zdd ZG dd dZdS )    N)data_dir)ImageCollection
MultiImagealphanumeric_key)reset_plugins)testing)assert_equalassert_allclosefetchc                  C   s   d} g d}t t| | d S )Nz23a)z   a)r   r   )test_stringtest_str_result r   G/tmp/pip-target-vg8gfxp4/lib/python/skimage/io/tests/test_collection.pytest_string_split   s   r   c                  C   s*   g d} g d}t | td}t|| d S )N)	f9.10.pngf9.9.png
f10.10.png	f10.9.pnge9.pnge10.pngem.png)r   r   r   r   r   r   r   )key)sortedr   r   )	filenamesexpected_filenamessorted_filenamesr   r   r   test_string_sort   s   r    c                  C   s*   dd dD } t | }t|dksJ dS )zTest function for ImageCollection. The new behavior (implemented
    in 0.16) allows the `pattern` argument to accept a list of strings
    as the input.

    Notes
    -----
        If correct, `images` will receive three images.
    c                 S      g | ]	}t jt|qS r   ospathjoinr   .0picr   r   r   
<listcomp>'       z.test_imagecollection_input.<locals>.<listcomp>)z
coffee.pngzchessboard_GRAY.pngz
rocket.jpg   N)r   len)patternimagesr   r   r   test_imagecollection_input   s
   r/   c                   @   sx   e Zd Zdd dD Zdd dD Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )TestImageCollectionc                 C   r!   r   r"   r&   r   r   r   r)   0   r*   zTestImageCollection.<listcomp>)	brick.pngz	color.pngc                 C   r!   r   r"   r&   r   r   r   r)   3   r*   )r1   zmoon.pngc                 C   s.   t   t| j| _t| j| _t| j| _d S N)r   r   r-   r.   pattern_matchedimages_matchedr   frames_matchedselfr   r   r   setup_method6   s   z TestImageCollection.setup_methodc                 C   s   t | jdks	J d S )N   )r,   r.   r6   r   r   r   test_len?   s   zTestImageCollection.test_lenc                    s   t  j}t| |D ]}t j| tjsJ qt jd  j|    fdd}tt	 || W d    n1 s?w   Y  tt	 || d  W d    d S 1 s\w   Y  d S )Nr   c                    s
    j |  S r2   )r.   )nr6   r   r   
return_imgI   s   
z4TestImageCollection.test_getitem.<locals>.return_img   )
r,   r.   range
isinstancenpndarrayr	   r   raises
IndexError)r7   numir<   r   r6   r   test_getitemB   s   



"z TestImageCollection.test_getitemc                 C   s   t | jd d  tu sJ t| jd d  dksJ t| jd d dks'J t| jdd  dks4J t| jd | jd d d  t| jd | jdd  d  t| jd | jd d d d  t| jd | jd d d d  d S )Nr9   r=   r   )typer.   r   r,   r	   r6   r   r   r   test_slicingP   s    $z TestImageCollection.test_slicingc                    sV   t  jjts	J  fdd}tt |d W d    d S 1 s$w   Y  d S )Nc                    s   |  j _d S r2   )r.   files)fr6   r   r   	set_files]   s   z:TestImageCollection.test_files_property.<locals>.set_filesnewfiles)r?   r.   rJ   listr   rB   AttributeError)r7   rL   r   r6   r   test_files_propertyZ   s
   
"z'TestImageCollection.test_files_propertyc                 C   sF   t d}dd }t||dd}t|dksJ t|d dks!J d S )	Nzdata/no_time_for_that_tiny.gifc                 S   s*   t | }dd | D }|d d | S )Nc                 S   s   g | ]}|qS r   r   )r'   vr   r   r   r)   g   s    zVTestImageCollection.test_custom_load_func_w_kwarg.<locals>.load_fn.<locals>.<listcomp>)imageio
get_reader	iter_data)rK   stepvidseqr   r   r   load_fne   s   
zBTestImageCollection.test_custom_load_func_w_kwarg.<locals>.load_fnr+   )	load_funcrU   r=   r      )r
   r   r,   )r7   load_patternrX   icr   r   r   test_custom_load_func_w_kwargb   s
   z1TestImageCollection.test_custom_load_func_w_kwargc                 C   s6   dd }t tj| j|d}t|d | jd  d S )Nc                 S   s   | S r2   r   )xr   r   r   rX   r   s   z:TestImageCollection.test_custom_load_func.<locals>.load_fn)rY   r   )r   r#   pathsepr%   r-   r   )r7   rX   r\   r   r   r   test_custom_load_funcp   s   z)TestImageCollection.test_custom_load_funcc                 C   s2   | j  }t| j f| jd j }t|j| d S )Nr   )r4   concatenater,   r.   shaper   )r7   arrayexpected_shaper   r   r   test_concatenatex   s   
z$TestImageCollection.test_concatenatec                 C   s:   t t | j  W d    d S 1 sw   Y  d S r2   )r   rB   
ValueErrorr.   ra   r6   r   r   r   (test_concatenate_mismatched_image_shapes}   s   "z<TestImageCollection.test_concatenate_mismatched_image_shapesc                 C   s0   t | jd | jd  t | jd | jd  d S )Nr   r=   )r   r4   r5   r6   r   r   r   test_multiimage_imagecollection   s   z3TestImageCollection.test_multiimage_imagecollectionN)__name__
__module____qualname__r-   r3   r8   r:   rF   rI   rP   r]   r`   re   rg   rh   r   r   r   r   r0   /   s"    	
r0   )r#   numpyr@   rR   skimager   skimage.io.collectionr   r   r   
skimage.ior   skimage._sharedr   skimage._shared.testingr   r	   r
   r   r    r/   r0   r   r   r   r   <module>   s    