o
    Rh7                    @   sZ  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddl m!Z!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+m,Z,m-Z- dd	l.m/Z/m0Z0m1Z1m2Z2 dd
l3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZR ddlSmTZT ddlUmVZVmWZW ddlXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZc ddldmeZemfZfmgZgmhZhmiZimjZjmkZkmlZl ddlmmnZnmoZompZpmqZq ddlrmsZs G dd de_ZtdddZudS )z+Test suite for the `humanfriendly` package.    N)InvalidDateInvalidLengthInvalidSizeInvalidTimespanTimercoerce_booleancoerce_patternformat_lengthformat_numberformat_pathformat_sizeformat_timespan
parse_dateparse_length
parse_path
parse_sizeparse_timespanpromptsround_number)CaseInsensitiveDictCaseInsensitiveKey)main)StringIOcached)DeprecationProxydefine_aliasesdeprecated_argsget_aliases)TooManyInvalidRepliesprompt_for_confirmationprompt_for_choiceprompt_for_input)deprecation_note_callbackman_role	pypi_rolesetupspecial_methods_callbackusage_message_callback)format_pretty_tableformat_robust_tableformat_rst_tableformat_smart_table)ANSI_CSIANSI_ERASE_LINEANSI_HIDE_CURSOR
ANSI_RESETANSI_SGRANSI_SHOW_CURSOR
ansi_strip
ansi_style
ansi_width	ansi_wrapclean_terminal_outputconnected_to_terminalfind_terminal_sizeget_pager_commandmessageoutput
show_pagerterminal_supports_colorswarninghtml_to_ansi)AutomaticSpinnerSpinner)CallableTimedOutCaptureOutputMockedProgramPatchedAttributePatchedItemTemporaryDirectoryTestCaseretryrun_cliskip_on_raisetouch)compactcompact_empty_linesconcatenatededentgenerate_slug	pluralizerandom_stringtrim_empty_lines)find_meta_variablesformat_usageparse_usagerender_usage)	MagicMockc                   @   sX  e Zd 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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(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Z d<d= Z!d>d? Z"d@dA Z#dBdC Z$dDdE Z%dFdG Z&dHdI Z'dJdK Z(dLdM Z)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5dfdg Z6dhdi Z7djdk Z8dldm Z9dndo Z:dpdq Z;drds Z<dtdu Z=dvdw Z>dxdy Z?dzd{ Z@d|d} ZAd~d ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdS )HumanFriendlyTestCasez-Container for the `humanfriendly` test suite.c                 C   s  t tddgdksJ t tddgdddd	ksJ t ttddd
dks)J t ttddddddd	ks:J t tddddd	ksGJ tg d}t |d	ksVJ tdd}|ddksdJ tdd}|ddksrJ t |dkszJ tdd}|ddksJ |dd |d dksJ tdd}d|v sJ tdd}|d= t |dksJ tdd}|d dksJ tdd}d|d< |d dksJ dS )z#Test the CaseInsensitiveDict class.)keyT)KEYF   )oneT)ONEFFT)r`   two   )r]   r^   )r`   ra   )r`   ra   rb   )Oner`   ra   Tworb   TWO*   )existing_keyExisting_Keyr   	other_key   	Other_Keyrh   N)lenr   dictfromkeysgetpop
setdefault)selfobj ru   U/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/humanfriendly/tests.pytest_case_insensitive_dict   s4   "






