U
    tc7                    @   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tt tddgdddd	ks6tt ttddd
dksRtt ttddddddd	ksttt tddddd	ksttddddddg}t |d	ksttdd}|ddksttdd}|ddkstt |dksttdd}|ddkst|dd |d dks8ttdd}d|ksPttdd}|d= t |dksrttdd}|d dksttdd}d|d< |d dkstdS )z#Test the CaseInsensitiveDict class.)keyT)KEYF   )oneT)ONEFFT)r^   two   )r[   r\   )r^   r_   )r^   r_   r`   Oner^   r_   Twor`   ZTWO*   )existing_keyZExisting_Keyr   Z	other_key   Z	Other_Keyre   N)lenr   AssertionErrordictfromkeysgetpop
setdefault)selfobj rp   7/tmp/pip-unpacked-wheel-b0xk_5ho/humanfriendly/tests.pytest_case_insensitive_dict   s4    "






z0HumanFriendlyTestCase.test_case_insensitive_dictc                 C   sD   t d}t d}||ksti }d||< d||< t|dks@tdS )z"Test the CaseInsensitiveKey class.zPlease don't shoutzPLEASE DON'T SHOUTr]   ra   N)r   rh   rg   )rn   ZpoliteZrudemappingrp   rp   rq   test_case_insensitive_key   s    z/HumanFriendlyTestCase.test_case_insensitive_keyc              	   C   sV   t  F}tjd tjd |j dgks4t|j dgksHtW 5 Q R X dS )zTest the CaptureOutput class.zSomething for stdout.
zAnd for stderr.
zSomething for stdout.zAnd for stderr.N)rC   sysstdoutwritestderr	get_linesrh   )rn   capturerrp   rp   rq   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   s
   t  d S N)NotImplementedErrorrp   rp   rp   rq   test_fn   s    z9HumanFriendlyTestCase.test_skip_on_raise.<locals>.test_fnN)rK   r}   assertRaisesunittestZSkipTest)rn   r~   Zdecorator_fnZdecorated_fnrp   rp   rq   test_skip_on_raise   s
    z(HumanFriendlyTestCase.test_skip_on_raisec              	      sJ    fdd t  dkstdd }| t t |dd W 5 Q R X dS )	zFTest :func:`~humanfriendly.testing.retry()` based on assertion errors.c                      s(   t  ds t dd ds$tndS d S )N
was_calledTFyes)hasattrsetattrrh   rp   success_helperrp   rq   r      s    

z>HumanFriendlyTestCase.test_retry_raise.<locals>.success_helperr   c                   S   s   dst d S NF)rh   rp   rp   rp   rq   failure_helper   s    z>HumanFriendlyTestCase.test_retry_raise.<locals>.failure_helperr]   timeoutN)rI   rh   r   )rn   r   rp   r   rq   test_retry_raise   s
    z&HumanFriendlyTestCase.test_retry_raisec              	      sF    fdd t  dkst| t t dd dd W 5 Q R X dS )	zCTest :func:`~humanfriendly.testing.retry()` based on return values.c                      s"   t  dst dd dS dS d S )Nr   TFrd   )r   r   rp   r   rp   rq   r      s    
z?HumanFriendlyTestCase.test_retry_return.<locals>.success_helperrd   c                   S   s   dS r   rp   rp   rp   rp   rq   <lambda>       z9HumanFriendlyTestCase.test_retry_return.<locals>.<lambda>r]   r   N)rI   rh   r   rB   rn   rp   r   rq   test_retry_return   s    z'HumanFriendlyTestCase.test_retry_returnc              	   C   s   t  }td}t|d|d~}tj|s.ttjtj||sHtt	j
|t	jt	jt	jd}|jdd\}}|jdks~t|dkst|dkstW 5 Q R X 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
        rd   )name
