a
    `6!                     @   s   d dl Z d dlmZmZmZ d dlZd dlZd dl	Z
G dd deZG dd deZG dd deZG d	d
 d
eZG dd deZG dd deZdS )    N)TestCaseSkipTestexpectedFailurec                   @   s&   e Zd Zdd Zd	ddZdd ZdS )
TestGeoc                 C   s   t jdkrtdz(dd l}dd l}dd l}dd lm} W n   tdY n0 dd l}dd l	}|
djdd| _|| jjdd | _d S )	Nwin32z!Skip geo tests on windows for nowr   z4xarray, rasterio, geoviews, or cartopy not availablezEhttps://github.com/mapbox/rasterio/raw/master/tests/data/RGB.byte.tif   )Zbandzepsg:)sysplatformr   Zxarrayrasteriogeoviewscartopy.crscrsZhvplot.xarrayhvplot.pandasZopen_rasterioZseldaZepsgsplit)selfZxrr
   r   ccrshvplot r   3lib/python3.9/site-packages/hvplot/tests/testgeo.pysetUp   s"    
zTestGeo.setUputmc                 C   s   |j jd |ksJ d S )Nproj)r   proj4_params)r   plotr   r   r   r   	assertCRS   s    zTestGeo.assertCRSc                 C   s,   t jd|d}|jd jd |ks(J d S )Nbokehr   
projectionr   )hvStorelookup_optionskwargsr   )r   r   r   optsr   r   r   assert_projection    s    zTestGeo.assert_projectionN)r   )__name__
__module____qualname__r   r   r#   r   r   r   r   r   
   s   
r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )TestCRSInferencec                    s$   t jdkrtdtt|   d S )Nr   zSkip CRS inference on Windows)r   r	   r   superr'   r   r   	__class__r   r   r   '   s    
zTestCRSInference.setUpc                 C   s&   | j jjdd| j jd}| | d S Nxyr   r   r   imager   r   r   r   r   r   r   !test_plot_with_crs_as_proj_string,   s    z2TestCRSInference.test_plot_with_crs_as_proj_stringc                 C   s"   | j jjdddd}| | d S Nr-   r.   Tgeo)r   r   r1   r   r2   r   r   r   (test_plot_with_geo_as_true_crs_undefined0   s    z9TestCRSInference.test_plot_with_geo_as_true_crs_undefined)r$   r%   r&   r   r3   r7   __classcell__r   r   r*   r   r'   %   s   r'   c                   @   sD   e Z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 )TestProjectionsc                 C   s$   | j jjdd| jd}| | d S r,   r0   r2   r   r   r   test_plot_with_crs_as_object7   s    z,TestProjections.test_plot_with_crs_as_objectc                 C   s6   | j  }d| ji|_|jjdddd}| | d S )Nbarr-   r.   r/   r   copyr   attrsr   r1   r   r   r   r   r   r   r   test_plot_with_crs_as_attr_str;   s    
z.TestProjections.test_plot_with_crs_as_attr_strc                 C   sD   |  td$ | jjjdddd W d    n1 s60    Y  d S )Nz'foo' must ber-   r.   foor/   ZassertRaisesRegex
ValueErrorr   r   r1   r)   r   r   r   *test_plot_with_crs_as_nonexistent_attr_strA   s    z:TestProjections.test_plot_with_crs_as_nonexistent_attr_strc                 C   s8   | j  }d| ji|_|jjdddd}| |d d S )Nr;   r-   r.   Tr5   Zeqcr<   r?   r   r   r   =test_plot_with_geo_as_true_crs_no_crs_on_data_returns_defaultE   s    
zMTestProjections.test_plot_with_geo_as_true_crs_no_crs_on_data_returns_defaultc                 C   s0   | j  }|jjdd| jdd}| |d d S )Nr-   r.   ZRobinsonr   r   Zrobinr   r=   r   r1   r   r#   r?   r   r   r   #test_plot_with_projection_as_stringK   s    
z3TestProjections.test_plot_with_projection_as_stringc                 C   s0   | j  }|jjdd| jdd}| |d d S )Nr-   r.   ZGOOGLE_MERCATORrF   ZmercrG   r?   r   r   r   3test_plot_with_projection_as_string_google_mercatorP   s    
zCTestProjections.test_plot_with_projection_as_string_google_mercatorc                 C   sD   |  td$ | jjjdddd W d    n1 s60    Y  d S )NzProjection must be definedr-   r.   rA   )r   rB   r)   r   r   r   +test_plot_with_projection_as_invalid_stringU   s    z;TestProjections.test_plot_with_projection_as_invalid_stringN)
r$   r%   r&   r:   r@   rD   rE   rH   rI   rJ   r   r   r   r   r9   5   s   r9   c                   @   sT   e Z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 )TestGeoAnnotationc                 C   sb   zdd l }dd lm} W n   tdY n0 dd l}| | _tjtj	
ddddgd| _d S Nr   z!geoviews or cartopy not available
      r-   r.   )columnsr   r   r   r   r   ZPlateCarreepdZ	DataFramenpZrandomZranddfr   r   r   r   r   r   r   r   \   s    
zTestGeoAnnotation.setUpc                 C   sJ   dd l }| jjjddddd}| t|d |d}| ||j d S )Nr   r-   r.   Tr6   	coastlinerN   r   	r   rS   r   pointsassertEquallengetassertIsInstanceZFeaturer   gvr   rV   r   r   r   test_plot_with_coastlinef   s
    
z*TestGeoAnnotation.test_plot_with_coastlinec                 C   sH   dd l }| jjjdddd}| t|d |d}| ||j d S )Nr   r-   r.   T)rV   rN   r   rW   r]   r   r   r   ,test_plot_with_coastline_sets_geo_by_defaultm   s
    
z>TestGeoAnnotation.test_plot_with_coastline_sets_geo_by_defaultc                 C   s>   | j jjddddd}|djd}| |jddi d S )	Nr-   r.   TZ10mrU   r   r   Zscale)rS   r   rX   r[   r"   rY   r!   )r   r   r"   r   r   r   test_plot_with_coastline_scalet   s    z0TestGeoAnnotation.test_plot_with_coastline_scalec                 C   sR   | j jjddddd}| t|d | |dtj | 	d|dj
 d S )Nr-   r.   Tr6   tilesrN   r   ZopenstreetmaprS   r   rX   rY   rZ   r\   r[   r   TilesassertIndatar2   r   r   r   test_plot_with_tilesy   s    z&TestGeoAnnotation.test_plot_with_tilesc                 C   sR   | j jjddddd}| t|d | |dtj | 	d|dj
 d S )	Nr-   r.   TZESRIrb   rN   r   ArcGISrd   r2   r   r   r   test_plot_with_specific_tiles   s    z/TestGeoAnnotation.test_plot_with_specific_tilesc                 C   sX   | j jjdddtjjjd}| t|d | 	|
dtj | d|
dj d S Nr-   r.   Trb   rN   r   ri   rS   r   rX   r   elementrc   ZEsriImageryrY   rZ   r\   r[   re   rf   rg   r2   r   r   r   "test_plot_with_specific_tile_class   s    z4TestGeoAnnotation.test_plot_with_specific_tile_classc                 C   sZ   | j jjdddtjj d}| t|d | 	|
dtj | d|
dj d S rk   rl   r2   r   r   r    test_plot_with_specific_tile_obj   s    z2TestGeoAnnotation.test_plot_with_specific_tile_objc                 C   sL   dd l }| jjjddd|jjd}| t|d | |	d|j
j d S )Nr   r-   r.   Trb   rN   )r   rS   r   rX   Ztile_sourcesZ	CartoDarkrY   rZ   r\   r[   rm   ZWMTS)r   r^   r   r   r   r   #test_plot_with_specific_gv_tile_obj   s    z5TestGeoAnnotation.test_plot_with_specific_gv_tile_objN)r$   r%   r&   r   r_   r`   ra   rh   rj   rn   ro   rp   r   r   r   r   rK   Z   s   
rK   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestGeoElementsc                 C   sb   zdd l }dd lm} W n   tdY n0 dd l}| | _tjtj	
ddddgd| _d S rL   rP   rT   r   r   r   r      s    
zTestGeoElements.setUpc                 C   s(   | j jjdddd}| |j| j d S r4   )rS   r   ZhexbinrY   r   )r   Zhextilesr   r   r   test_geo_hexbin   s    zTestGeoElements.test_geo_hexbinc                 C   s(   | j jjdddd}| |j| j d S r4   )rS   r   rX   rY   r   r   rX   r   r   r   test_geo_points   s    zTestGeoElements.test_geo_pointsc                 C   sN   | j jjdddd}tjd|dj}| |dd | |d	d  d S )
Nr-   r.   Tr5   r   r   data_aspectr   width	rS   r   rX   r   r   r    r!   rY   r[   r   rX   r"   r   r   r   test_geo_opts   s    zTestGeoElements.test_geo_optsc                 C   sb   | j jjddddd}tjd|dj}| |dd	 | |d
d | |dd  d S )Nr-   r.   T   )r6   rv   r   r   ru   r   rv   Zheightrw   rx   r   r   r   test_geo_opts_with_width   s
    z(TestGeoElements.test_geo_opts_with_widthN)r$   r%   r&   r   rr   rt   ry   r{   r   r   r   r   rq      s
   
rq   c                   @   sH   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Ze	dd Z
dS )TestGeoPandasc                 C   sV   z dd l }dd l}dd lm} W n   tdY n0 dd l}||jd| _	d S )Nr   z-geopandas, geoviews, or cartopy not availableZnaturalearth_cities)
Z	geopandasr   r   r   r   r   Z	read_fileZdatasetsZget_pathcities)r   Zgpdr   r   r   r   r   r   r      s    zTestGeoPandas.setUpc                 C   s.   | j  }|jddgksJ |jg ks*J d S )Nr-   r.   r}   r   kdimsvdimsrs   r   r   r   *test_points_hover_cols_is_empty_by_default   s    
z8TestGeoPandas.test_points_hover_cols_is_empty_by_defaultc                 C   s:   | j jdddd}|jddgks$J |jddgks6J d S )Nr-   r.   all)r-   r.   
hover_colsindexnamer~   rs   r   r   r   9test_points_hover_cols_does_not_include_geometry_when_all   s    zGTestGeoPandas.test_points_hover_cols_does_not_include_geometry_when_allc                 C   s8   | j jdddd}|jddgks$J |jdgks4J d S )Nr-   r   F)r-   r   Z	use_indexr.   r   r~   rs   r   r   r   8test_points_hover_cols_when_all_and_use_columns_is_false   s    zFTestGeoPandas.test_points_hover_cols_when_all_and_use_columns_is_falsec                 C   s8   | j jddgd}|jddgks$J |jdgks4J d S )Nr.   r   )r.   r   r-   r~   rs   r   r   r   $test_points_hover_cols_index_in_list   s    z2TestGeoPandas.test_points_hover_cols_index_in_listc                 C   sV   | j jdd}|jddgks J |jdgks0J tjd|dj}|d dksRJ d S )Nr   )cr-   r.   r   ZstyleZcolor)r}   r   r   r   r   r   r    r!   rx   r   r   r   )test_points_hover_cols_with_c_set_to_name   s
    z7TestGeoPandas.test_points_hover_cols_with_c_set_to_namec                 C   s4   | j jdd}|jddgks J |jdgks0J d S )Nr   )Zbyr-   r.   r~   rs   r   r   r   *test_points_hover_cols_with_by_set_to_name   s    z8TestGeoPandas.test_points_hover_cols_with_by_set_to_nameN)r$   r%   r&   r   r   r   r   r   r   r   r   r   r   r   r   r|      s   r|   )r   Zunittestr   r   r   ZnumpyrR   ZpandasrQ   Z	holoviewsr   r   r'   r9   rK   rq   r|   r   r   r   r   <module>   s   %>"