a
    IDg7                    @   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s6J t ttddd
dksRJ t ttddddddd	kstJ t tddddd	ksJ tg d}t |d	ksJ tdd}|ddksJ tdd}|ddksJ t |dksJ tdd}|ddksJ |dd |d dks0J tdd}d|v sHJ tdd}|d= t |dksjJ 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   ZTWO*   )existing_keyZExisting_Keyr   Z	other_key   Z	Other_Keyrg   N)lenr   dictfromkeysgetpop
setdefault)selfobj rq   d/mounts/lovelace/software/anaconda3/envs/paleomix/lib/python3.9/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   ri   )ro   ZpoliteZrudemappingrq   rq   rr   test_case_insensitive_key   s    z/HumanFriendlyTestCase.test_case_insensitive_keyc                 C   sj   t  P}tjd tjd |j dgks4J |j dgksHJ W d   n1 s\0    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)ro   capturerrq   rq   rr   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)NotImplementedErrorrq   rq   rq   rr   test_fn   s    z9HumanFriendlyTestCase.test_skip_on_raise.<locals>.test_fnN)rM   r~   assertRaisesunittestZSkipTest)ro   r   Zdecorator_fnZdecorated_fnrq   rq   rr   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   n1 sP0    Y  dS )	zFTest :func:`~humanfriendly.testing.retry()` based on assertion errors.c                      s(   t  ds t dd ds$J ndS d S )N
was_calledTFyeshasattrsetattrrq   success_helperrq   rr   r      s    

z>HumanFriendlyTestCase.test_retry_raise.<locals>.success_helperr   c                   S   s   dsJ d S NFrq   rq   rq   rq   rr   failure_helper   s    z>HumanFriendlyTestCase.test_retry_raise.<locals>.failure_helperr_   timeoutN)rK   r   AssertionError)ro   r   rq   r   rr   test_retry_raise   s
    z&HumanFriendlyTestCase.test_retry_raisec                    sZ    fdd t  dksJ | t  t dd dd W d   n1 sL0    Y  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   TFrf   r   rq   r   rq   rr   r      s    
z?HumanFriendlyTestCase.test_retry_return.<locals>.success_helperrf   c                   S   s   dS r   rq   rq   rq   rq   rr   <lambda>       z9HumanFriendlyTestCase.test_retry_return.<locals>.<lambda>r_   r   N)rK   r   rD   ro   rq   r   rr   test_retry_return   s    z'HumanFriendlyTestCase.test_retry_returnc                 C   s   t  }td}t|d|d}tj|s.J tjtj||sHJ tj	|tj
tj
tj
d}|jdd\}}|jdks~J |dksJ |dksJ W d	   n1 s0    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
        rf   )name