returncodescript)stdinrv   rx   s   hello world
inputs   HELLO WORLD
s   Fake warning
N)rS   rP   rD   ospathisdirrh   isfilejoin
subprocessPopenPIPEcommunicater   )rn   r   r   	directoryprogramrv   rx   rp   rp   rq   test_mocked_program   s    z)HumanFriendlyTestCase.test_mocked_programc              
   C   st   t  D}tj|sttj|d}t|d}|d W 5 Q R X W 5 Q R X tj|r`ttj|rptdS )z7Test :class:`humanfriendly.testing.TemporaryDirectory`.z	some-filewzHello world!N)	rG   r   r   r   rh   r   openrw   exists)rn   r   Ztemporary_filehandlerp   rp   rq   test_temporary_directory   s    z.HumanFriendlyTestCase.test_temporary_directoryc              	   C   s   t  z}tj|t }tj|r(tt| tj|s@ttj|t t }tj|rdtt| tj|s|tW 5 Q R X dS )z+Test :func:`humanfriendly.testing.touch()`.N)rG   r   r   r   rS   r   rh   rL   )rn   r   filenamerp   rp   rq   
test_touch
  s    z HumanFriendlyTestCase.test_touchc              	   C   sh   G dd dt }| }|jdks$tt|dd }||ks>t|jdksLtW 5 Q R X |jdksdtdS )z5Test :class:`humanfriendly.testing.PatchedAttribute`.c                   @   s   e Zd ZdZdS )z;HumanFriendlyTestCase.test_patch_attribute.<locals>.Subjectrd   N)__name__
__module____qualname__my_attributerp   rp   rp   rq   Subject  s   r   rd   r      N)objectr   rh   rE   )rn   r   instancereturn_valuerp   rp   rq   test_patch_attribute  s    z*HumanFriendlyTestCase.test_patch_attributec              	   C   sb   t dd}|d dkstt|dd"}||ks4t|d dksDtW 5 Q R X |d dks^tdS )z0Test :class:`humanfriendly.testing.PatchedItem`.T)my_itemr   FN)ri   rh   rF   )rn   r   r   rp   rp   rq   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 )Nrd   )ru   exitrp   rp   rp   rq   r   .  r   zDHumanFriendlyTestCase.test_run_cli_intercepts_exit.<locals>.<lambda>rd   N)rJ   assertEqualrn   r   r;   rp   rp   rq   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)rJ   run_cli_raise_otherr   r   rp   rp   rq   test_run_cli_intercepts_error1  s    z3HumanFriendlyTestCase.test_run_cli_intercepts_errorc                 C   s
   t  dS )z*run_cli() sample that raises an exception.N)
ValueErrorr   rp   rp   rq   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|   )ru   rv   rw   rp   Zexpected_outputrp   rq   r   =  r   zFHumanFriendlyTestCase.test_run_cli_intercepts_output.<locals>.<lambda>r   N)rS   rJ   r   r   rp   r   rq   test_run_cli_intercepts_output:  s    
z4HumanFriendlyTestCase.test_run_cli_intercepts_outputc                 C   sL   t dd }t dd }| | ks(t| | ks8t| | ksHtdS )zTest the caching decorator.c                   S   s   t   S r|   randomrp   rp   rp   rq   r   D  r   z>HumanFriendlyTestCase.test_caching_decorator.<locals>.<lambda>c                   S   s   t   S r|   r   rp   rp   rp   rq   r   E  r   N)r   rh   )rn   abrp   rp   rq   test_caching_decoratorA  s
    z,HumanFriendlyTestCase.test_caching_decoratorc                 C   s:   t ddkstt dddks"tt dddd	ks6td
S )z*Test :func:`humanfriendly.text.compact()`.z a 

 b za bz*
            %s template notation
        ZSimplezSimple template notationz3
            More {type} template notation
        readable)typezMore readable template notationN)rM   rh   r   rp   rp   rq   test_compactK  s    z"HumanFriendlyTestCase.test_compactc                 C   st   t ddkstt ddks tt ddks0tt ddks@tt ddksPtt ddks`tt ddksptdS )	z6Test :func:`humanfriendly.text.compact_empty_lines()`.fooz	foofoo
barzfoo

barz	foo


barz
foo



barzfoo




barN)rN   rh   r   rp   rp   rq   test_compact_empty_linesU  s    z.HumanFriendlyTestCase.test_compact_empty_linesc                 C   s:   t ddkstt dddks"tt dddd	ks6td
S )z)Test :func:`humanfriendly.text.dedent()`.z
 line 1
  line 2

zline 1
 line 2
z'
            Dedented, %s text
        ZinterpolatedzDedented, interpolated text
z)
            Dedented, {op} text
        	formatted)opzDedented, formatted text