z0HumanFriendlyTestCase.test_case_insensitive_dictc                 C   sD   t d}t d}||ksJ i }d||< d||< t|dks J dS )z"Test the CaseInsensitiveKey class.zPlease don't shoutzPLEASE DON'T SHOUTr_   rc   N)r   rm   )rs   politerudemappingru   ru   rv   test_case_insensitive_key   s   z/HumanFriendlyTestCase.test_case_insensitive_keyc                 C   sl   t  )}tjd tjd |j dgksJ |j dgks$J W d   dS 1 s/w   Y  dS )zTest the CaptureOutput class.zSomething for stdout.
zAnd for stderr.
zSomething for stdout.zAnd for stderr.N)rE   sysstdoutwritestderr	get_lines)rs   capturerru   ru   rv   test_capture_output   s   "z)HumanFriendlyTestCase.test_capture_outputc                 C   s6   dd }t t}||}| t| | tj| dS )z#Test the skip_on_raise() decorator.c                   S      t  N)NotImplementedErrorru   ru   ru   rv   test_fn   s   z9HumanFriendlyTestCase.test_skip_on_raise.<locals>.test_fnN)rM   r   assertRaisesunittestSkipTest)rs   r   decorator_fndecorated_fnru   ru   rv   test_skip_on_raise   s
   z(HumanFriendlyTestCase.test_skip_on_raisec                    s`    fdd t  dksJ dd }| t t |dd W d   dS 1 s)w   Y  dS )	zFTest :func:`~humanfriendly.testing.retry()` based on assertion errors.c                      s   t  dst dd J dS )N
was_calledTFyeshasattrsetattrru   success_helperru   rv   r      s   
z>HumanFriendlyTestCase.test_retry_raise.<locals>.success_helperr   c                   S   s   J r   ru   ru   ru   ru   rv   failure_helper   s   z>HumanFriendlyTestCase.test_retry_raise.<locals>.failure_helperr_   timeoutN)rK   r   AssertionError)rs   r   ru   r   rv   test_retry_raise   s   "z&HumanFriendlyTestCase.test_retry_raisec                    s\    fdd t  dksJ | t t dd dd W d   dS 1 s'w   Y  dS )	zCTest :func:`~humanfriendly.testing.retry()` based on return values.c                      s   t  dst dd dS dS )Nr   TFrg   r   ru   r   ru   rv   r      s   
z?HumanFriendlyTestCase.test_retry_return.<locals>.success_helperrg   c                   S      dS )NFru   ru   ru   ru   rv   <lambda>       z9HumanFriendlyTestCase.test_retry_return.<locals>.<lambda>r_   r   N)rK   r   rD   rs   ru   r   rv   test_retry_return   s
   "z'HumanFriendlyTestCase.test_retry_returnc                 C   s   t  }td}t|d|dE}tj|sJ tjtj||s$J tj	|tj
tj
tj
d}|jdd\}}|jdks?J |dksEJ |dksKJ W d	   d	S 1 sVw   Y  d	S )
z2Test :class:`humanfriendly.testing.MockedProgram`.z
            # This goes to stdout.
            tr a-z A-Z
            # This goes to stderr.
            echo Fake warning >&2
        rg   )name
returncodescript)stdinr}   r   s   hello world
inputs   HELLO WORLD
s   Fake warning
N)rU   rR   rF   ospathisdirisfilejoin
subprocessPopenPIPEcommunicater   )rs   r   r   	directoryprogramr}   r   ru   ru   rv   test_mocked_program   s   "z)HumanFriendlyTestCase.test_mocked_programc              	   C   s   t  1}tj|sJ tj|d}t|d}|d W d   n1 s(w   Y  W d   n1 s7w   Y  tj|rDJ tj|rLJ dS )z7Test :class:`humanfriendly.testing.TemporaryDirectory`.z	some-filewzHello world!N)rI   r   r   r   r   openr~   exists)rs   r   temporary_filehandleru   ru   rv   test_temporary_directory   s   z.HumanFriendlyTestCase.test_temporary_directoryc                 C   s   t  C}tj|t }tj|rJ t| tj|s J tj|t t }tj|r2J t| tj|s>J W d   dS 1 sIw   Y  dS )z+Test :func:`humanfriendly.testing.touch()`.N)rI   r   r   r   rU   r   rN   )rs   r   filenameru   ru   rv   
test_touch
  s   "z HumanFriendlyTestCase.test_touchc                 C   s|   G dd dt }| }|jdksJ t|dd}||u sJ |jdks&J W d   n1 s0w   Y  |jdks<J dS )z5Test :class:`humanfriendly.testing.PatchedAttribute`.c                   @   s   e Zd ZdZdS )z;HumanFriendlyTestCase.test_patch_attribute.<locals>.Subjectrg   N)__name__
__module____qualname__my_attributeru   ru   ru   rv   Subject  s    r   rg   r      N)objectr   rG   )rs   r   instancereturn_valueru   ru   rv   test_patch_attribute  s   z*HumanFriendlyTestCase.test_patch_attributec                 C   sv   t dd}|d du sJ t|dd}||u sJ |d du s"J W d   n1 s,w   Y  |d du s9J dS )z0Test :class:`humanfriendly.testing.PatchedItem`.T)my_itemr   FN)rn   rH   )rs   r   r   ru   ru   rv   test_patch_item#  s   
z%HumanFriendlyTestCase.test_patch_itemc                 C   s    t dd \}}| |d dS )z*Test that run_cli() intercepts SystemExit.c                   S   s
   t dS )Nrg   )r|   exitru   ru   ru   rv   r   .     
 zDHumanFriendlyTestCase.test_run_cli_intercepts_exit.<locals>.<lambda>rg   N)rL   assertEqualrs   r   r<   ru   ru   rv   test_run_cli_intercepts_exit,  s   z2HumanFriendlyTestCase.test_run_cli_intercepts_exitc                 C   s   t | j\}}| |d dS )z*Test that run_cli() intercepts exceptions.r_   N)rL   run_cli_raise_otherr   r   ru   ru   rv   test_run_cli_intercepts_error1  s   z3HumanFriendlyTestCase.test_run_cli_intercepts_errorc                 C   r   )z*run_cli() sample that raises an exception.)
ValueErrorr   ru   ru   rv   r   6  s   z)HumanFriendlyTestCase.run_cli_raise_otherc                    s:   t  d  t fdd\}}| |d | |  dS )z&Test that run_cli() intercepts output.
c                      s   t j S r   )r|   r}   r~   ru   expected_outputru   rv   r   =  s    zFHumanFriendlyTestCase.test_run_cli_intercepts_output.<locals>.<lambda>r   N)rU   rL   r   r   ru   r   rv   test_run_cli_intercepts_output:  s   
z4HumanFriendlyTestCase.test_run_cli_intercepts_outputc                 C   sL   t dd }t dd }| | ksJ | | ksJ | | ks$J dS )zTest the caching decorator.c                   S      t   S r   randomru   ru   ru   rv   r   D      z>HumanFriendlyTestCase.test_caching_decorator.<locals>.<lambda>c                   S   r   r   r   ru   ru   ru   rv   r   E  r   Nr   )rs   abru   ru   rv   test_caching_decoratorA  s
   z,HumanFriendlyTestCase.test_caching_decoratorc                 C   :   t ddksJ t dddksJ t dddd	ksJ d
S )z*Test :func:`humanfriendly.text.compact()`.z a 

 b za bz*
            %s template notation
        SimplezSimple template notationz3
            More {type} template notation
        readable)typezMore readable template notationN)rO   r   ru   ru   rv   test_compactK     z"HumanFriendlyTestCase.test_compactc                 C   st   t ddksJ t ddksJ t ddksJ t ddks J t ddks(J t ddks0J t ddks8J dS )	z6Test :func:`humanfriendly.text.compact_empty_lines()`.fooz	foofoo
barzfoo

barz	foo


barz
foo



barzfoo




barN)rP   r   ru   ru   rv   test_compact_empty_linesU  s   z.HumanFriendlyTestCase.test_compact_empty_linesc                 C   r   )z)Test :func:`humanfriendly.text.dedent()`.z
 line 1
  line 2

zline 1
 line 2
z'
            Dedented, %s text
        interpolatedzDedented, interpolated text
z)
            Dedented, {op} text
        	formatted)opzDedented, formatted text
N)rR   r   ru   ru   rv   test_dedentd  r   z!HumanFriendlyTestCase.test_dedentc                 C   sP   t dddks	J t dddksJ t ddddksJ t dddd	ks&J d
S )z,Test :func:`humanfriendly.text.pluralize()`.r_   wordz1 wordrc   z2 wordsboxboxesz1 boxz2 boxesN)rT   r   ru   ru   rv   test_pluralizationn  s   z(HumanFriendlyTestCase.test_pluralizationc                 C   s   |  dtd |  dtd | t td W d   n1 s$w   Y  | t td W d   dS 1 s>w   Y  dS )z0Test :func:`humanfriendly.text.generate_slug()`.zsome-random-textzSome Random Text! N-)r   rS   r   r   r   ru   ru   rv   test_generate_slugu  s   

"z(HumanFriendlyTestCase.test_generate_slugc                 C   sl   dD ]
}|  dt| qdD ]
}|  dt| q| t td W d   dS 1 s/w   Y  dS )z,Test :func:`humanfriendly.coerce_boolean()`.)TTRUETruetrueonr   1T)FFALSEFalsefalseoffno0Fznot a booleanN)r   r   r   r   )rs   valueru   ru   rv   test_boolean_coercion  s   
"z+HumanFriendlyTestCase.test_boolean_coercionc                 C   s   t d}ttdt|sJ |t|u sJ tdt j}|ds%J | t tg  W d   dS 1 s:w   Y  dS )z,Test :func:`humanfriendly.coerce_pattern()`. foobarFOOBARN)	recompile
isinstancer   r   
IGNORECASEmatchr   r   )rs   empty_patternpatternru   ru   rv   test_pattern_coercion  s   

"z+HumanFriendlyTestCase.test_pattern_coercionc                 C   s  d}|d }|d }|d }|d }dt dddksJ d	t d
ddks&J dt dddks0J dt dddks:J dt dddksDJ dt dddksNJ dt dddksXJ dt dks`J dt dkshJ dt dkspJ dt tjksyJ dt |ksJ dt dksJ dt |d  ksJ d!t |ksJ d"t |d  ksJ d#t |ksJ d$t |d  ksJ d%t |ksJ d&t |d  ksJ d't |ksJ d(t |d  ksJ d)t |d* |d+  |d,  |d-  |d   d ddksJ d.t ||d   |d-  |d/  ksJ d0t d1ddksJ d2t d1ddks$J d3t d4ks-J d5t d6ks6J d7t d8ddksAJ d9t d:ddksLJ d;t d<ddksWJ tj }|tjd=d> }d?t || ksoJ d@S )Az-Test :func:`humanfriendly.format_timespan()`.<         4   z1 nanosecond&.>T)detailedz500 nanosecondsgƠ>z1 microsecondư>z500 microsecondsgMb@?1 millisecondMbP?500 milliseconds      ?0.5 secondsFz	0 secondsr   z0.54 secondsgna?1 secondr_   z3.14 seconds1 minutez1 minute and 20 secondsP   	2 minutesrc   1 hour2 hours1 day2 days1 week2 weeksz1 yearz2 yearszA6 years, 5 weeks, 4 days, 3 hours, 2 minutes and 500 milliseconds            z1 year, 2 weeks and 3 days   z'1 minute, 1 second and 100 millisecondsǧN@z1 minute and 1.1 secondsz1 minute and 0.3 secondsgfffff&N@z5 minutes and 0.3 secondsgr@z1 second and 15 millisecondsg=
ףp=?z10 seconds and 15 millisecondsgHz$@z 1 microsecond and 50 nanosecondsgӋ5>   )hoursz23 hoursN)r   mathpidatetimenow	timedelta)rs   minutehourdayweekyearr#  thenru   ru   rv   test_format_timespan  sV   2

