o
    v&iN2                     @  s:  U 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 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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ddG dd dZeeef Zded< d=ddZd>ddZd?d$d%Zd@d'd(Z dAd+d,Z!dBd/d0Z"d1Z#dCd7d8Z$dDd;d<Z%dS )E    )annotations)Iterable)Sequence)	dataclass)KW_ONLYN)Path)Literal)	TypeAlias   )
UsageError)failabsolutepath)
commonpathsafe_existsT)frozenc                   @  s2   e Zd ZU dZded< ded< ded< ded	< d
S )ConfigValuea8  Represents a configuration value with its origin and parsing mode.

    This allows tracking whether a value came from a configuration file
    or from a CLI override (--override-ini), which is important for
    determining precedence when dealing with ini option aliases.

    The mode tracks the parsing mode/data model used for the value:
    - "ini": from INI files or [tool.pytest.ini_options], where the only
      supported value types are `str` or `list[str]`.
    - "toml": from TOML files (not in INI mode), where native TOML types
       are preserved.
    objectvaluer   _zLiteral['file', 'override']originzLiteral['ini', 'toml']modeN)__name__
__module____qualname____doc____annotations__ r   r   ^/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/config/findpaths.pyr      s   
 r   r	   
ConfigDictpathr   returniniconfig.IniConfigc              
   C  s:   zt t| W S  t jy } ztt||d}~ww )zParse the given generic '.ini' file using legacy IniConfig parser, returning
    the parsed object.

    Raise UsageError if the file cannot be parsed.
    N)	iniconfig	IniConfigstr
ParseErrorr   )r!   excr   r   r   _parse_ini_config.   s   r)   filepathConfigDict | Nonec           
   
     s  | j dkr!t| }d|v rdd |d  D S | jdv ri S dS | j dkrKt| }d|jv r:dd |d  D S d|jv rIttjd	d
dd dS | j dkrtj	dkrZddl
}nddl}| jdd}z||}W n |jy } z
t|  d| |d}~ww | jdv r|di }|rdd | D S i S |di di }dd | D }|dd}	|r|	rt|  d|rdd | D S |	durd"dd   fd!d|	 D S dS )#zLoad pytest configuration from the given file path, if supported.

    Return None if the file does not contain valid pytest configuration.
    z.inipytestc                 S      i | ]\}}|t |d ddqS fileinir   r   r   .0kvr   r   r   
<dictcomp>F       z.load_config_dict_from_file.<locals>.<dictcomp>>   
pytest.ini.pytest.iniz.cfgztool:pytestc                 S  r-   r.   r2   r3   r   r   r   r7   T   r8   	setup.cfg)filenameF)pytracez.toml)      r   Nzutf-8)encodingz: )pytest.toml.pytest.tomlc                 S  r-   r/   tomlr1   r2   r3   r   r   r   r7   q   r8   toolc                 S  s   i | ]\}}|d kr||qS )ini_optionsr   r3   r   r   r   r7   }       rF   z: Cannot use both [tool.pytest] (native TOML types) and [tool.pytest.ini_options] (string-based INI format) simultaneously. Please use [tool.pytest] with native TOML types (recommended) or [tool.pytest.ini_options] for backwards compatibility.c                 S  r-   rC   r2   r3   r   r   r   r7      r8   r6   r   r"   str | list[str]c                 S  s   t | tr| S t| S N)
isinstancelistr&   )r6   r   r   r   make_scalar   s   z/load_config_dict_from_file.<locals>.make_scalarc                   s$   i | ]\}}|t  |d ddqS r.   r2   r3   rL   r   r   r7      s    )r6   r   r"   rH   )suffixr)   itemsnamesectionsr   CFG_PYTEST_SECTIONformatsysversion_infotomllibtomli	read_textloadsTOMLDecodeErrorr   get)
r*   r$   rV   	toml_textconfigr(   pytest_configtool_pytesttoml_config
ini_configr   rM   r   load_config_dict_from_file:   sj   


N



@





rb   invocation_dirargsIterable[Path]:tuple[Path | None, Path | None, ConfigDict, Sequence[str]]c                 C  s  g d}dd |D }|s| g}d}g }|D ]_}t |}|g|jR D ]Q}|D ]L}|| }	|	 rs|	jdkr<|du r<|	}t|	}
|
durs||}||d d D ]}|| }| rft|durf|| qQ||	|
|f      S q'q#q|dur|j|i g fS ddi g fS )a	  Search in the list of arguments for a valid ini-file for pytest,
    and return a tuple of (rootdir, inifile, cfg-dict, ignored-config-files), where
    ignored-config-files is a list of config basenames found that contain
    pytest configuration but were ignored.)rA   rB   r9   r:   pyproject.tomlztox.inir;   c                 S  s   g | ]}t |d s|qS )-)r&   