N)rP   rh   r   rp   rp   rq   test_dedentd  s    z!HumanFriendlyTestCase.test_dedentc                 C   sP   t dddkstt dddks$tt ddddks8tt dddd	ksLtd
S )z,Test :func:`humanfriendly.text.pluralize()`.r]   wordz1 wordra   z2 wordsZboxZboxesz1 boxz2 boxesN)rR   rh   r   rp   rp   rq   test_pluralizationn  s    z(HumanFriendlyTestCase.test_pluralizationc              	   C   s`   |  dtd |  dtd | t td W 5 Q R X | t td W 5 Q R X dS )z0Test :func:`humanfriendly.text.generate_slug()`.zsome-random-textzSome Random Text! -N)r   rQ   r   r   r   rp   rp   rq   test_generate_slugu  s    z(HumanFriendlyTestCase.test_generate_slugc              	   C   sV   dD ]}|  dt| qdD ]}|  dt| q| t td W 5 Q R X 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   )rn   valuerp   rp   rq   test_boolean_coercion  s    z+HumanFriendlyTestCase.test_boolean_coercionc              	   C   sl   t d}ttdt|s t|t|ks0ttdt j}|dsJt| t	 tg  W 5 Q R X dS )z,Test :func:`humanfriendly.coerce_pattern()`. ZfoobarZFOOBARN)
recompile
isinstancer   r   rh   
IGNORECASEmatchr   r   )rn   Zempty_patternpatternrp   rp   rq   test_pattern_coercion  s    
z+HumanFriendlyTestCase.test_pattern_coercionc                 C   s  d}|d }|d }|d }|d }dt dddks8td	t d
ddksLtdt dddks`tdt dddksttdt dddkstdt dddkstdt dddkstdt dkstdt dkstdt dkstdt tjkstdt |kstdt dkstdt |d  ks,td!t |ks>td"t |d  ksTtd#t |ksftd$t |d  ks|td%t |kstd&t |d  kstd't |kstd(t |d  kstd)t |d* |d+  |d,  |d-  |d   d ddks
td.t ||d   |d-  |d/  ks4td0t d1ddksJtd2t d1ddks`td3t d4ksrtd5t d6kstd7t d8ddkstd9t d:ddkstd;t d<ddksttj }|tjd=d> }d?t || kstd@S )Az-Test :func:`humanfriendly.format_timespan()`.<         4   z1 nanosecond&.>T)Z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 minutesra   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   rh   mathpidatetimenow	timedelta)rn   minutehourdayweekyearr  Zthenrp   rp   rq   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 5 Q R X d%S )&z,Test :func:`humanfriendly.parse_timespan()`.r   r   Z0sr   Z1nsgbak>Z51nsr   Z1usg'eRC?Z52usr   Z1msr   r   r   r   r   Z5sz	5 secondsx   Z2mr      z3 minz3 minsi0*  z3 hz3 hoursi F Z4dz4 daysi$. z5 wz5 weeks1zN)r   r   r   r   r   rp   rp   rq   test_parse_timespan  s0    z)HumanFriendlyTestCase.test_parse_timespanc              	   C   sR   |  dtd |  dtd |  dtd | t td W 5 Q R X dS )	z(Test :func:`humanfriendly.parse_date()`.)  r      r   r   r   z
2013-06-17)r  r   r  ra   /   rd   z2013-06-17 02:47:42)i  rf      r   r  r  z2016-11-30 00:47:17z
2013-06-XYN)r   r   r   r   r   rp   rp   rq   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 bytesrd   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   rp   rp   rq   test_format_size  s*    z&HumanFriendlyTestCase.test_format_sizec              	   C   sX  |  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 5 Q R X | t td  W 5 Q R X d!S )"z(Test :func:`humanfriendly.parse_size()`.r   Z0Brd   42Z42Br  Z1kr'  Tr(  r  z
1 kilobytei@z69 MBr  r  r  r  r   r  r"  r!  r$  r#  r&  r%  g   ZAz1.5 GBg      Dz1.5 YiBZ1qr   N)r   r   r   r   r   rp   rp   rq   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 metresrd   z1 kmr  15.3 cm/$?z1 cm{Gz?z1 mmr   z1 nmr   N)r   r	   r   rp   rp   rq   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 5 Q R X | t td W 5 Q R X dS )z*Test :func:`humanfriendly.parse_length()`.r   Z0mrd   r,        ?1.5Z42mr  Z1kmr/  r.  r0  Z1cmr   Z1mmr   Z1nmr  r   N)r   r   r   r   r   rp   rp   rq   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]   r3  r2  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   rp   rp   rq   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Z
keep_widthz3.14g-DT!	@N)r   r   r   rp   rp   rq   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   rn   Zfriendly_pathZabsolute_pathrp   rp   rq   test_format_pathL  s    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()`.r9  r:  r;  N)r   r   r   r<  r   r   r=  rp   rp   rq   test_parse_pathR  s    z%HumanFriendlyTestCase.test_parse_pathc                 C   s   dgg}t |td ks tdddgdddgg}t |td	 ksLtdddg}dddgd
ddgg}tt ||td kstddg}ddgddgg}tt ||td kstdS )z8Test :func:`humanfriendly.tables.format_pretty_table()`.zJust one columnzi
            -------------------
            | Just one column |
            -------------------
        rb   rc   Threer   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 oneZ15zRow twoZ300a/  
            ------------------------------------
            | Just a label | Important numbers |
            ------------------------------------
            | Row one      |                15 |
            | Row two      |               300 |
            ------------------------------------
        N)r(   rP   striprh   r2   )rn   datacolumn_namesrp   rp   rq   test_pretty_tablesX  s    
	z(HumanFriendlyTestCase.test_pretty_tablesc                 C   s|   dddg}dddgddd	gg}t t||td
 ks<tdddg}dddgdddgg}t t||td ksxtdS )z8Test :func:`humanfriendly.tables.format_robust_table()`.rb   rc   r@  r   rA  rB  r   r   rC  z
            --------
            One: 1
            Two: 2
            Three: 3
            --------
            One: a
            Two: b
            Three: c
            --------
        Here comes a
