Ë
    Ìi*!  ã                   óš  — d dl Z d dlZd dlZd dlmZmZmZ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mZ d dlmZmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZ d dlm Z m!Z!  ejD                  e#«      Z$de%de j                   fd„Z&dedeege'f   deee(f   fd„Z)dedeege'f   deee(f   fd„Z*defd„Z+defd„Z, e,«       ddfde%dededede%dee%   defd„Z-dd e,«       dddfde%dee%   dee   ded ee   d!ee   d"ee   defd#„Z.d$ee!   d%e%ddfd&„Z/d d g g fd'e d(e(d)e(d*ee%   d+ee%   ddfd,„Z0d'e d-e%ddfd.„Z1d'e d-e%ddfd/„Z2d'e ddfd0„Z3y)1é    N)ÚCallableÚOptionalÚSequenceÚTuple)ÚPydanticDimension)ÚPydanticEntity)ÚPydanticMeasure)ÚPydanticFileSliceÚPydanticMetadata)ÚPydanticMetricÚPydanticMetricTypeParams)ÚPydanticSemanticManifest©ÚPydanticNodeRelationÚPydanticSemanticModel)ÚYamlConfigFile)Ú
MetricType)Ú!SemanticManifestValidationResultsÚValidationIssueÚdate_stringÚreturnc                 ó@   — t         j                  j                  | «      S )zDHelper to convert a string like '2020-01-01' into a datetime object.)ÚdateutilÚparserÚparse)r   s    úc/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt_semantic_interfaces/test_utils.pyÚas_datetimer   $   s   € ä�?‰?× Ñ  Ó-Ð-ó    ÚmodelÚfunctionc                 ón   — t        | j                  «      D ]  \  }} ||«      sŒ||fc S  t        d«      ‚)ad  Returns a semantic model from the model which matches the criteria defined by the passed in function'.

    This is useful because the order of semantic models in the list is non determinant, thus it's impossible to
    hard code which semantic model you want by index. Using semantic model names isn't great for consistency because
    semantic models change and might no longer have the necessary parts to be useful for a given test. This
    allows us to guarantee that a semantic model will be returned which meets the requirements of what a test needs,
    unless none of the semantic models will work.
    z:Unable to find a semantic_model matching function criteria)Ú	enumerateÚsemantic_modelsÚ	Exception)r   r    ÚindexÚsemantic_models       r   Úfind_semantic_model_withr'   )   sD   € ô "+¨5×+@Ñ+@Ó!Aò )Ñˆˆ~Ù�NÕ#Ø! 5Ð(Ò(ð)ô ÐPÓ
QÐQr   c                 ón   — t        | j                  «      D ]  \  }} ||«      sŒ||fc S  t        d«      ‚)a,  Returns a metric from the model which matches the criteria defined by the passed in function'.

    This is useful because the order of metrics in the list is non-determinant, thus it's impossible to
    hard code which metric you want by index. Using metric names isn't great for consistency because
    metrics change and might no longer have the necessary parts to be useful for a given test. This
    allows us to guarantee that a metric will be returned which meets the requirements of what a test needs,
    unless none of the metrics will work.
    z2Unable to find a metric matching function criteria)r"   Úmetricsr$   )r   r    r%   Úmetrics       r   Úfind_metric_withr+   ;   s@   € ô # 5§=¡=Ó1ò !‰ˆˆvÙ�FÕØ˜5�=Ò ð!ô ÐHÓ
IÐIr   c                  óF   — t        j                  d«      } t        d| ¬«      S )zðReturns a YamlConfigFile with the inputs for a basic valid semantic manifest.

    This is useful to seed a simple error-free semantic manifest, which can easily be extended with YAML inputs
    containing specific validation triggers.
    ag          semantic_model:
          name: sample_semantic_model
          node_relation:
            schema_name: some_schema
            alias: source_table
          entities:
            - name: example_entity
              type: primary
              role: test_role
              expr: example_id
          measures:
            - name: num_sample_rows
              agg: sum
              agg_time_dimension: ds
              expr: 1
              create_metric: true
          dimensions:
            - name: ds
              type: time
              type_params:
                time_granularity: day
        Úinline_for_test)ÚfilepathÚcontents)ÚtextwrapÚdedentr   )Úyaml_contentss    r   Úbase_semantic_manifest_filer3   M   s'   € ô —O‘Oð	ó€Mô2 Ð#4¸}ÔMÐMr   c            	      ó6   — t        dt        dddd¬«      ¬«      S )z8Returns a Metadata object with the required information.z/not/from/a/repoznot_from_file.pyzN/Ar   )ÚfilenameÚcontentÚstart_line_numberÚend_line_number)Úrepo_file_pathÚ
file_slice)r   r
   © r   r   Údefault_metar<   o   s&   € äØ)Ü$Ø'ØØØô	
ôð r   zadhoc metricÚnameÚtypeÚtype_paramsÚmetadataÚdescriptionÚtime_granularityc           	      ó&   — t        | |||d||¬«      S )zyCreates a metric with the given input.

    If a metadata object is not supplied, a default metadata object is used.
    N)r=   rA   r>   r?   Úfilterr@   rB   )r   )r=   r>   r?   r@   rA   rB   s         r   Úmetric_with_guaranteed_metarE   |   s&   € ô ØØØØØØØ)ôð r   r;   Únode_relationÚentitiesÚmeasuresÚ