returncodescript)stdinrw   ry   s   hello world
inputs   HELLO WORLD
s   Fake warning
N)rU   rR   rF   ospathisdirisfilejoin
subprocessPopenPIPEcommunicater   )ro   r   r   	directoryprogramrw   ry   rq   rq   rr   test_mocked_program   s    z)HumanFriendlyTestCase.test_mocked_programc              	   C   s   t  b}tj|sJ tj|d}t|d}|d W d   n1 sP0    Y  W d   n1 sn0    Y  tj|rJ tj|rJ dS )z7Test :class:`humanfriendly.testing.TemporaryDirectory`.z	some-filewzHello world!N)rI   r   r   r   r   openrx   exists)ro   r   Ztemporary_filehandlerq   rq   rr   test_temporary_directory   s    Fz.HumanFriendlyTestCase.test_temporary_directoryc                 C   s   t  }tj|t }tj|r(J t| tj|s@J tj|t t }tj|rdJ t| tj|s|J W d   n1 s0    Y  dS )z+Test :func:`humanfriendly.testing.touch()`.N)rI   r   r   r   rU   r   rN   )ro   r   filenamerq   rq   rr   
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sLJ W d   n1 s`0    Y  |jdksxJ dS )z5Test :class:`humanfriendly.testing.PatchedAttribute`.c                   @   s   e Zd ZdZdS )z;HumanFriendlyTestCase.test_patch_attribute.<locals>.Subjectrf   N)__name__
__module____qualname__my_attributerq   rq   rq   rr   Subject  s   r   rf   r      N)objectr   rG   )ro   r   instancereturn_valuerq   rq   rr   test_patch_attribute  s    ,z*HumanFriendlyTestCase.test_patch_attributec                 C   sv   t dd}|d du sJ t|dd,}||u s4J |d du sDJ W d   n1 sX0    Y  |d du srJ dS )z0Test :class:`humanfriendly.testing.PatchedItem`.T)my_itemr   FN)rj   rH   )ro   r   r   rq   rq   rr   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 )Nrf   )rv   exitrq   rq   rq   rr   r   .  r   zDHumanFriendlyTestCase.test_run_cli_intercepts_exit.<locals>.<lambda>rf   N)rL   assertEqualro   r   r<   rq   rq   rr   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   rq   rq   rr   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   rq   rq   rr   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}   )rv   rw   rx   rq   Zexpected_outputrq   rr   r   =  r   zFHumanFriendlyTestCase.test_run_cli_intercepts_output.<locals>.<lambda>r   N)rU   rL   r   r   rq   r   rr   test_run_cli_intercepts_output:  s    
z4HumanFriendlyTestCase.test_run_cli_intercepts_outputc                 C   sL   t dd }t dd }| | ks(J | | ks8J | | ksHJ dS )zTest the caching decorator.c                   S   s   t   S r}   randomrq   rq   rq   rr   r   D  r   z>HumanFriendlyTestCase.test_caching_decorator.<locals>.<lambda>c                   S   s   t   S r}   r   rq   rq   rq   rr   r   E  r   Nr   )ro   abrq   rq   rr   test_caching_decoratorA  s
    z,HumanFriendlyTestCase.test_caching_decoratorc                 C   s:   t ddksJ t dddks"J t dddd	ks6J 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)rO   r   rq   rq   rr   test_compactK  s    z"HumanFriendlyTestCase.test_compactc                 C   st   t ddksJ t ddks J t ddks0J t ddks@J t ddksPJ t ddks`J t ddkspJ dS )	z6Test :func:`humanfriendly.text.compact_empty_lines()`.fooz	foofoo
barzfoo

barz	foo


barz
foo



barzfoo