z*HumanFriendlyTestCase.test_format_timespanc                 C   s  |  dtd |  dtd |  dtd |  dtd |  dtd	 |  d
td |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd  |  d!td" |  d!td# | t td$ W d%   d%S 1 sw   Y  d%S )&z,Test :func:`humanfriendly.parse_timespan()`.r   r   0sr  1nsgbak>51nsr	  1usg'eRC?52usr  1msr
  r  r  r  r  5sz	5 secondsx   2mr     z3 minz3 minsi0*  z3 hz3 hoursi F 4dz4 daysi$. z5 wz5 weeks1zN)r   r   r   r   r   ru   ru   rv   test_parse_timespan  s2   
"z)HumanFriendlyTestCase.test_parse_timespanc                 C   sh   |  dtd |  dtd |  dtd | t td W d   dS 1 s-w   Y  dS )	z(Test :func:`humanfriendly.parse_date()`.)  r     r   r   r   z
2013-06-17)r9  r  r:  rc   /   rg   z2013-06-17 02:47:42)i  rk      r   r;  r:  z2016-11-30 00:47:17z
2013-06-XYN)r   r   r   r   r   ru   ru   rv   test_parse_date  s   
"z%HumanFriendlyTestCase.test_parse_datec                 C   st  |  dtd |  dtd |  dtd |  dtd |  d	td
 |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtddd |  dtddd |  dtddd |  dtd dd |  d!td"dd |  d#td$dd |  d%td&dd |  d'td(dd |  d)td* |  d+td, d-S ).z)Test :func:`humanfriendly.format_size()`.z0 bytesr   z1 byter_   z42 bytesrg   1 KB  z1 MB@B 1 GB ʚ;1 TB    J)1 PB     I5 1 EB     NZo1 ZB     @=7M.c1 YB      B3v^!< z1 KiB   Tbinaryz1 MiB   z1 GiBi   @z1 TiBl        z1 PiBl           z1 EiBl            z1 ZiBl            z1 YiBl               z45 KBiȯ  z2.9 TBg  @«BN)r   r   r   ru   ru   rv   test_format_size  s*   z&HumanFriendlyTestCase.test_format_sizec                 C   s  |  dtd |  dtd |  dtd |  dtd |  dtdd	d
 |  dtd |  dtd |  dtdd	d
 |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd |  dtd | t td W d    n1 sw   Y  | t td! W d    d S 1 sw   Y  d S )"z(Test :func:`humanfriendly.parse_size()`.r   0Brg   4242Br?  1krM  TrN  r>  z
1 kilobytei@z69 MBrB  rA  rD  rC  rF  rE  rH  rG  rJ  rI  rL  rK  g   ZAz1.5 GBg      Dz1.5 YiB1qNr   )r   r   r   r   r   ru   ru   rv   test_parse_size  s.   

"z%HumanFriendlyTestCase.test_parse_sizec                 C   s   |  dtd |  dtd |  dtd |  dtd |  d	td
 |  dtd |  dtd |  dtd dS )z+Test :func:`humanfriendly.format_length()`.z0 metresr   z1 metrer_   z	42 metresrg   z1 kmr?  15.3 cm/$?z1 cm{Gz?z1 mmr  z1 nmr  N)r   r	   r   ru   ru   rv   test_format_length  s   z(HumanFriendlyTestCase.test_format_lengthc                 C   s   |  dtd |  dtd |  dtd |  dtd |  dtd	 |  d
td |  dtd |  dtd |  dtd | t td W d   n1 s\w   Y  | t td W d   dS 1 svw   Y  dS )z*Test :func:`humanfriendly.parse_length()`.r   0mrg   rS        ?1.542mr?  1kmrY  rX  rZ  1cmr  1mmr  1nmr7  Nr   )r   r   r   r   r   ru   ru   rv   test_parse_length(  s   

"z'HumanFriendlyTestCase.test_parse_lengthc                 C   s   |  dtd |  dtd |  dtd |  dtdd |  d	td
 |  d	tdd |  dtd |  dtd |  dtd dS )z+Test :func:`humanfriendly.format_number()`.r   r_   r^  r]  z1.56gg?z1.567r  z1,000r?  g)\@@r   z	1,000,000r@  z1,000,000.42gq=