dimensionsc           	      óH   — |}|€t        dd¬«      }t        | ||||||¬«      S )z�Creates a semantic model with the given input.

    If a metadata object is not supplied, a default metadata object is used.
    ÚschemaÚtable)Úschema_nameÚalias)r=   rA   rF   rG   rH   rI   r@   r   )r=   rA   rF   r@   rG   rH   rI   Úcreated_node_relations           r   Ú#semantic_model_with_guaranteed_metarP   “   sE   € ð *ÐØÐ$Ü 4Ø Øô!
Ðô
 !ØØØ+ØØØØôð r   ÚissuesÚmessage_fragmentc                 óÄ   — t        | D �cg c]   }|j                  j                  |«      dk7  ‘Œ" c}«      }|| D �cg c]  }|j                  ‘Œ c}dœr|sJ ‚y c c}w c c}w )Néÿÿÿÿ)ÚexpectedÚactual_messages)ÚanyÚmessageÚfind)rQ   rR   ÚissueÚfound_matchs       r   Ú#_assert_expected_validation_messager\   ²   si   € ô ÈvÖVÀe�u—}‘}×)Ñ)Ð*:Ó;¸rÓAÒVÓW€Kð %Ø7=Ö>¨e˜EŸM›MÒ>òñ ðð ð ùò Wùò ?s
   Š%A»AÚresultsÚnum_expected_errorsÚnum_expected_warningsÚexpected_error_msgsÚexpected_warning_msgsc                 ó"  — t        | j                  «      |k(  sJ ‚t        | j                  «      |k(  sJ ‚t        | j                  «      dk(  sJ d«       ‚|D ]  }t	        | j                  |¬«       Œ |D ]  }t	        | j                  |¬«       Œ y)zÖValidates the number, type, and content of ValidationIssues.

    Currently assumes zero future_errors as there are no future_errors
    implemented, but this function can be expanded to cover those if needed.
    r   zAvalidation function expects zero future_errors to be implemented.)rQ   rR   N)ÚlenÚwarningsÚerrorsÚfuture_errorsr\   )r]   r^   r_   r`   ra   Úexpected_error_msgÚexpected_warning_msgs          r   Úcheck_expected_issuesri   ¾   s™   € ô ˆw×ÑÓ Ð$9Ò9Ð9Ð9Üˆw�~‰~ÓÐ"5Ò5Ð5Ð5Üˆw×$Ñ$Ó%¨Ò*ÐoÐ,oÓoÐ*à1ò hÐÜ+°7·>±>ÐTfÖgðhà 5ò lÐÜ+°7×3CÑ3CÐVjÖkñlr   Útarget_messagec                 ó"   — t        | d|g¬«       y )Né   )r]   r^   r`   ©ri   ©r]   rj   s     r   Ú!check_only_one_error_with_messagero   Ô   s   € ô ØØØ+Ð,ör   c                 ó"   — t        | d|g¬«       y )Nrl   )r]   r_   ra   rm   rn   s     r   Ú#check_only_one_warning_with_messagerq   Þ   s   € ô ØØØ-Ð.ör   c                 ó   — t        | ¬«       y )N©r]   rm   rs   s    r   Úcheck_no_errors_or_warningsrt   è   s   € äØör   )4ÚdatetimeÚloggingr0   Útypingr   r   r   r   Údateutil.parserr   Ú:dbt_semantic_interfaces.implementations.elements.dimensionr   Ú7dbt_semantic_interfaces.implementations.elements.entityr   Ú8dbt_semantic_interfaces.implementations.elements.measurer	   Ú0dbt_semantic_interfaces.implementations.metadatar
   r   Ú.dbt_semantic_interfaces.implementations.metricr   r   Ú9dbt_semantic_interfaces.implementations.semantic_manifestr   Ú6dbt_semantic_interfaces.implementations.semantic_modelr   r   Ú'dbt_semantic_interfaces.parsing.objectsr   Ú"dbt_semantic_interfaces.type_enumsr   Ú5dbt_semantic_interfaces.validations.validator_helpersr   r   Ú	getLoggerÚ__name__ÚloggerÚstrr   ÚboolÚintr'   r+   r3   r<   rE   rP   r\   ri   ro   rq   rt   r;   r   r   ú<module>r‰      s£  ðÛ Û Û ß 6Ó 6ã å XÝ RÝ T÷÷õ÷õ CÝ 9÷ð
 
ˆ×	Ñ	˜8Ó	$€ð.˜Sð . X×%6Ñ%6ó .ð
RØ#ðRØ/7Ð9NÐ8OÐQUÐ8UÑ/VðRà
Ð  #Ð%Ñ&óRð$JØ#ðJØ/7¸Ð8HÈ$Ð8NÑ/OðJà
ˆ>˜3ÐÑóJð$N ^ó NðD
Ð&ó 
ñ" ".£Ø%Ø&*ñØ
ðà
ðð *ðð ð	ð
 ðð ˜s‘mðð óð2 "&Ø48Ù!-£Ø)+Ø*,Ø.0ñØ
ðà˜#‘ðð Ð0Ñ1ðð ð	ð
 �~Ñ&ðð �Ñ'ðð Ð*Ñ+ðð óð>	Ø�_Ñ%ð	àð	ð 
ó	ð  !Ø!"Ø)+Ø+-ñlØ.ðlàðlð ðlð " #™ð	lð
 $ C™=ðlð 
ólð,Ø.ðØ@Cðà	óðØ.ðØ@Cðà	óðÐ)Jð Ètô r   