barN)rP   r   rq   rq   rr   test_compact_empty_linesU  s    z.HumanFriendlyTestCase.test_compact_empty_linesc                 C   s:   t ddksJ t dddks"J t dddd	ks6J 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)rR   r   rq   rq   rr   test_dedentd  s    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s8J t dddd	ksLJ d
S )z,Test :func:`humanfriendly.text.pluralize()`.r_   wordz1 wordrc   z2 wordsboxZboxesz1 boxz2 boxesN)rT   r   rq   rq   rr   test_pluralizationn  s    z(HumanFriendlyTestCase.test_pluralizationc                 C   s   |  dtd |  dtd | t td W d   n1 sH0    Y  | t td W d   n1 sz0    Y  dS )z0Test :func:`humanfriendly.text.generate_slug()`.zsome-random-textzSome Random Text! N-)r   rS   r   r   r   rq   rq   rr   test_generate_slugu  s    &z(HumanFriendlyTestCase.test_generate_slugc                 C   sj   dD ]}|  dt| qdD ]}|  dt| q| t td W d   n1 s\0    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   )ro   valuerq   rq   rr   test_boolean_coercion  s    z+HumanFriendlyTestCase.test_boolean_coercionc                 C   s   t d}ttdt|s J |t|u s0J tdt j}|dsJJ | t tg  W d   n1 sr0    Y  dS )z,Test :func:`humanfriendly.coerce_pattern()`. ZfoobarZFOOBARN)	recompile
isinstancer   r   
IGNORECASEmatchr   r   )ro   Zempty_patternpatternrq   rq   rr   test_pattern_coercion  s    
z+HumanFriendlyTestCase.test_pattern_coercionc                 C   s  d}|d }|d }|d }|d }dt dddks8J d	t d
ddksLJ dt dddks`J dt dddkstJ dt dddksJ dt dddksJ dt dddksJ dt dksJ dt dksJ dt dksJ dt tjksJ dt |ksJ dt dksJ dt |d  ks,J d!t |ks>J d"t |d  ksTJ d#t |ksfJ d$t |d  ks|J 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s
J d.t ||d   |d-  |d/  ks4J d0t d1ddksJJ d2t d1ddks`J d3t d4ksrJ d5t d6ksJ d7t d8ddksJ d9t d:ddksJ d;t d<ddksJ tj }|tjd=d> }d?t || ksJ 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 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)ro   minutehourdayweekyearr  Zthenrq   rq   rr   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%   n1 s0    Y  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   rq   rq   rr   test_parse_timespan  s0    z)HumanFriendlyTestCase.test_parse_timespanc                 C   sf   |  dtd |  dtd |  dtd | t td W d   n1 sX0    Y  dS )	z(Test :func:`humanfriendly.parse_date()`.)  r     r   r   r   z
2013-06-17)r  r  r  rc   /   rf   z2013-06-17 02:47:42)i  rh      r   r  r  z2016-11-30 00:47:17z
2013-06-XYN)r   r   r   r   r   rq   rq   rr   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 bytesrf   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   rq   rq   rr   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 sB0    Y  | t td! W d    n1 sv0    Y  d S )"z(Test :func:`humanfriendly.parse_size()`.r   Z0Brf   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1qNr   )r   r   r   r   r   rq   rq   rr   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 metresrf   z1 kmr  15.3 cm/$?z1 cm{Gz?z1 mmr   z1 nmr   N)r   r	   r   rq   rq   rr   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 s0    Y  | t td W d   n1 s0    Y  dS )z*Test :func:`humanfriendly.parse_length()`.r   Z0mrf   r0        ?1.5Z42mr  Z1kmr3  r2  r4  Z1cmr   Z1mmr   Z1nmr  Nr   )r   r   r   r   r   rq   rq   rr   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_   r7  r6  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   rq   rq   rr   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   rq   rq   rr   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   ro   Zfriendly_pathZabsolute_pathrq   rq   rr   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()`.r=  r>  r?  N)r   r   r   r@  r   r   rA  rq   rq   rr   test_parse_pathR  s    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sHJ 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sJ dS )z8Test :func:`humanfriendly.tables.format_pretty_table()`.zJust one columnzi
            -------------------
            | Just one column |
            -------------------
        rd   re   Z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 oneZ15zRow twoZ300a/  
            ------------------------------------
            | Just a label | Important numbers |
            ------------------------------------
            | Row one      |                15 |
            | Row two      |               300 |
            ------------------------------------
        N)r)   rR   stripr3   )ro   datacolumn_namesrq   rq   rr   test_pretty_tablesX  s    	z(HumanFriendlyTestCase.test_pretty_tablesc                 C   sp   g d}g dg dg}t t||td ks6J g d}g dg dg}t t||td kslJ dS )z8Test :func:`humanfriendly.tables.format_robust_table()`.rD  rE  rH  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   rK  ro   rM  rL  rq   rq   rr   test_robust_tables  s    z(HumanFriendlyTestCase.test_robust_tablesc                 C   sp   g d}g dg dg}t t||td ks6J g d}g dg dg}t t||td kslJ dS )z7Test :func:`humanfriendly.tables.format_smart_table()`.rD  rE  rH  rJ  rO  rP  N)r3   r,   rR   rK  rQ  rq   rq   rr   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()`.rD  rE  rH  z
                ===  ===  =====
                One  Two  Three
                ===  ===  =====
                1    2    3
                a    b    c
                ===  ===  =====
            zm
                =  =  =
                1  2  3
                a  b  c
                =  =  =
            N)r   r+   rR   rstriprQ  rq   rq   rr   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s6J t g ddksJJ t g dddd	ksbJ t g dd
ddkszJ dS )z.Test :func:`humanfriendly.text.concatenate()`.r   r`   rb   zone and two)r`   rb   threezone, two and threeor)Zconjunctionzone, two or threeT)Zserial_commazone, two, and threeNrQ   r   rq   rq   rr   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.textrZ  r   )ro   rZ  rq   rq   rr   
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 ]2}| td W d   q1 s0    Y  q| t|jdd t dd
}|dusJ W d   n1 s0    Y  dS )z!Test :func:`humanfriendly.Timer`.)
)r_   r   )rc   	2 seconds)r   r   )r  r   )i  r   )i   r   )iQ r   )i  r   )i:	 r   )i u r   Tr;  z%i.00g@r`  r_   r   r:  )Z	resumablerc   Nz2.00)
r   timer   r   Zelapsed_timestrZroundedsleepnormalize_timestamprange)ro   secondstexttZautomatic_timerZresumable_timeriZtimerrq   rq   rr   
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 rq   rq   .0linerq   rq   rr   
<listcomp>  r   z6HumanFriendlyTestCase.test_spinner.<locals>.<listcomp>r   c                 s   s   | ]}d |v V  qdS )rk  Nrq   rq  rq   rq   rr   	<genexpr>  r   z5HumanFriendlyTestCase.test_spinner.<locals>.<genexpr>c                 s   s   | ]}d |v V  qdS )%Nrq   rq  rq   rq   rr   ru    r   N)r   rC   stepra  rc  cleargetvaluereplacer2   r/   rZ  r.   Z
assertTrueri   allr   sortedset)ro   rn  spinnerrp  r<   linesrq   rq   rr   test_spinner  s    z"HumanFriendlyTestCase.test_spinnerc                 C   s8   t dd td W d   n1 s*0    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.
        rk  )rl  r_   N)rB   ra  rc  r   rq   rq   rr   test_automatic_spinner   s    