׀.Az-285.67gQqN)r   r
   r   ru   ru   rv   test_format_number8  s   z(HumanFriendlyTestCase.test_format_numberc                 C   sH   |  dtd |  dtd |  dtddd |  dtd d	S )
z*Test :func:`humanfriendly.round_number()`.r   r_   g      ?1.00T
keep_widthz3.14g-DT!	@N)r   r   r   ru   ru   rv   test_round_numberE  s   z'HumanFriendlyTestCase.test_round_numberc                 C   s6   t jdd}t jt jd d}| |t| dS )z)Test :func:`humanfriendly.format_path()`.~.vimrcHOMEN)r   r   r   environr   r   rs   friendly_pathabsolute_pathru   ru   rv   test_format_pathL     z&HumanFriendlyTestCase.test_format_pathc                 C   s6   t jdd}t jt jd d}| |t| dS )z(Test :func:`humanfriendly.parse_path()`.rj  rk  rl  N)r   r   r   rm  r   r   rn  ru   ru   rv   test_parse_pathR  rr  z%HumanFriendlyTestCase.test_parse_pathc                 C   s   dgg}t |td ksJ g dg dg}t |td ks$J g d}g dg dg}tt ||td ks?J dd	g}d
dgddgg}tt ||td ksZJ dS )z8Test :func:`humanfriendly.tables.format_pretty_table()`.zJust one columnzi
            -------------------
            | Just one column |
            -------------------
        rd   re   Threer   23z
            ---------------------
            | One | Two | Three |
            | 1   | 2   | 3     |
            ---------------------
        r   r   c
            ---------------------
            | One | Two | Three |
            ---------------------
            | 1   | 2   | 3     |
            | a   | b   | c     |
            ---------------------
        zJust a labelzImportant numberszRow one15zRow two300a/  
            ------------------------------------
            | Just a label | Important numbers |
            ------------------------------------
            | Row one      |                15 |
            | Row two      |               300 |
            ------------------------------------
        N)r)   rR   stripr3   )rs   datacolumn_namesru   ru   rv   test_pretty_tablesX  s$   	z(HumanFriendlyTestCase.test_pretty_tablesc                 C   p   g d}g dg dg}t t||td ksJ g d}g dg dg}t t||td ks6J dS )z8Test :func:`humanfriendly.tables.format_robust_table()`.rt  rv  ry  z
            --------
            One: 1
            Two: 2
            Three: 3
            --------
            One: a
            Two: b
            Three: c
            --------
        r   r   zHere comes a
multi line column!  
            ------------------
            One: 1
            Two: 2
            Three: 3
            ------------------
            One: a
            Two: b
            Three:
            Here comes a
            multi line column!
            ------------------
        N)r3   r*   rR   r~  rs   r  r  ru   ru   rv   test_robust_tables  s   
z(HumanFriendlyTestCase.test_robust_tablesc                 C   r  )z7Test :func:`humanfriendly.tables.format_smart_table()`.rt  rv  ry  r{  r  r  N)r3   r,   rR   r~  r  ru   ru   rv   test_smart_tables  s   z'HumanFriendlyTestCase.test_smart_tablesc                 C   s^   g d}g dg dg}|  t||td  g dg dg}|  t|td  dS )z5Test :func:`humanfriendly.tables.format_rst_table()`.rt  rv  ry  z
                ===  ===  =====
                One  Two  Three
                ===  ===  =====
                1    2    3
                a    b    c
                ===  ===  =====
            zm
                =  =  =
                1  2  3
                a  b  c
                =  =  =
            N)r   r+   rR   rstripr  ru   ru   rv   test_rst_tables  s   z%HumanFriendlyTestCase.test_rst_tablesc                 C   s~   t g dksJ t dgdksJ t ddgdksJ t g ddks%J t g dddd	ks1J t g dd
ddks=J dS )z.Test :func:`humanfriendly.text.concatenate()`.r   r`   rb   zone and two)r`   rb   threezone, two and threeor)conjunctionzone, two or threeT)serial_commazone, two, and threeNrQ   r   ru   ru   rv   test_concatenate  s   z&HumanFriendlyTestCase.test_concatenatec                 C   sn   ddl m} | |dg  | |ddg | |dddg | |dg d | |d	g d d
S )z(Test :func:`humanfriendly.text.split()`.r   )splitr   r   zfoo, barbarzfoo, bar, bazr   r  bazzfoo,bar,bazN)humanfriendly.textr  r   )rs   r  ru   ru   rv   
test_split  s   z HumanFriendlyTestCase.test_splitc              	   C   s   dD ]!\}}t t | }| t|jddd|  | t|| qt t d }| |jd t  }td | t|jdd	 t dd
}t	dD ]}| td W d   n1 sbw   Y  qN| t|jdd t dd
}|dus~J W d   dS 1 sw   Y  dS )z!Test :func:`humanfriendly.Timer`.)
)r_   r  )rc   	2 seconds)r  r  )r3  r  )i  r  )i   r  )iQ r  )i  r  )i:	 r  )i u r  Trg  z%i.00g@r  r_   r   rf  )	resumablerc   Nz2.00)
r   timer   r   elapsed_timestrroundedsleepnormalize_timestamprange)rs   secondstexttautomatic_timerresumable_timeritimerru   ru   rv   
test_timer  s&   


"z HumanFriendlyTestCase.test_timerc                 C   s   t  }tdd|dd}dD ]}|j|d td q|  | }|tdt	d}d	d
 |
tD }| t|dk | tdd |D  | tdd |D  | tt|t| dS )z#Test :func:`humanfriendly.Spinner`.test spinnerr  T)labeltotalstreaminteractive)r_   rc   r  r  )progressg?r   c                 S   s   g | ]}|r|qS ru   ru   .0lineru   ru   rv   
<listcomp>      z6HumanFriendlyTestCase.test_spinner.<locals>.<listcomp>r   c                 s       | ]}d |v V  qdS )r  Nru   r  ru   ru   rv   	<genexpr>      z5HumanFriendlyTestCase.test_spinner.<locals>.<genexpr>c                 s   r  )%Nru   r  ru   ru   rv   r    r  N)r   rC   stepr  r  cleargetvaluereplacer2   r/   r  r.   
assertTruerm   allr   sortedset)rs   r  spinnerr  r<   linesru   ru   rv   test_spinner  s   
z"HumanFriendlyTestCase.test_spinnerc                 C   s:   t dd td W d   dS 1 sw   Y  dS )a  
        Test :func:`humanfriendly.AutomaticSpinner`.

        There's not a lot to test about the :class:`.AutomaticSpinner` class,
        but by at least running it here we are assured that the code functions
        on all supported Python versions. :class:`.AutomaticSpinner` is built
        on top of the :class:`.Spinner` class so at least we also have the
        tests for the :class:`.Spinner` class to back us up.
        r  )r  r_   N)rB   r  r  r   ru   ru   rv   test_automatic_spinner   s   
