o
    }oi                     @   sr   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ dd Z	G dd	 d	eZ
G d
d de
ZG dd dZdS )    N)
DictConfig)EncDecCTCModel)SpectrogramAugmentation)Serializationc                 C   s   | j  d| j S )N.)
__module____name__)cls r
   Q/home/ubuntu/.local/lib/python3.10/site-packages/tests/core/test_serialization.pyget_class_path   s   r   c                   @   s   e Zd ZdefddZdS )MockSerializationImplcfgc                 C   s   || _ | jj| _d S )N)r   	__class__r   value)selfr   r
   r
   r   __init__   s   zMockSerializationImpl.__init__N)r   r   __qualname__r   r   r
   r
   r
   r   r      s    r   c                   @   s   e Zd ZdS )MockSerializationImplV2N)r   r   r   r
   r
   r
   r   r   !   s    r   c                   @   sl   e Zd Zejjdd Zejjdd Zejjdd Zejjdd Z	ejjd	d
 Z
ejjdd ZdS )TestSerializationc                 C   s4   t dddddd}tj|d}t|tsJ dS )	zHere we test that instantiation works for configs with cls class path in them.
        Note that just Serialization.from_config_dict can be used to create an object4nemo.collections.asr.modules.SpectrogramAugmentation2      x   	rect_freq
rect_masks	rect_timer	   paramsconfigN)r   r   from_config_dict
isinstancer   )r   r!   objr
   r
   r   test_from_config_dict_with_cls&   s   
z0TestSerialization.test_from_config_dict_with_clsc                 C   s   dt i d}dddddddgdgdgd	d
dddd
gdd}dddg ddd}tt|t|t|d}tj|d}t|tsFJ dS )zHere we test that instantiation works for configs without cls class path in them.
        IMPORTANT: in this case, correct class type should call from_config_dict. This should work for Models.z>nemo.collections.asr.modules.AudioToMelSpectrogramPreprocessorr   z+nemo.collections.asr.modules.ConvASREncoder@   reluTi      g        F)
filtersrepeatkernelstridedilationdropoutresidual	separablesese_context_size)feat_in
activation	conv_maskjasperz+nemo.collections.asr.modules.ConvASRDecoder   ) abcdefghijklmnopqrstuvwxyz')r4   num_classes
vocabulary)preprocessorencoderdecoderr    N)dictr   r   r"   r#   )r   rW   rX   rY   modelConfigr$   r
   r
   r   !test_from_config_dict_without_cls3   s<   %z3TestSerialization.test_from_config_dict_without_clsc                 C   s^   t dddddd}tj|d}| }||ksJ d|vs!J d	|vs'J d
|v s-J d S )Nr   r   r   r   r   r   r    r   r	   _target_)r   r   r"   to_config_dictr   r!   r$   
new_configr
   r
   r   test_config_updatedz   s   
z%TestSerialization.test_config_updatedc                 C   sP   t dtti}tj|d}| }||ksJ t|tsJ |jdks&J d S Ntargetr    r   )r   r   r   r   r"   r^   r#   r   r_   r
   r
   r   test_base_class_instantiation      z/TestSerialization.test_base_class_instantiationc                 C   sP   t dtti}tj|d}| }||ksJ t|tsJ |jdks&J d S )Nrc   r    r   )r   r   r   r"   r^   r#   r   r_   r
   r
   r   test_self_class_instantiation   re   z/TestSerialization.test_self_class_instantiationc                 C   sP   t dtti}tj|d}| }||ksJ t|tsJ |jdks&J d S rb   )r   r   r   r   r"   r^   r#   r   r_   r
   r
   r   test_sub_class_instantiation   re   z.TestSerialization.test_sub_class_instantiationN)r   r   r   pytestmarkunitr%   r\   ra   rd   rf   rg   r
   r
   r
   r   r   %   s    

F

	
	r   )rh   	omegaconfr   nemo.collections.asr.modelsr   nemo.collections.asr.modulesr   nemo.core.classes.commonr   r   r   r   r   r
   r
   r
   r   <module>   s   