z,HumanFriendlyTestCase.test_automatic_spinnerc              	      s(  |  t tg  W d   n1 s(0    Y  ttjR}ttd|& d}t|g|ksbJ W d   n1 sv0    Y  W d   n1 s0    Y  ttddd $ tddgdksJ W d   n1 s0    Y  ttdd	d & tddgdks
J W d   n1 s 0    Y  ttdd
d & tddgdksRJ W d   n1 sh0    Y  ttddd * tddgdddksJ W d   n1 s0    Y  g d ttd fdd& tg ddksJ W d   n1 s0    Y  ddg ttd fdd& tg ddksFJ W d   n1 s\0    Y  ddg ttd fdd& tg ddksJ W d   n1 s0    Y  ttddd H |  t	 tg d W d   n1 s0    Y  W d   n1 s0    Y  dS )z7Test :func:`humanfriendly.prompts.prompt_for_choice()`.Nr   zonly one option (shortcut)interactive_promptc                 S   s   dS )Nr   rq   prq   rq   rr   r   :  r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>r   r[  c                 S   s   dS )Nfrq   r  rq   rq   rr   r   =  r   c                 S   s   dS )NrF  rq   r  rq   rq   rr   r   @  r   c                 S   s   dS Nr   rq   r  rq   rq   rr   r   C  r   default)r   qzc                    s
     dS Nr   rm   r  repliesrq   rr   r   G  r   r\  r]  r   r  c                    s
     dS r  r  r  r  rq   rr   r   K  r   )r   r[  r]  quxr  r0  rF  c                    s
     dS r  r  r  r  rq   rr   r   O  r   c                 S   s   dS r  rq   r  rq   rq   rr   r   R  r   rH  )
r   r   r!   r   r   devnullrG   rv   r   r   )ro   r   Zonly_optionrq   r  rr   test_prompt_for_choice-  s4    &N266:666z,HumanFriendlyTestCase.test_prompt_for_choicec              
      sx  dD ]Ht tdfdd  tddu s.J W d   q1 sB0    Y  qdD ]Ht tdfd	d  tdd
