
    Wpf              	           d Z ddlZddlZddlmZ 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l
mZ ej        Zej        Zej        Zd	Zd
 ZdedefdZ	 	 ddedededefdZ	 ddZd ZdS )zTest util for MediaPipe Tasks.    N)flags)
descriptordescriptor_pool)text_format)image)image_frame   c                      dt           j        v rt           j        d         j        S dt          j        v rt          j        d         S t          d          )z3Returns the path where to look for test data files.test_srcdirTEST_SRCDIRz Missing TEST_SRCDIR environment.)r   FLAGSvalueosenvironRuntimeError     f/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/mediapipe/tasks/python/test/test_utils.pyr   r   "   sH    ek!!;}%++
"":m$$
9
:
::r   file_or_dirname_pathreturnc                    t          j        d          D ]I\  }}}||z   D ]=}t           j                            ||          }|                    |           r|c c S >Jt          d| dt                      d          )zReturns full test data path.z/tmp/root/sources/mediapipezNo z in test directory: .)r   walkpathjoinendswith
ValueErrorr   )r   	directorysubdirsfilesfr   s         r   get_test_data_pathr#   ,   s    #%7+H#I#I  i%u_  W\\)Q''d	+	,	,  	
(<(<(<kmmmmL	 	 r   score_calibration.txt1.0,2.0,3.0,4.0file_dir	file_namecontentc                     t           j                            | |          }t          |d          5 }|                    |           ddd           n# 1 swxY w Y   |S )zCreates the calibration file.w)modeN)r   r   r   openwrite)r&   r'   r(   calibration_filefiles        r   create_calibration_filer0   8   s     W\\(I663''' 4JJw              	s   AAATc                    t          j                    }t          |t          j                  r)t          j        ||                                |          }||fD ]F}|r1|                                }|r| 	                    d|d|           |rt          |           Gt          j        ||          }	t          j        ||          }
t          |	          dk     r-t          |
          dk     r|                     |	|
|           d	S d                    t          j        |	                    d          |
                    d                              }|r| 	                    |d|           d	S d	S )
a  assert_proto_equals() is useful for unit tests.

  It produces much more helpful output than assertEqual() for proto2 messages.
  Fails with a useful error if a and b aren't equal. Comparison of repeated
  fields matches the semantics of unittest.TestCase.assertEqual(), ie order and
  extra duplicates fields matter.

  This is a fork of https://github.com/tensorflow/tensorflow/blob/
  master/tensorflow/python/util/protobuf/compare.py#L73. We use slightly
  different rounding cutoffs to support Mac usage.

  Args:
    self: absltest.testing.parameterized.TestCase
    a: proto2 PB instance, or text string representing one.
    b: proto2 PB instance -- message.Message or subclass thereof.
    check_initialized: boolean, whether to fail if either a or b isn't
      initialized.
    normalize_numbers: boolean, whether to normalize types and precision of
      numbers before comparison.
    msg: if specified, is used as the error message on failure.
  r   zInitialization errors: 
i   )msg Tz :
N)r   Default
isinstancesixstring_typesr   Parse	__class__FindInitializationErrorsfail_normalize_number_fieldsMessageToStringlenassertMultiLineEqualr   difflibunified_diff
splitlines)selfabcheck_initializednormalize_numbersr3   poolpberrorsa_strb_strdiffs               r   assert_proto_equalsrO   D   s   0 
	 	"	"$3#$$ B!Q[[]]DAAAAqD # #b B**,,f	 B			VVVRR@AAA #r"""

%a
>
>
>%

%a
>
>
>% 	ZZ%CJJ..eU4444477U--d33U5E5Ed5K5KLL D  *
iiccc44()))))* *r   c                    |                                  D ]S\  }}d}|j        t          j        j        k    rd}|g}d}|j        t          j        j        t          j        j        t          j        j        fv rd |D             }n|j        t          j        j	        t          j        j
        t          j        j        t          j        j        fv rd |D             }nM|j        t          j        j        k    rd |D             }n&|j        t          j        j        k    rd |D             }|a|rC|                     |j                   t#          | |j                                      |           nt'          | |j        |d                    |j        t          j        j        k    s|j        t          j        j        k    r|j        t          j        j        k    r||j        j        rp|j                                        j        rR|j        j        d	         j        t          j        j        k    r&t7          j        |          D ]}t;          |           ?|D ]}t;          |           U| S )
a  Normalizes types and precisions of number fields in a protocol buffer.

  Due to subtleties in the python protocol buffer implementation, it is possible
  for values to have different types and precision depending on whether they
  were set and retrieved directly or deserialized from a protobuf. This function
  normalizes integer values to ints and longs based on width, 32-bit floats to
  five digits of precision to account for python always storing them as 64-bit,
  and ensures doubles are floating point for when they're set to integers.
  Modifies pb in place. Recurses into nested objects. https://github.com/tensorf
  low/tensorflow/blob/master/tensorflow/python/util/protobuf/compare.py#L118

  Args:
    pb: proto2 message.

  Returns:
    the given pb, modified in place.
  TFNc                 ,    g | ]}t          |          S r   int.0xs     r   
<listcomp>z,_normalize_number_fields.<locals>.<listcomp>       222a3q66222r   c                 ,    g | ]}t          |          S r   rR   rT   s     r   rW   z,_normalize_number_fields.<locals>.<listcomp>   rX   r   c                 .    g | ]}t          |d           S )   )roundrT   s     r   rW   z,_normalize_number_fields.<locals>.<listcomp>   s     77715A;;777r   c                 H    g | ]}t          t          |          d            S )   )r\   floatrT   s     r   rW   z,_normalize_number_fields.<locals>.<listcomp>   s(    >>>!5q1-->>>r   r      )
ListFieldslabelr   FieldDescriptorLABEL_REPEATEDtype
TYPE_INT64TYPE_UINT64TYPE_SINT64
TYPE_INT32TYPE_UINT32TYPE_SINT32	TYPE_ENUM
TYPE_FLOATTYPE_DOUBLE
ClearFieldnamegetattrextendsetattrTYPE_MESSAGE
TYPE_GROUPmessage_typehas_options
GetOptions	map_entryfields_by_numberr7   
itervaluesr=   )rJ   descvaluesis_repeatednormalized_valuesvs         r   r=   r=   y   ss   $ mmoo 7& 7&ldFKzZ/>>>kxf
 y"-".".  
 326222	"-".".",	 
 
 326222	j0;	;	;77777	j0<	<	<>>v>>>$	 5
di   DI%%&78888DI03444 		Z/<<<9
2=== )z1>
>
>+ ?**,,6 ? .q16)67 7 >&)) ( (a$Q'''' 	& 	&A
"1
%
%
%
%	)r   )r$   r%   )TTN)__doc__rA   r   abslr   r7   google.protobufr   r   r   $mediapipe.python._framework_bindingsr   image_moduler	   image_frame_moduler   Image_ImageImageFormat_ImageFormat_RGB_CHANNELSr   strr#   r0   rO   r=   r   r   r   <module>r      s`   % $  				       



 & & & & & & + + + + + + ' ' ' ' ' ' F F F F F F R R R R R R		!-; ; ;	S 	S 	 	 	 	 -$	 			 	 			 	 	 	 EI2* 2* 2* 2*jK K K K Kr   