multi line column!  
            ------------------
            One: 1
            Two: 2
            Three: 3
            ------------------
            One: a
            Two: b
            Three:
            Here comes a
            multi line column!
            ------------------
        N)r2   r)   rP   rE  rh   rn   rG  rF  rp   rp   rq   test_robust_tables  s    

z(HumanFriendlyTestCase.test_robust_tablesc                 C   s|   dddg}dddgddd	gg}t t||td
 ks<tdddg}dddgdddgg}t t||td ksxtdS )z7Test :func:`humanfriendly.tables.format_smart_table()`.rb   rc   r@  r   rA  rB  r   r   rC  rD  rI  rJ  N)r2   r+   rP   rE  rh   rK  rp   rp   rq   test_smart_tables  s    

z'HumanFriendlyTestCase.test_smart_tablesc                 C   sh   dddg}dddgddd	gg}|  t||td
  dddgddd	gg}|  t|td  dS )z5Test :func:`humanfriendly.tables.format_rst_table()`.rb   rc   r@  r   rA  rB  r   r   rC  z
                ===  ===  =====
                One  Two  Three
                ===  ===  =====
                1    2    3
                a    b    c
                ===  ===  =====
            zm
                =  =  =
                1  2  3
                a  b  c
                =  =  =
            N)r   r*   rP   rstriprK  rp   rp   rq   test_rst_tables  s    