u s|J W d   qR1 s0    Y  qRdD ]H}t tddd $ td|d|u sJ W d   q1 s0    Y  qddg t td fdd` tdd4}tddu s&J d| v s8J W d   n1 sN0    Y  W d   n1 sn0    Y  t tddd t dD ]^\}}tdd8}td|ddu sJ || v sJ W d   n1 s0    Y  qW d   n1 s0    Y  t tddd D | t td W d   n1 sJ0    Y  W d   n1 sj0    Y  dS )z=Test :func:`humanfriendly.prompts.prompt_for_confirmation()`.)r   ZYesZYESyYr  c                    s    S r}   rq   r  replyrq   rr   r   Z  r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>zAre you sure?TN)r   ZNoNOnNc                    s    S r}   rq   r  r  rq   rr   r   ^  r   F)TFc                 S   s   dS r  rq   r  rq   rq   rr   r   b  r   r  r   r  c                    s
     dS r  r  r  r  rq   rr   r   f  r   Zmergedzthere's no default choicec                 S   s   dS )Nr  rq   r  rq   rq   rr   r   k  r   ))TzY/n)Fzy/N)Nzy/nc                 S   s   dS r  rq   r  rq   rq   rr   r   q  r   )rG   r   r    rE   get_textr   r   )ro   Zdefault_choicer{   default_valueZexpected_textrq   )r  r  rr   test_prompt_for_confirmationV  s,    004RVz2HumanFriendlyTestCase.test_prompt_for_confirmationc              
   C   s   t tj}ttd|Z d}td|d|ks2J | t td W d   n1 sZ0    Y  W d   n1 sx0    Y  W d   n1 s0    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   rv   r"   r   EOFError)ro   r   r  rq   rq   rr   test_prompt_for_inputu  s    z+HumanFriendlyTestCase.test_prompt_for_inputc                 C   s  t t\}}d|v sJ t td\}}d|v s2J t td\}}|dksLJ t td\}}| dksjJ tdd}t td	| \}}| t|ksJ tdd}t td	| d
\}}| t|ddksJ tdd}t td| \}}| t|ksJ t|d }t td| \}}| t|ks<J t tdddd\}}| td ksjJ 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s2J t td d!d"d#\}}|d$ksTJ t td%\}}|dkspJ d&d' | D }d(|v sJ d)|v sJ d*|v sJ d+|v sJ d,|v sJ d-|v sJ d.|v sJ 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-commandbashz-czsleep 2 && exit 42rf   z--democ                 S   s   g | ]}t |qS rq   )r3   rq  rq   rq   rr   rt    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   rK  r   randintr   r	   floatrR   r   intr   r   
splitlines)ro   r   r<   Zrandom_byte_countZ
random_lenZrandom_timespanr  rq   rq   rr   test_cli  sZ    zHumanFriendlyTestCase.test_clic                 C   s  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sNJ t ddd	ttf kshJ 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dttf ksJ 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s\J t dddttf ksxJ | t t dd W d   n1 s0    Y  dS ) z1Test :func:`humanfriendly.terminal.ansi_style()`.Tboldz%s1%s)Zfaintz%s2%s)italicz%s3%s)	underlinez%s4%s)Zinversez%s7%s)Z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   rq   rq   rr   test_ansi_style  s     z%HumanFriendlyTestCase.test_ansi_stylec                 C   s\   d}t |t|ksJ t|dd}||ks0J t |t |ksDJ t |t|ksXJ dS )z1Test :func:`humanfriendly.terminal.ansi_width()`.WhateverTr  N)ri   r5   r6   )ro   rg  wrappedrq   rq   rr   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   ro   rg  rq   rq   rr   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s0J t ddks@J t ddksPJ t d	d
ks`J t dd
kspJ 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 t ddksJ t ddksJ t ddksJ t ddksJ t ddksJ t ddks&J t dd ks8J t d!dksJJ d"d# }d$t d%|d&vshJ d$t d'|d&v s~J 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;-))rz  )rg  rq   rq   rr   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@   )ro   r  rq   rq   rr   test_html_to_ansi  sd    z'HumanFriendlyTestCase.test_html_to_ansic                 C   s`   d}t dd>}t| | |g|j  | g |j  W d   n1 sR0    Y  dS )z:Test the :func:`humanfriendly.terminal.output()` function.z%Standard output generated by output()Fr  N)rE   r<   r   rw   rz   ry   ro   rg  r{   rq   rq   rr   test_generate_output9  s
    z*HumanFriendlyTestCase.test_generate_outputc                 C   s`   d}t dd>}t| | g |j  | |g|j  W d   n1 sR0    Y  dS )z;Test the :func:`humanfriendly.terminal.message()` function.z%Standard error generated by message()Fr  N)rE   r;   r   rw   rz   ry   r  rq   rq   rr   test_generate_messageA  s
    z+HumanFriendlyTestCase.test_generate_messagec                 C   sv   ddl m} d}|ddH}t| | g |j  | t|ddg| |j W d   n1 sh0    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   rw   rz   r6   ignore_coverage_warningry   )ro   rE   rg  r{   rq   rq   rr   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-collectedrq   rq  rq   rq   rr   rt  [  r   zAHumanFriendlyTestCase.ignore_coverage_warning.<locals>.<listcomp>)rz   )ro   rn  rq   rq   rr   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sLJ t ddgks^J t d	g d
ksrJ dS )z<Test :func:`humanfriendly.terminal.clean_terminal_output()`.r   r   r[  zfoobar
bazr]  zaaaabZabazaaabzfoo
bar
baz


r\  N)r7   r   rq   rq   rr   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}zt t_t t_t t_t  \}}|dksdJ |dkspJ tjd }z:dtjd< t  \}}|dksJ |dksJ W |tjd< n|tjd< 0 W |t_|t_|t_n|t_|t_|t_0 dS )z9Test :func:`humanfriendly.terminal.find_terminal_size()`.r   PATHr   N)r9   rv   r   rw   ry   r   r   r@  )ro   r  columnsZsaved_stdinZsaved_stdoutZsaved_stderrZ
saved_pathrq   rq   rr   test_find_terminal_sizel  s4    




z-HumanFriendlyTestCase.test_find_terminal_sizec              
   C   s   ddl m} ttfD ]}tjtjfD ]6}|  ||s<J W d   q$1 sP0    Y  q$ttj	}||rtJ W d   n1 s0    Y  |t
 rJ qdS )z8Test the functions that check for terminal capabilities.r   r  N)r{   rE   r8   r>   rv   rw   ry   r   r   r  r   )ro   rE   Ztest_streamrn  r   rq   rq   rr   test_terminal_capabilities  s    ,*z0HumanFriendlyTestCase.test_terminal_capabilitiesc              	   C   s   t jdd}zdt jd< ddd tdD }t (}t| || v sRJ W d   n1 sf0    Y  W |dur|t jd< qt jd n"|dur|t jd< nt jd 0 dS )z1Test :func:`humanfriendly.terminal.show_pager()`.PAGERNcatr   c                 s   s   | ]}t d V  qdS )   N)rU   )rr  ri  rq   rq   rr   ru    r   z8HumanFriendlyTestCase.test_show_pager.<locals>.<genexpr>r  )	r   r@  rl   r   re  rE   r=   r  rm   )ro   original_pagerZrandom_textr{   rq   rq   rr   test_show_pager  s    
0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 ]}tjdd	}zr|tjd< t   |d
kr|t fdd|D sJ nt fdd|D rJ W |d	ur|tjd< qtjd q4|d	ur|tjd< ntjd 0 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   | ]}| v V  qd S r}   rq   rr  optZcommand_linerq   rr   ru    r   z?HumanFriendlyTestCase.test_get_pager_command.<locals>.<genexpr>c                 3   s   | ]}| v V  qd S r}   rq   r  r  rq   rr   ru    r   )r:   r6   r   r@  rl   r{  anyrm   )ro   Zoptions_specific_to_lesspagerr  rq   r  rr   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.
        )ZVALUEZBYTESZSECONDSN)r|  rW   r   rq   rq   rr   test_find_meta_variables  s    

z.HumanFriendlyTestCase.test_find_meta_variablesc                 C   sN   |  d\}}d|v sJ d|v s&J d|v s2J d|v s>J d|v sJJ 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ro   Zintroductionoptionsrq   rq   rr   test_parse_usage_simple  s    z-HumanFriendlyTestCase.test_parse_usage_simplec                 C   sp   |  d\}}d|v sJ tdd |D s0J d|v s<J d|v sHJ d|v sTJ d|v s`J d	|v slJ 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 |v V  qdS )zstill part of the introductionNrq   rr  r  rq   rq   rr   ru    r   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  r  r  rq   rq   rr   test_parse_usage_tricky  s    z-HumanFriendlyTestCase.test_parse_usage_trickyc                 C   sf   |  d\}}d|v sJ d|v s&J d|v s2J d|v s>J d|v sJJ d|v sVJ d|v sbJ 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  rq   rq   rr   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 rq   )rK  r  rq   rq   rr   rt  5  r   zKHumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>.<listcomp>Nrq   )rr  rrq   rq   rr   ru  5  r   z@HumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>)tuplerY   rR   r  rq   rq   rr   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sNJ ||v sZJ ||rhJ d}t |}| }t|d v sJ t|d vsJ 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   ri   r  r  r-   )ro   Z
usage_textZformatted_textZformatted_linesrq   rq   rr   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 s4J tdd d	D sJJ 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 v V  qdS )zm
            Supported options:

              -n, --dry-run

                Don't change anything.
        N)rZ   rR   )rr  tokenrq   rq   rr   ru  [  s   z:HumanFriendlyTestCase.test_render_usage.<locals>.<genexpr>)z`-n`z`--dry-run`N)rZ   rR   r{  r   rq   rq   rr   test_render_usageQ  s    z'HumanFriendlyTestCase.test_render_usagec              	   C   s   t dddd }t }ttd|X |dddks8J | t |ddd W d   n1 sd0    Y  W d   n1 s0    Y  |jsJ 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[  rf   )rl   )r  rq   rq   rr   test_functione  s    zAHumanFriendlyTestCase.test_deprecated_args.<locals>.test_functionwarnrf   r]  N)r   r[   rG   warningsr   	TypeErrorr   )ro   r  fake_fnrq   rq   rr   test_deprecated_argsc  s    
H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 sT0    Y  |j	shJ dS )@Test that the DeprecationProxy class emits deprecation warnings.r  humanfriendly.text.concatenaterX  N)
r[   rG   r  rv   modulesr   rj   r   rQ   r   )ro   r  modulealiasesproxyrq   rq   rr   $test_alias_proxy_deprecation_warningq  s    