startswith)r4   xr   r   r   
<listcomp>   rG   z!locate_config.<locals>.<listcomp>Nrg   r
   )r   parentsis_filerP   rb   indexappendparent)rc   rd   config_namesfound_pyproject_tomlignored_config_filesargargpathbaseconfig_namepra   rn   	remainderp2r   r   r   locate_config   s>   	

r{   pathsc                 C  s   d }|D ]+}|  sq|d u r|}q||jv s||krq||jv r$|}qt||}|d ur/|}q|d u r8| }|S | r?|j}|S rI   )existsrl   r   rm   rp   )rc   r|   common_ancestorr!   sharedr   r   r   get_common_ancestor   s(   

r   Iterable[str]
list[Path]c                   sD   ddddddddd fdd| D } fdd|D S )Nrj   r&   r"   boolc                 S  s
   |  dS )Nrh   )ri   rj   r   r   r   	is_option   s   
z%get_dirs_from_args.<locals>.is_optionc                 S  s   |  dd S )Nz::r   )splitr   r   r   r   get_file_part_from_node_id   s   z6get_dirs_from_args.<locals>.get_file_part_from_node_idr!   r   c                 S  s   |   r| S | jS rI   )is_dirrp   )r!   r   r   r   get_dir_from_path   s   z-get_dirs_from_args.<locals>.get_dir_from_pathc                 3  s$    | ]}|st  |V  qd S rI   r   )r4   rt   )r   r   r   r   	<genexpr>   s    

z%get_dirs_from_args.<locals>.<genexpr>c                   s   g | ]
}t |r |qS r   r   )r4   r!   )r   r   r   rk      s    z&get_dirs_from_args.<locals>.<listcomp>)rj   r&   r"   r   )rj   r&   r"   r&   )r!   r   r"   r   r   )rd   possible_pathsr   )r   r   r   r   get_dirs_from_args   s   


r   override_iniSequence[str] | Nonec                 C  sh   i }| pdD ]+}z
| dd\}}W n ty' } z	td|d|d}~ww t|ddd	||< q|S )
zParse the -o/--override-ini command line arguments and return the overrides.

    :raises UsageError:
        If one of the values is malformed.
    r   =r
   z3-o/--override-ini expects option=value style (got: z).Noverrider0   r1   )r   
ValueErrorr   r   )r   	overridesra   keyuser_ini_valueer   r   r   parse_override_ini   s   
r   z][pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead.inifile
str | NoneSequence[str]rootdir_cmd_arg3tuple[Path, Path | None, ConfigDict, Sequence[str]]c                 C  s&  d}t |}g }| rt| }|}	t|pi }
|du r|j}nJt||}t||g\}}	}
}|du rh|du rh|g|jR D ]}|d  rH|} n q<||gkrWt||\}}	}
}|du rht|||g}t|rh|}|r~tt	j
|}| s~td| dt|}|
| |dusJ ||	|
|fS )a  Determine the rootdir, inifile and ini configuration values from the
    command line arguments.

    :param inifile:
        The `--inifile` command line argument, if given.
    :param override_ini:
        The -o/--override-ini command line arguments, if given.
    :param args:
        The free command line arguments.
    :param rootdir_cmd_arg:
        The `--rootdir` command line argument, if given.
    :param invocation_dir:
        The working directory when pytest was invoked.

    :raises UsageError:
    Nzsetup.pyzDirectory 'z+' not found. Check your '--rootdir' option.)r   r   rb   rp   r   r{   rl   rm   
is_fs_rootosr!   
expandvarsr   r   r   update)r   r   rd   r   rc   rootdirdirsrs   inipath_inipathinicfgancestorpossible_rootdirr   ini_overridesr   r   r   determine_setup  sL   



r   rx   r   c                 C  s   t jt| d t jkS )z
    Return True if the given path is pointing to the root of the
    file system ("/" on Unix and "C:\\" on Windows for example).
    r
   )r   r!   
splitdriver&   sep)rx   r   r   r   r   Y  s   r   )r!   r   r"   r#   )r*   r   r"   r+   )rc   r   rd   re   r"   rf   )rc   r   r|   re   r"   r   )rd   r   r"   r   )r   r   r"   r    )r   r   r   r   rd   r   r   r   rc   r   r"   r   )rx   r   r"   r   )&
__future__r   collections.abcr   r   dataclassesr   r   r   pathlibr   rT   typingr   r	   r$   
exceptionsr   _pytest.outcomesr   _pytest.pathlibr   r   r   r   dictr&   r    r   r)   rb   r{   r   r   r   rR   r   r   r   r   r   r   <module>   s8    


d
/


C