z%HumanFriendlyTestCase.test_rst_tablesc                 C   s   t g dkstt dgdks"tt ddgdks6tt dddgdksLtt dddgddd	ksftt dddgd
ddkstdS )z.Test :func:`humanfriendly.text.concatenate()`.r   r^   r`   zone and twoZthreezone, two and threeor)Zconjunctionzone, two or threeT)Zserial_commazone, two, and threeN)rO   rh   r   rp   rp   rq   test_concatenate  s    z&HumanFriendlyTestCase.test_concatenatec                 C   sr   ddl m} | |dg  | |ddg | |dddg | |ddddg | |d	dddg d
S )z(Test :func:`humanfriendly.text.split()`.r   )splitr   r   zfoo, barbarzfoo, bar, bazbazzfoo,bar,bazN)humanfriendly.textrR  r   )rn   rR  rp   rp   rq   
test_split  s    z HumanFriendlyTestCase.test_splitc              
   C   s   dD ]B\}}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 5 Q R X q| t|jdd t dd
}|dk	st
W 5 Q R X dS )z!Test :func:`humanfriendly.Timer`.)
)r]   r   )ra   	2 seconds)r   r   )r  r   )i  r   )i   r   )iQ r   )i  r   )i:	 r   )i u r   Tr7  z%i.00g@rW  r]   r   r6  )Z	resumablera   z2.00N)r   timer   r   Zelapsed_timestrZroundedsleepnormalize_timestamprangerh   )rn   secondstexttZautomatic_timerZresumable_timeriZtimerrp   rp   rq   
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]   ra   r   r   )progressg?r   c                 S   s   g | ]}|r|qS rp   rp   .0linerp   rp   rq   
<listcomp>  s      z6HumanFriendlyTestCase.test_spinner.<locals>.<listcomp>r   c                 s   s   | ]}d |kV  qdS )rb  Nrp   rh  rp   rp   rq   	<genexpr>  s     z5HumanFriendlyTestCase.test_spinner.<locals>.<genexpr>c                 s   s   | ]}d |kV  qdS )%Nrp   rh  rp   rp   rq   rl    s     N)r   rA   steprX  rZ  cleargetvaluereplacer1   r.   rR  r-   
assertTruerg   allr   sortedset)rn   re  spinnerrg  r;   linesrp   rp   rq   test_spinner  s      z"HumanFriendlyTestCase.test_spinnerc              	   C   s$   t dd td W 5 Q R X 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.
        rb  )rc  r]   N)r@   rX  rZ  r   rp   rp   rq   test_automatic_spinner   s    
z,HumanFriendlyTestCase.test_automatic_spinnerc              
      s0  |  t tg  W 5 Q R X ttj4}ttd| d}t|g|ksNtW 5 Q R X W 5 Q R X tt	ddd  tddgdkstW 5 Q R X tt	ddd  tddgdkstW 5 Q R X tt	dd	d  tddgdkstW 5 Q R X tt	dd
d   tddgdddkstW 5 Q R X dddg tt	d fdd tdddgdks`tW 5 Q R X ddg tt	d fdd  tddddgdkstW 5 Q R X ddg tt	d fdd tdddgdkstW 5 Q R X tt	ddd * |  t
 tdddg W 5 Q R X W 5 Q R X dS )z7Test :func:`humanfriendly.prompts.prompt_for_choice()`.r   zonly one option (shortcut)interactive_promptc                 S   s   dS )Nr   rp   prp   rp   rq   r   :  r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>r   rS  c                 S   s   dS )Nfrp   r{  rp   rp   rq   r   =  r   c                 S   s   dS )NrA  rp   r{  rp   rp   rq   r   @  r   c                 S   s   dS Nr   rp   r{  rp   rp   rq   r   C  r   defaultr   qzc                    s
     dS Nr   rl   r{  repliesrp   rq   r   G  r   rT  r   c                    s
     dS r  r  r{  r  rp   rq   r   K  r   Zquxr,  rA  c                    s
     dS r  r  r{  r  rp   rq   r   O  r   c                 S   s   dS r~  rp   r{  rp   rp   rq   r   R  r   r   rC  N)r   r   r    r   r   devnullrE   ru   rh   r   r   )rn   r   Zonly_optionrp   r  rq   test_prompt_for_choice-  s4    &$
"$"z,HumanFriendlyTestCase.test_prompt_for_choicec                    s  dD ]4t tdfdd tddks.tW 5 Q R X qdD ]4t tdfdd tdd	kshtW 5 Q R X q>d
D ]4}t tddd  td|d|kstW 5 Q R X qxddg t td fdd< tdd&}tddkstd| kstW 5 Q R X W 5 Q R X t tddd T dD ]H\}}tdd.}td|ddksLt|| ks^tW 5 Q R X q"W 5 Q R X t tddd $ | t td W 5 Q R X W 5 Q R X dS )z=Test :func:`humanfriendly.prompts.prompt_for_confirmation()`.)r   ZYesZYESyYrz  c                    s    S r|   rp   r{  replyrp   rq   r   Z  r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>zAre you sure?T)r   ZNoNOnNc                    s    S r|   rp   r{  r  rp   rq   r   ^  r   F)TFc                 S   s   dS r~  rp   r{  rp   rp   rq   r   b  r   r  r   r  c                    s
     dS r  r  r{  r  rp   rq   r   f  r   mergedzthere's no default choicec                 S   s   dS )Nr  rp   r{  rp   rp   rq   r   k  r   ))TzY/n)Fzy/N)Nzy/nc                 S   s   dS r~  rp   r{  rp   rp   rq   r   q  r   N)rE   r   r   rh   rC   get_textr   r   )rn   Zdefault_choicerz   default_valueZexpected_textrp   )r  r  rq   test_prompt_for_confirmationV  s,     $*z2HumanFriendlyTestCase.test_prompt_for_confirmationc                 C   sh   t tjT}ttd|< d}td|d|ks2t| t td W 5 Q R X W 5 Q R X W 5 Q R X 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  rE   ru   r!   rh   r   EOFError)rn   r   r  rp   rp   rq   test_prompt_for_inputu  s    z+HumanFriendlyTestCase.test_prompt_for_inputc                 C   s  t t\}}d|kstt td\}}d|ks2tt td\}}|dksLtt td\}}| dksjttdd}t td	| \}}| t|ksttdd}t td	| d
\}}| t|ddksttdd}t td| \}}| t|kstt|d }t td| \}}| t|ks<tt tdddd\}}| t	d ksjttdd}t td| \}}| t
|kstt td\}}t|tdkstt td\}}t|tdddkstt td\}}t|tdkstt td\}}t|tdks2tt td d!d"d#\}}|d$ksTtt td%\}}|dksptd&d' | D }d(|kstd)|kstd*|kstd+|kstd,|kstd-|kstd.|kstd/S )0z Test the command line interface.zUsage:z--helpz--unsupported-optionr   z--format-number=1234567z	1,234,567r'  r*  z--format-size=%iz--binaryTr(  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-commandZbashz-czsleep 2 && exit 42rd   z--democ                 S   s   g | ]}t |qS rp   )r2   rh  rp   rp   rq   rk    s     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)rJ   r   rh   rE  r   randintr   r	   floatrP   r   intr   r   
splitlines)rn   r   r;   Zrandom_byte_countZ
random_lenZrandom_timespanrw  rp   rp   rq   test_cli  sZ    zHumanFriendlyTestCase.test_clic              	   C   s  t dddttf kstt dddttf ks4tt dddttf ksNtt ddd	ttf kshtt dd
dttf kstt dddttf kstt dddttf kstt dddttf kstt ddddttf kstt dddttf kstt dddttf ks$tt dddttf ks@tt dddttf ks\tt dddttf ksxt| t t dd W 5 Q R X dS ) z1Test :func:`humanfriendly.terminal.ansi_style()`.TZboldz%s1%s)Zfaintz%s2%s)Zitalicz%s3%s)Z	underlinez%s4%s)Zinversez%s7%s)Zstrike_throughz%s9%sZbluecolorz%s34%s)Z
backgroundz%s44%s)r  Z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)r3   r,   r0   rh   r   r   r   rp   rp   rq   test_ansi_style  s     z%HumanFriendlyTestCase.test_ansi_stylec                 C   s\   d}t |t|kstt|dd}||ks0tt |t |ksDtt |t|ksXtdS )z1Test :func:`humanfriendly.terminal.ansi_width()`.WhateverTr  N)rg   r4   rh   r5   )rn   r^  wrappedrp   rp   rq   test_ansi_width  s    z%HumanFriendlyTestCase.test_ansi_widthc                 C   sD   d}|t |kstt |ddts*tt |ddts@tdS )z0Test :func:`humanfriendly.terminal.ansi_wrap()`.r  Tr  N)r5   rh   
startswithr,   endswithr/   rn   r^  rp   rp   rq   test_ansi_wrap  s    z$HumanFriendlyTestCase.test_ansi_wrapc                 C   s  t ddkstt ddks tt ddks0tt ddks@tt ddksPtt d	d
ks`tt dd
ksptt ddkstt ddkstt ddkstt ddkstt ddkstt ddkstt ddkstt ddkstt ddkstt ddkstt ddks&tt dd ks8tt d!dksJtd"d# }d$t d%|d&kshtd$t d'|d&ks~tt d(st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;-))rq  )r^  rp   rp   rq   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>
        N)r?   rh   )rn   r  rp   rp   rq   test_html_to_ansi  sd    z'HumanFriendlyTestCase.test_html_to_ansic              	   C   sL   d}t dd4}t| | |g|j  | g |j  W 5 Q R X dS )z:Test the :func:`humanfriendly.terminal.output()` function.z%Standard output generated by output()Fr  N)rC   r;   r   rv   ry   rx   rn   r^  rz   rp   rp   rq   test_generate_output9  s
    z*HumanFriendlyTestCase.test_generate_outputc              	   C   sL   d}t dd4}t| | g |j  | |g|j  W 5 Q R X dS )z;Test the :func:`humanfriendly.terminal.message()` function.z%Standard error generated by message()Fr  N)rC   r:   r   rv   ry   rx   r  rp   rp   rq   test_generate_messageA  s
    z+HumanFriendlyTestCase.test_generate_messagec              	   C   sb   ddl m} d}|dd>}t| | g |j  | t|ddg| |j W 5 Q R X dS )	z;Test the :func:`humanfriendly.terminal.warning()` function.r   rC   z%Standard error generated by warning()Fr  Zredr  N)	rz   rC   r>   r   rv   ry   r5   ignore_coverage_warningrx   )rn   rC   r^  rz   rp   rp   rq   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 |kr|qS )zno-data-collectedrp   rh  rp   rp   rq   rk  [  s      zAHumanFriendlyTestCase.ignore_coverage_warning.<locals>.<listcomp>)ry   )rn   re  rp   rp   rq   r  R  s    	z-HumanFriendlyTestCase.ignore_coverage_warningc                 C   sx   t ddgkstt dddgks&tt dddgks:tt ddgksLtt ddgks^tt d	dddgksttd
S )z<Test :func:`humanfriendly.terminal.clean_terminal_output()`.r   r   rS  zfoobar
bazrT  zaaaabZabazaaabzfoo
bar
baz


N)r6   rh   r   rp   rp   rq   test_clean_output]  s    z'HumanFriendlyTestCase.test_clean_outputc              	   C   s   t  \}}|dkst|dks"ttj}tj}tj}zt t_t t_t t_t  \}}|dksdt|dkspttjd }z0dtjd< t  \}}|dkst|dkstW 5 |tjd< X W 5 |t_|t_|t_X dS )z9Test :func:`humanfriendly.terminal.find_terminal_size()`.r   PATHr   N)	r8   rh   ru   r   rv   rx   r   r   r<  )rn   rw  columnsZsaved_stdinZsaved_stdoutZsaved_stderrZ
saved_pathrp   rp   rq   test_find_terminal_sizel  s.    




z-HumanFriendlyTestCase.test_find_terminal_sizec                 C   s~   ddl m} ttfD ]d}tjtjfD ]"}|  ||s<tW 5 Q R X q$tt	j
}||r`tW 5 Q R X |t rtqdS )z8Test the functions that check for terminal capabilities.r   r  N)rz   rC   r7   r=   ru   rv   rx   rh   r   r   r  r   )rn   rC   Ztest_streamre  r   rp   rp   rq   test_terminal_capabilities  s    z0HumanFriendlyTestCase.test_terminal_capabilitiesc              	   C   s   t jdd}zPdt jd< ddd tdD }t }t| || ksRt	W 5 Q R X W 5 |dk	rt|t jd< nt jd X dS )z1Test :func:`humanfriendly.terminal.show_pager()`.PAGERNcatr   c                 s   s   | ]}t d V  qdS )   N)rS   )ri  r`  rp   rp   rq   rl    s     z8HumanFriendlyTestCase.test_show_pager.<locals>.<genexpr>r  )
r   r<  rk   rl   r   r\  rC   r<   r  rh   )rn   original_pagerZrandom_textrz   rp   rp   rq   test_show_pager  s    
z%HumanFriendlyTestCase.test_show_pagerc              
      s   dt dkstdt tdddks(tddg}dD ]}tjdd	}zR|tjd< t   |d
kr|t fdd|D stnt fdd|D rtW 5 |d	k	r|tjd< ntjd X q4d	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   s   | ]}| kV  qd S r|   rp   ri  optZcommand_linerp   rq   rl    s     z?HumanFriendlyTestCase.test_get_pager_command.<locals>.<genexpr>c                 3   s   | ]}| kV  qd S r|   rp   r  r  rp   rq   rl    s     )	r9   rh   r5   r   r<  rk   rl   rs  any)rn   Zoptions_specific_to_lessZpagerr  rp   r  rq   test_get_pager_command  s    
z,HumanFriendlyTestCase.test_get_pager_commandc                 C   s"   t tdt dddgkst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.
        ZVALUEZBYTESZSECONDSN)rt  rU   rh   r   rp   rp   rq   test_find_meta_variables  s    
z.HumanFriendlyTestCase.test_find_meta_variablesc                 C   sN   |  d\}}d|kstd|ks&td|ks2td|ks>td|ksJt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_resultrh   rn   Zintroductionoptionsrp   rp   rq   test_parse_usage_simple  s    z-HumanFriendlyTestCase.test_parse_usage_simplec                 C   sp   |  d\}}d|ksttdd |D s0td|ks<td|ksHtd|ksTtd|ks`td	|kslt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.
        r  c                 s   s   | ]}d |kV  qdS )zstill part of the introductionNrp   ri  r|  rp   rp   rq   rl    s     z@HumanFriendlyTestCase.test_parse_usage_tricky.<locals>.<genexpr>r  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  rh   r  r  rp   rp   rq   test_parse_usage_tricky  s    z-HumanFriendlyTestCase.test_parse_usage_trickyc                 C   sf   |  d\}}d|kstd|ks&td|ks2td|ks>td|ksJtd|ksVtd|ksbt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.
        r  zSome introduction goes here.r  z-f, --first-optionzExplanation of first option.z-s, --second-option=WITH,COMMAz/This should be a separate option's description.Nr  r  rp   rp   rq   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 rp   )rE  r  rp   rp   rq   rk  5  s     zKHumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>.<listcomp>Nrp   )ri  rrp   rp   rq   rl  5  s     z@HumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>)tuplerW   rP   r  rp   rp   rq   r  3  s    z-HumanFriendlyTestCase.preprocess_parse_resultc                 C   s   d}t |}t|t|ks t|ds.td}t |}t|t|ksNt||ksZt||rhtd}t |}| }t|d kstt|d kst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]   ra   N)rV   rg   rh   r  r  r,   )rn   Z