,z:HumanFriendlyTestCase.test_alias_proxy_deprecation_warningc                 C   sj   t tjdtdB ttdd dttjt v s8J dttv sHJ W d   n1 s\0    Y  dS )r  sphinxr  rX  rQ   N)	rH   rv   r  types
ModuleTyper   r   dirr   r   rq   rq   rr   $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sHJ dS )z?Test that aliases can be injected into generated documentation.r  rX  Nappwhatr   rp   r  r  r   )rv   r  r   r   __doc__r  r#   r   )ro   r  r  rq   rq   rr   #test_alias_proxy_sphinx_integration  s
    

z9HumanFriendlyTestCase.test_alias_proxy_sphinx_integrationc                 C   s   G dd dt }| }t| t|jd ks0J t|jd ksBJ t|jd v sTJ t|jd v sfJ t|jd v sxJ tddd|j	ddd	d
u sJ tddd|j
ddd	du sJ ddlm}m} | |sJ | |rJ | |jrJ 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   rq   rq   rr   __init__  s    zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__init__c                 S   s   dS )z%Documented unofficial special method.Nrq   r   rq   rq   rr   __documented_special_method__  s    z_HumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__documented_special_method__c                 S   s   d S r}   rq   r   rq   rq   rr   __undocumented_special_method__  s    zaHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__undocumented_special_method__c                 S   s   || j |< d S r}   )r  )ro   r   r  rq   rq   rr   add_role  s    zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.add_rolec                 S   s   | j |g | d S r}   )r  rn   append)ro   eventr  rq   rq   rr   connect  s    zIHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.connectc                 S   s   dS )z.Usage: This is not supposed to be reformatted!Nrq   r   rq   rq   rr   bogus_usage  s    zMHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.bogus_usageN)	r   r   r   r  r  r  r  r	  r
  rq   rq   rq   rr   FakeApp  s   r  manpypizautodoc-process-docstringzautodoc-skip-memberNT)r  r  r   rp   skipr  Fr   )clir  )r   r&   r$   r  r%   r#   r  r'   r(   r  r  humanfriendlyr  r  docstring_is_reformattedr
  )ro   r  Zfake_appr  r  rq   rq   rr   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(   )ro   entityr  Zsaved_linesrq   rq   rr   r    s    z.HumanFriendlyTestCase.docstring_is_reformattedN)Mr   r   r   r  rs   ru   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  r5  r8  r9  r<  rB  rC  rN  rR  rS  rU  rY  r_  rj  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   r  r  rq   rq   rq   rr   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   r  rq   rq   rr   rd    s    rd  )r_   )vr  r
  r  r   r   r   r   rv   ra  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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   Zhumanfriendly.terminal.htmlrA   Zhumanfriendly.terminal.spinnersrB   rC   Zhumanfriendly.testingrD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r^  rO   rP   rQ   rR   rS   rT   rU   rV   Zhumanfriendly.usagerW   rX   rY   rZ   Zmockr[   r\   rd  rq   rq   rq   rr   <module>
   sN   T T4(
          Y