"z,HumanFriendlyTestCase.test_automatic_spinnerc              	      s*  |  t tg  W d   n1 sw   Y  ttj)}ttd| d}t|g|ks1J W d   n1 s;w   Y  W d   n1 sJw   Y  ttddd  tddgdksbJ W d   n1 slw   Y  ttdd	d  tddgdksJ W d   n1 sw   Y  ttdd
d  tddgdksJ W d   n1 sw   Y  ttddd  tddgdddksJ W d   n1 sw   Y  g d ttd fdd tg ddksJ W d   n1 sw   Y  ddg ttd fdd tg ddksJ W d   n	1 s&w   Y  ddg ttd fdd tg ddksEJ W d   n	1 sPw   Y  ttddd - |  t	 tg d W d   n1 suw   Y  W d   dS W d   dS 1 sw   Y  dS )z7Test :func:`humanfriendly.prompts.prompt_for_choice()`.Nr   zonly one option (shortcut)interactive_promptc                 S   r   )Nr   ru   pru   ru   rv   r   :  r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>r   r  c                 S   r   )Nfru   r  ru   ru   rv   r   =  r   c                 S   r   )Nrw  ru   r  ru   ru   rv   r   @  r   c                 S   r   Nr   ru   r  ru   ru   rv   r   C  r   default)r   qzc                    
     dS Nr   rq   r  repliesru   rv   r   G  r   r  r  r   r  c                    r  r  r  r  r  ru   rv   r   K  r   )r   r  r  quxr  rS  rw  c                    r  r  r  r  r  ru   rv   r   O  r   c                 S   r   r  ru   r  ru   ru   rv   r   R  r   ry  )
r   r   r!   r   r   devnullrG   r|   r   r   )rs   r   only_optionru   r  rv   test_prompt_for_choice-  sR   
 $z,HumanFriendlyTestCase.test_prompt_for_choicec              
      sx  dD ]$t tdfdd tddu sJ W d   n1 s!w   Y  qdD ]$t tdfd	d tdd
u s>J W d   n1 sHw   Y  q)dD ]$}t tddd  td|d|u seJ W d   n1 sow   Y  qPddg t td fdd- tdd}tddu sJ d| v sJ W d   n1 sw   Y  W d   n1 sw   Y  t tddd 6 dD ]+\}}tdd}td|ddu sJ || v sJ W d   n1 sw   Y  qW d   n1 sw   Y  t tddd + | t td W d   n1 sw   Y  W d   dS W d   dS 1 s5w   Y  dS )z=Test :func:`humanfriendly.prompts.prompt_for_confirmation()`.)r   YesYESyYr  c                        S r   ru   r  replyru   rv   r   Z  r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>zAre you sure?TN)r   NoNOnNc                    r  r   ru   r  r  ru   rv   r   ^  r   F)TFc                 S   r   r  ru   r  ru   ru   rv   r   b  r   r  r   r  c                    r  r  r  r  r  ru   rv   r   f  r   mergedzthere's no default choicec                 S   r   )Nr  ru   r  ru   ru   rv   r   k  r   ))TzY/n)Fzy/N)Nzy/nc                 S   r   r  ru   r  ru   ru   rv   r   q  r   )rG   r   r    rE   get_textr   r   )rs   default_choicer   default_valueexpected_textru   )r  r  rv   test_prompt_for_confirmationV  sN   
 $z2HumanFriendlyTestCase.test_prompt_for_confirmationc              
   C   s   t tjL}ttd|- d}td|d|ksJ | t td W d   n1 s-w   Y  W d   n1 s<w   Y  W d   dS W d   dS 1 sTw   Y  dS )z6Test :func:`humanfriendly.prompts.prompt_for_input()`.r   zTo seek the holy grail!zWhat is your quest?r  zWhat is your favorite color?N)r   r   r  rG   r|   r"   r   EOFError)rs   r   r  ru   ru   rv   test_prompt_for_inputu  s   
"z+HumanFriendlyTestCase.test_prompt_for_inputc                 C   s  t t\}}d|v sJ t td\}}d|v sJ t td\}}|dks&J t td\}}| dks5J tdd}t td	| \}}| t|ksNJ tdd}t td	| d
\}}| t|ddksjJ tdd}t td| \}}| t|ksJ t|d }t td| \}}| t|ksJ t tdddd\}}| td ksJ tdd}t td| \}}| t	|ksJ t td\}}t
|tdksJ t td\}}t
|tdddksJ t td\}}t
|tdksJ t td\}}t|tdksJ t td d!d"d#\}}|d$ks$J t td%\}}|dks2J d&d' | D }d(|v sBJ d)|v sIJ d*|v sPJ d+|v sWJ d,|v s^J d-|v seJ d.|v slJ d/S )0z Test the command line interface.zUsage:z--helpz--unsupported-optionr   z--format-number=1234567z	1,234,567rM  rP  z--format-size=%iz--binaryTrN  z--format-length=%ig@z--format-length=%fz--format-tablez--delimiter=	z1	2	3
4	5	6
7	8	9r   z
            -------------
            | 1 | 2 | 3 |
            | 4 | 5 | 6 |
            | 7 | 8 | 9 |
            -------------
        r  iX  z--format-timespan=%iz--parse-size=5 KBz5 KBz--parse-size=5 YiBz5 YBz--parse-length=5 kmz5 kmz--parse-length=1.05 kmz1.05 kmz--run-commandbashz-czsleep 2 && exit 42rg   z--democ                 S   s   g | ]}t |qS ru   )r3   r  ru   ru   rv   r    r  z2HumanFriendlyTestCase.test_cli.<locals>.<listcomp>zText styles:zForeground colors:zBackground colors:z!256 color mode (standard colors):z'256 color mode (high-intensity colors):z256 color mode (216 colors):z#256 color mode (gray scale colors):N)rL   r   r~  r   randintr   r	   floatrR   r   intr   r   