usage_textZformatted_textZformatted_linesrp   rp   rq   test_format_usage7  s    z'HumanFriendlyTestCase.test_format_usagec                 C   sN   t ddkstt ddks tdt tdks4ttdd d	D sJtd
S )z0Test :func:`humanfriendly.usage.render_usage()`.zUsage: some-command WITH ARGSz#**Usage:** `some-command WITH ARGS`r  z**Supported options:**z
code-blockz_
            Here comes a shell command:

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

              -n, --dry-run

                Don't change anything.
        N)rX   rP   )ri  tokenrp   rp   rq   rl  [  s   z:HumanFriendlyTestCase.test_render_usage.<locals>.<genexpr>)z`-n`z`--dry-run`N)rX   rh   rP   rs  r   rp   rp   rq   test_render_usageQ  s    z'HumanFriendlyTestCase.test_render_usagec              
   C   sr   t dddd }t }ttd|: |dddks8t| t |ddd W 5 Q R X W 5 Q R X |jsntdS )	z.Test the deprecated_args() decorator function.r   rS  c                  [   s&   | d dkst | ddks"t dS )Nr   rS  )NrS  rd   )rh   rk   )r  rp   rp   rq   test_functione  s    zAHumanFriendlyTestCase.test_deprecated_args.<locals>.test_functionwarnrd   rT  N)r   rY   rE   warningsrh   r   	TypeErrorr   )rn   r  fake_fnrp   rp   rq   test_deprecated_argsc  s    
 z*HumanFriendlyTestCase.test_deprecated_argsc              	   C   sX   t  }ttd|2 tjt }tdd}t||}|jtks@t	W 5 Q R X |j
sTt	dS )@Test that the DeprecationProxy class emits deprecation warnings.r  humanfriendly.text.concatenaterO   N)rY   rE   r  ru   modulesr   ri   r   rO   rh   r   )rn   r  modulealiasesproxyrp   rp   rq   $test_alias_proxy_deprecation_warningq  s    


z:HumanFriendlyTestCase.test_alias_proxy_deprecation_warningc              	   C   sV   t tjdtd8 ttdd dttjt ks8tdt	tksHtW 5 Q R X dS )r  sphinxr  r  rO   N)
rF   ru   r  types
ModuleTyper   r   dirrh   r   r   rp   rp   rq   $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sHtdS )z?Test that aliases can be injected into generated documentation.r  r  Nappwhatr   ro   r  rw  r   )	ru   r  r   r   __doc__r  r"   r   rh   )rn   r  rw  rp   rp   rq   #test_alias_proxy_sphinx_integration  s
    

z9HumanFriendlyTestCase.test_alias_proxy_sphinx_integrationc                 C   s   G dd dt }| }t| t|jd ks0tt|jd ksBtt|jd ksTtt|jd ksftt	|jd ksxttddd|j
ddd	d
ksttddd|jddd	dkstddlm}m} | |st| |rt| |jrt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   rp   rp   rq   __init__  s    zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__init__c                 S   s   dS )z%Documented unofficial special method.Nrp   r   rp   rp   rq   __documented_special_method__  s    z_HumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__documented_special_method__c                 S   s   d S r|   rp   r   rp   rp   rq   __undocumented_special_method__  s    zaHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__undocumented_special_method__c                 S   s   || j |< d S r|   )r  )rn   r   r  rp   rp   rq   add_role  s    zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.add_rolec                 S   s   | j |g | d S r|   )r  rm   append)rn   eventr  rp   rp   rq   connect  s    zIHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.connectc                 S   s   dS )z.Usage: This is not supposed to be reformatted!Nrp   r   rp   rp   rq   bogus_usage  s    zMHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.bogus_usageN)	r   r   r   r  r  r  r  r  r  rp   rp   rp   rq   FakeApp  s   r  Zmanpypizautodoc-process-docstringzautodoc-skip-memberNT)r  r  r   ro   skipr  Fr   )clir  )r   r%   r#   r  rh   r$   r"   r  r&   r'   r  r  humanfriendlyr  r  docstring_is_reformattedr  )rn   r  Zfake_appr  r  rp   rp   rq   test_sphinx_customizations  s@          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  )rT   r  r  listr'   )rn   entityrw  Zsaved_linesrp   rp   rq   r     s        z.HumanFriendlyTestCase.docstring_is_reformattedN)Mr   r   r   r  rr   rt   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+  r-  r1  r4  r5  r8  r>  r?  rH  rL  rM  rO  rQ  rV  ra  rx  ry  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  r  r  r  r  r   rp   rp   rp   rq   rZ      s   *	
	


	2(	$)I
D	*	!
	:rZ   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   r  rp   rp   rq   r[    s    r[  )r]   )vr  r  r  r   r   r   r   ru   rX  r  r   r  r  r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Zhumanfriendly.caser   r   Zhumanfriendly.clir   Zhumanfriendly.compatr   Zhumanfriendly.decoratorsr   Zhumanfriendly.deprecationr   r   r   r   Zhumanfriendly.promptsr   r   r    r!   Zhumanfriendly.sphinxr"   r#   r$   r%   r&   r'   Zhumanfriendly.tablesr(   r)   r*   r+   Zhumanfriendly.terminalr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   Zhumanfriendly.terminal.htmlr?   Zhumanfriendly.terminal.spinnersr@   rA   Zhumanfriendly.testingrB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rU  rM   rN   rO   rP   rQ   rR   rS   rT   Zhumanfriendly.usagerU   rV   rW   rX   ZmockrY   rZ   r[  rp   rp   rp   rq   <module>
   sN   T T4(
          Y