splitlines)rs   r   r<   random_byte_count
random_lenrandom_timespanr  ru   ru   rv   test_cli  s^   zHumanFriendlyTestCase.test_clic                 C   s  t dddttf ksJ t dddttf ksJ t dddttf ks'J t ddd	ttf ks4J t dd
dttf ksAJ t dddttf ksNJ t dddttf ks[J t dddttf kshJ t ddddttf ksvJ t dddttf ksJ t dddttf ksJ t dddttf ksJ t dddttf ksJ t dddttf ksJ | t t dd W d   dS 1 sw   Y  dS ) z1Test :func:`humanfriendly.terminal.ansi_style()`.Tboldz%s1%s)faintz%s2%s)italicz%s3%s)	underlinez%s4%s)inversez%s7%s)strike_throughz%s9%sbluecolorz%s34%s)
backgroundz%s44%s)r  brightz%s94%s   z%s38;5;214%sz%s39;5;214%s)r   r   r   z%s38;2;0;0;0%s)   r  r  z%s38;2;255;255;255%s)2   d      z%s48;2;50;100;150%sunknownN)r4   r-   r1   r   r   r   ru   ru   rv   test_ansi_style  s"   "z%HumanFriendlyTestCase.test_ansi_stylec                 C   s\   d}t |t|ksJ t|dd}||ksJ t |t |ks"J t |t|ks,J dS )z1Test :func:`humanfriendly.terminal.ansi_width()`.WhateverTr  N)rm   r5   r6   )rs   r  wrappedru   ru   rv   test_ansi_width  s   z%HumanFriendlyTestCase.test_ansi_widthc                 C   sD   d}|t |ks
J t |ddtsJ t |ddts J dS )z0Test :func:`humanfriendly.terminal.ansi_wrap()`.r  Tr  N)r6   
startswithr-   endswithr0   rs   r  ru   ru   rv   test_ansi_wrap  s   z$HumanFriendlyTestCase.test_ansi_wrapc                 C   s  t ddksJ t ddksJ t ddksJ t ddks J t ddks(J t d	d
ks0J t dd
ks8J t ddks@J t ddksHJ t ddksPJ t ddksXJ t ddks`J t ddkshJ t ddkspJ t ddksxJ t ddksJ t ddksJ t ddksJ t dd ksJ t d!dksJ d"d# }d$t d%|d&vsJ d$t d'|d&v sJ t d(sJ d)S )*z@Test the :func:`humanfriendly.terminal.html_to_ansi()` function.zJust some plain textz+<a href="https://python.org">python.org</a>z=[0m[4;94mpython.org[0m ([0m[4;94mhttps://python.org[0m)z@<a href="mailto:peter@peterodding.com">peter@peterodding.com</a>z$[0m[4;94mpeter@peterodding.com[0mzLet's try <b>bold</b>zLet's try [0m[1mbold[0mz5Let's try <span style="font-weight: bold">bold</span>zLet's try <i>italic</i>zLet's try [0m[3mitalic[0mz8Let's try <span style="font-style: italic">italic</span>zLet's try <ins>underline</ins>zLet's try [0m[4munderline[0mzCLet's try <span style="text-decoration: underline">underline</span>zLet's try <s>strike-through</s>z$Let's try [0m[9mstrike-through[0mzKLet's try <span style="text-decoration: line-through">strike-through</span>z$Let's try <code>pre-formatted</code>z$Let's try [0m[33mpre-formatted[0mz6Let's try <span style="color: #AABBCC">text colors</s>z0Let's try [0m[38;2;170;187;204mtext colors[0mzOLet's try <span style="background-color: rgb(50, 50, 50)">background colors</s>z3Let's try [0m[48;2;50;50;50mbackground colors[0mz Let's try some<br>line<br>breakszLet's try some
line
breaksz&#38;&z&amp;z&gt;>z&lt;<z&#x26;c                 S   s   |  ddS )N:wink:z;-))r  )r  ru   ru   rv   callback'  s   z9HumanFriendlyTestCase.test_html_to_ansi.<locals>.callbackr  z<b>:wink:</b>)r  z<code>:wink:</code>a  
            Tweakers zit er idd nog steeds:<br><br>
            peter@peter-work&gt; curl -s <a href="tweakers.net">tweakers.net</a> | grep -i hosting<br>
            &lt;a href="<a href="http://www.true.nl/webhosting/">http://www.true.nl/webhosting/</a>"
                rel="external" id="true" title="Hosting door True"&gt;&lt;/a&gt;<br>
            Hosting door &lt;a href="<a href="http://www.true.nl/vps/">http://www.true.nl/vps/</a>"
                title="VPS hosting" rel="external"&gt;True</a>
        Nr@   )rs   r  ru   ru   rv   test_html_to_ansi  sd   z'HumanFriendlyTestCase.test_html_to_ansic                 C   sb   d}t dd }t| | |g|j  | g |j  W d   dS 1 s*w   Y  dS )z:Test the :func:`humanfriendly.terminal.output()` function.z%Standard output generated by output()Fr  N)rE   r<   r   r}   r   r   rs   r  r   ru   ru   rv   test_generate_output9  s   "z*HumanFriendlyTestCase.test_generate_outputc                 C   sb   d}t dd }t| | g |j  | |g|j  W d   dS 1 s*w   Y  dS )z;Test the :func:`humanfriendly.terminal.message()` function.z%Standard error generated by message()Fr  N)rE   r;   r   r}   r   r   r  ru   ru   rv   test_generate_messageA  s   "z+HumanFriendlyTestCase.test_generate_messagec                 C   sx   ddl m} d}|dd%}t| | g |j  | t|ddg| |j W d   dS 1 s5w   Y  dS )	z;Test the :func:`humanfriendly.terminal.warning()` function.r   rE   z%Standard error generated by warning()Fr  redr  N)	r   rE   r?   r   r}   r   r6   ignore_coverage_warningr   )rs   rE   r  r   ru   ru   rv   test_generate_warningI  s    "z+HumanFriendlyTestCase.test_generate_warningc                 C   s   dd |  D S )a  
        Filter out coverage.py warning from standard error.

        This is intended to remove the following line from the lines captured
        on the standard error stream:

        Coverage.py warning: No data was collected. (no-data-collected)
        c                 S   s   g | ]}d |vr|qS )zno-data-collectedru   r  ru   ru   rv   r  [  s    zAHumanFriendlyTestCase.ignore_coverage_warning.<locals>.<listcomp>)r   )rs   r  ru   ru   rv   r  R  s   	z-HumanFriendlyTestCase.ignore_coverage_warningc                 C   sv   t ddgks	J t dddgksJ t dddgksJ t ddgks&J t ddgks/J t d	g d
ks9J dS )z<Test :func:`humanfriendly.terminal.clean_terminal_output()`.r   r   r  zfoobar
bazr  zaaaababazaaabzfoo
bar
baz


r  N)r7   r   ru   ru   rv   test_clean_output]  s   z'HumanFriendlyTestCase.test_clean_outputc              	   C   s   t  \}}|dksJ |dksJ tj}tj}tj}zRt t_t t_t t_t  \}}|dks2J |dks8J tjd }zdtjd< t  \}}|dksNJ |dksTJ W |tjd< n|tjd< w W |t_|t_|t_dS |t_|t_|t_w )z9Test :func:`humanfriendly.terminal.find_terminal_size()`.r   PATHr   N)r9   r|   r   r}   r   r   r   rm  )rs   r  columnssaved_stdinsaved_stdoutsaved_stderr
saved_pathru   ru   rv   test_find_terminal_sizel  s4   





z-HumanFriendlyTestCase.test_find_terminal_sizec              
   C   s   ddl m} ttfD ]F}tjtjfD ]}|  ||sJ W d   n1 s(w   Y  qttj	}||r:J W d   n1 sDw   Y  |t
 rPJ q
dS )z8Test the functions that check for terminal capabilities.r   r  N)r   rE   r8   r>   r|   r}   r   r   r   r  r   )rs   rE   test_streamr  r   ru   ru   rv   test_terminal_capabilities  s   z0HumanFriendlyTestCase.test_terminal_capabilitiesc              	   C   s   t jdd}zDdt jd< ddd tdD }t }t| || v s)J W d   n1 s3w   Y  W |durD|t jd< dS t jd dS |durV|t jd< w t jd w )z1Test :func:`humanfriendly.terminal.show_pager()`.PAGERNcatr   c                 s   s    | ]}t d V  qdS )   N)rU   )r  r  ru   ru   rv   r    r  z8HumanFriendlyTestCase.test_show_pager.<locals>.<genexpr>r  )	r   rm  rp   r   r  rE   r=   r  rq   )rs   original_pagerrandom_textr   ru   ru   rv   test_show_pager  s   
z%HumanFriendlyTestCase.test_show_pagerc              
      s   dt dvsJ dt tdddv sJ ddg}dD ]S}tjdd	}z9|tjd< t   |d
kr>t fdd|D s=J nt fdd|D rKJ W |d	urV|tjd< qtjd q|d	urg|tjd< w tjd w d	S )z8Test :func:`humanfriendly.terminal.get_pager_command()`.z--RAW-CONTROL-CHARSzUsage messageTr  z	--no-initz--quit-if-one-screen)r$  lessr#  Nr)  c                 3       | ]}| v V  qd S r   ru   r  optcommand_lineru   rv   r    r  z?HumanFriendlyTestCase.test_get_pager_command.<locals>.<genexpr>c                 3   r*  r   ru   r+  r-  ru   rv   r    r  )r:   r6   r   rm  rp   r  anyrq   )rs   options_specific_to_lesspagerr&  ru   r-  rv   test_get_pager_command  s&   
z,HumanFriendlyTestCase.test_get_pager_commandc                 C   s    t tdt g dksJ dS )z7Test :func:`humanfriendly.usage.find_meta_variables()`.z
            Here's one example: --format-number=VALUE
            Here's another example: --format-size=BYTES
            A final example: --format-timespan=SECONDS
            This line doesn't contain a META variable.
        )VALUEBYTESSECONDSN)r  rW   r   ru   ru   rv   test_find_meta_variables  s   

z.HumanFriendlyTestCase.test_find_meta_variablesc                 C   sN   |  d\}}d|v sJ d|v sJ d|v sJ d|v sJ d|v s%J dS )z?Test :func:`humanfriendly.usage.parse_usage()` (a simple case).z
            Usage: my-fancy-app [OPTIONS]

            Boring description.

            Supported options:

              -h, --help

                Show this message and exit.
        Usage: my-fancy-app [OPTIONS]zBoring description.Supported options:z
-h, --helpzShow this message and exit.Npreprocess_parse_resultrs   introductionoptionsru   ru   rv   test_parse_usage_simple  s   z-HumanFriendlyTestCase.test_parse_usage_simplec                 C   sp   |  d\}}d|v sJ tdd |D sJ d|v sJ d|v s$J d|v s*J d|v s0J d	|v s6J d
S )z?Test :func:`humanfriendly.usage.parse_usage()` (a tricky case).a<  
            Usage: my-fancy-app [OPTIONS]

            Here's the introduction to my-fancy-app. Some of the lines in the
            introduction start with a command line option just to confuse the
            parsing algorithm :-)

            For example
            --an-awesome-option
            is still part of the introduction.

            Supported options:

              -a, --an-awesome-option

                Explanation why this is an awesome option.

              -b, --a-boring-option

                Explanation why this is a boring option.
        r7  c                 s   r  )zstill part of the introductionNru   r  r  ru   ru   rv   r    r  z@HumanFriendlyTestCase.test_parse_usage_tricky.<locals>.<genexpr>r8  z-a, --an-awesome-optionz*Explanation why this is an awesome option.z-b, --a-boring-optionz(Explanation why this is a boring option.N)r:  r/  r;  ru   ru   rv   test_parse_usage_tricky  s   z-HumanFriendlyTestCase.test_parse_usage_trickyc                 C   sf   |  d\}}d|v sJ d|v sJ d|v sJ d|v sJ d|v s%J d|v s+J d|v s1J d	S )
zWTest :func:`humanfriendly.usage.parse_usage()` against option labels containing commas.a<  
            Usage: my-fancy-app [OPTIONS]

            Some introduction goes here.

            Supported options:

              -f, --first-option

                Explanation of first option.

              -s, --second-option=WITH,COMMA

                This should be a separate option's description.
        r7  zSome introduction goes here.r8  z-f, --first-optionzExplanation of first option.z-s, --second-option=WITH,COMMAz/This should be a separate option's description.Nr9  r;  ru   ru   rv   test_parse_usage_commas  s   z-HumanFriendlyTestCase.test_parse_usage_commasc                 C   s   t dd tt|D S )z:Ignore leading/trailing whitespace in usage parsing tests.c                 s   s    | ]
}d d |D V  qdS )c                 S   s   g | ]}|  qS ru   )r~  r?  ru   ru   rv   r  5  r  zKHumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>.<listcomp>Nru   )r  rru   ru   rv   r  5  s    z@HumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>)tuplerY   rR   r	  ru   ru   rv   r:  3  s   z-HumanFriendlyTestCase.preprocess_parse_resultc                 C   s   d}t |}t|t|ksJ |dsJ d}t |}t|t|ks'J ||v s-J ||r4J d}t |}| }t|d v sFJ t|d vsNJ dS )z0Test :func:`humanfriendly.usage.format_usage()`.zJust one --optionz	Just one zUsage: humanfriendly [OPTIONS]z^--valid-option=VALID_METAVAR
VALID_METAVAR is bogus
INVALID_METAVAR should not be highlighted
r_   rc   N)rX   rm   r  r  r-   )rs   
usage_textformatted_textformatted_linesru   ru   rv   test_format_usage7  s   z'HumanFriendlyTestCase.test_format_usagec                 C   sN   t ddksJ t ddksJ dt tdv sJ tdd d	D s%J d
S )z0Test :func:`humanfriendly.usage.render_usage()`.zUsage: some-command WITH ARGSz#**Usage:** `some-command WITH ARGS`r8  z**Supported options:**z
code-blockz_
            Here comes a shell command:

              $ echo test
              test
        c                 s   s     | ]}|t td v V  qdS )zm
            Supported options:

              -n, --dry-run

                Don't change anything.
        N)rZ   rR   )r  tokenru   ru   rv   r  [  s    z:HumanFriendlyTestCase.test_render_usage.<locals>.<genexpr>)z`-n`z`--dry-run`N)rZ   rR   r  r   ru   ru   rv   test_render_usageQ  s   z'HumanFriendlyTestCase.test_render_usagec              	   C   s   t dddd }t }ttd|, |dddksJ | t |ddd W d   n1 s2w   Y  W d   n1 sAw   Y  |jsKJ dS )	z.Test the deprecated_args() decorator function.r   r  c                  [   s&   | d dksJ |  ddv sJ dS )Nr   r  )Nr  rg   )rp   )r=  ru   ru   rv   test_functione  s   zAHumanFriendlyTestCase.test_deprecated_args.<locals>.test_functionwarnrg   r  N)r   r[   rG   warningsr   	TypeErrorr   )rs   rJ  fake_fnru   ru   rv   test_deprecated_argsc  s   
z*HumanFriendlyTestCase.test_deprecated_argsc                 C   sl   t  }ttd| tjt }tdd}t||}|jtks J W d   n1 s*w   Y  |j	s4J dS )@Test that the DeprecationProxy class emits deprecation warnings.rK  humanfriendly.text.concatenater  N)
r[   rG   rL  r|   modulesr   rn   r   rQ   r   )rs   rN  modulealiasesproxyru   ru   rv   $test_alias_proxy_deprecation_warningq  s   


z:HumanFriendlyTestCase.test_alias_proxy_deprecation_warningc                 C   sl   t tjdtd" ttdd dttjt v sJ dttv s$J W d   dS 1 s/w   Y  dS )rP  sphinxrQ  r  rQ   N)	rH   r|   rR  types
ModuleTyper   r   dirr   r   ru   ru   rv   $test_alias_proxy_sphinx_compensation{  s
   "z:HumanFriendlyTestCase.test_alias_proxy_sphinx_compensationc                 C   sL   t jt }ttdd |j }tddd|d|d d||jks$J dS )z?Test that aliases can be injected into generated documentation.rQ  r  Nappwhatr   rt   r=  r  r   )r|   rR  r   r   __doc__r  r#   r   )rs   rS  r  ru   ru   rv   #test_alias_proxy_sphinx_integration  s
   

z9HumanFriendlyTestCase.test_alias_proxy_sphinx_integrationc                 C   s   G dd dt }| }t| t|jd ksJ t|jd ks!J t|jd v s*J t|jd v s3J t|jd v s<J tddd|j	ddd	d
u sKJ tddd|j
ddd	du sZJ ddlm}m} | |siJ | |rpJ | |jrxJ dS )z,Test the :mod:`humanfriendly.sphinx` module.c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )zAHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeAppc                 S   s   i | _ i | _d S r   )	callbacksrolesr   ru   ru   rv   __init__  s   
zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__init__c                 S   r   )z%Documented unofficial special method.Nru   r   ru   ru   rv   __documented_special_method__     z_HumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__documented_special_method__c                 S   s   d S r   ru   r   ru   ru   rv   __undocumented_special_method__  re  zaHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__undocumented_special_method__c                 S   s   || j |< d S r   )rb  )rs   r   r  ru   ru   rv   add_role  s   zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.add_rolec                 S   s   | j |g | d S r   )ra  rr   append)rs   eventr  ru   ru   rv   connect  s   zIHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.connectc                 S   r   )z.Usage: This is not supposed to be reformatted!Nru   r   ru   ru   rv   bogus_usage  re  zMHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.bogus_usageN)	r   r   r   rc  rd  rf  rg  rj  rk  ru   ru   ru   rv   FakeApp  s    rl  manpypizautodoc-process-docstringzautodoc-skip-memberNT)r]  r^  r   rt   skipr=  Fr   )clirW  )r   r&   r$   rb  r%   r#   ra  r'   r(   rd  rf  humanfriendlyrp  rW  docstring_is_reformattedrk  )rs   rl  fake_apprp  rW  ru   ru   rv   test_sphinx_customizations  s4   z0HumanFriendlyTestCase.test_sphinx_customizationsc                 C   s2   t |j }t|}tddd|d|d ||kS )zOCheck whether :func:`.usage_message_callback()` reformats a module's docstring.Nr\  )rV   r_  r  listr(   )rs   entityr  saved_linesru   ru   rv   rr    s   z.HumanFriendlyTestCase.docstring_is_reformattedN)Mr   r   r   r_  rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r+  r8  r=  rQ  rW  r[  rd  re  ri  rq  rs  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r   r"  r(  r2  r6  r>  r@  rA  r:  rG  rI  rO  rV  r[  r`  rt  rr  ru   ru   ru   rv   r\      s    *	
	


	2(	$)I
D	*	!
	:r\   r_   c                 C   s   dt t| |d S )z
    Round timestamps to the given number of digits.

    This helps to make the test suite less sensitive to timing issues caused by
    multitasking, processor scheduling, etc.
    z%.2f)ndigits)roundr  )r   rx  ru   ru   rv   r    s   r  )r_   )vr_  r"  r   r   r   r   r   r|   r  rX  r   rL  rq  r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   humanfriendly.caser   r   humanfriendly.clir   humanfriendly.compatr   humanfriendly.decoratorsr   humanfriendly.deprecationr   r   r   r   humanfriendly.promptsr   r    r!   r"   humanfriendly.sphinxr#   r$   r%   r&   r'   r(   humanfriendly.tablesr)   r*   r+   r,   humanfriendly.terminalr-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   humanfriendly.terminal.htmlrA   humanfriendly.terminal.spinnersrB   rC   humanfriendly.testingrD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r  rO   rP   rQ   rR   rS   rT   rU   rV   humanfriendly.usagerW   rX   rY   rZ   mockr[   r\   r  ru   ru   ru   rv   <module>   sP   	T T4(
          Y