
    @g7                    ^   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e_      ZtddZuy)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                      e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLyK)LHumanFriendlyTestCasez-Container for the `humanfriendly` test suite.c                 z   t        t        ddg            dk(  sJ t        t        ddgdd            d	k(  sJ t        t        t        dd
                  dk(  sJ t        t        t        dd      dd            d	k(  sJ t        t        ddd            d	k(  sJ t        j                  g d      }t        |      d	k(  sJ t        d      }|j	                  d      dk(  sJ t        d      }|j                  d      dk(  sJ t        |      dk(  sJ t        d      }|j                  d      dk(  sJ |j                  dd       |d   dk(  sJ t        d      }d|v sJ t        d      }|d= t        |      dk(  sJ t        d      }|d   dk(  sJ t        d      }d|d<   |d   dk(  sJ y)z#Test the CaseInsensitiveDict class.)keyT)KEYF   )oneT)ONEFFT)rc   two   )r`   ra   )rc   rd   )rc   rd   re   )Onerc   rd   Twore   TWO*   )existing_keyExisting_Keyr   	other_key   	Other_Keyrk   N)lenr   dictfromkeysgetpop
setdefault)selfobjs     H/var/www/openai/venv/lib/python3.12/site-packages/humanfriendly/tests.pytest_case_insensitive_dictz0HumanFriendlyTestCase.test_case_insensitive_dict   s    &~'FGHAMMM&~'FEW[\]abbbb&t%'@ABaGGG&t%'@eQUVW[\\\\&4UEF!KKK!**+UV3x1}}!r2ww~&",,,!r2ww~&",,,3x1}}!r2~~n-333{B';2%%%!r2$$$!r23x1}}!r2>"b(((!r2 N>"b(((    c                 v    t        d      }t        d      }||k(  sJ i }d||<   d||<   t        |      dk(  sJ y)z"Test the CaseInsensitiveKey class.zPlease don't shoutzPLEASE DON'T SHOUTrb   rf   N)r   rp   )rv   politerudemappings       rx   test_case_insensitive_keyz/HumanFriendlyTestCase.test_case_insensitive_key   sO     $$89!"67~~7|q   rz   c                 @   t               5 }t        j                  j                  d       t        j                  j                  d       |j                  j                         dgk(  sJ |j                  j                         dgk(  sJ 	 ddd       y# 1 sw Y   yxY w)zTest the CaptureOutput class.zSomething for stdout.
zAnd for stderr.
zSomething for stdout.zAnd for stderr.N)rF   sysstdoutwritestderr	get_lines)rv   capturers     rx   test_capture_outputz)HumanFriendlyTestCase.test_capture_output   sw    _JJ67JJ01??,,.3J2KKKK??,,.3D2EEEE	 __s   A?BBc                     d }t        t              } ||      }| j                  t        |       | j                  t        j                  |       y)z#Test the skip_on_raise() decorator.c                      t               N)NotImplementedError rz   rx   test_fnz9HumanFriendlyTestCase.test_skip_on_raise.<locals>.test_fn   s    %''rz   N)rN   r   assertRaisesunittestSkipTest)rv   r   decorator_fndecorated_fns       rx   test_skip_on_raisez(HumanFriendlyTestCase.test_skip_on_raise   sC    	($%89#G,-w7(++\:rz   c                     fdt              dk(  sJ d }| j                  t              5  t        |d       ddd       y# 1 sw Y   yxY w)zFTest :func:`~humanfriendly.testing.retry()` based on assertion errors.c                  <    t         d      st         dd       J y)N
was_calledTyeshasattrsetattrsuccess_helpers   rx   r   z>HumanFriendlyTestCase.test_retry_raise.<locals>.success_helper   s!    ><8d;urz   r   c                      J r   r   r   rz   rx   failure_helperz>HumanFriendlyTestCase.test_retry_raise.<locals>.failure_helper   s    5rz   rb   timeoutN)rL   r   AssertionError)rv   r   r   s     @rx   test_retry_raisez&HumanFriendlyTestCase.test_retry_raise   sF    	 ^$---	~..!, /..s   AAc                     fdt              dk(  sJ | j                  t              5  t        d d       ddd       y# 1 sw Y   yxY w)zCTest :func:`~humanfriendly.testing.retry()` based on return values.c                  :    t         d      st         dd       yy)Nr   TFrj   r   r   s   rx   r   z?HumanFriendlyTestCase.test_retry_return.<locals>.success_helper   s!    ><8d; rz   rj   c                       y)NFr   r   rz   rx   <lambda>z9HumanFriendlyTestCase.test_retry_return.<locals>.<lambda>   s    %rz   rb   r   N)rL   r   rE   )rv   r   s    @rx   test_retry_returnz'HumanFriendlyTestCase.test_retry_return   sB    	 ^$***/0-+ 100s   AAc                 $   t               }t        d      }t        |d|      5 }t        j                  j                  |      sJ t        j                  j                  t        j                  j                  ||            sJ t        j                  |t        j                  t        j                  t        j                        }|j                  d      \  }}|j                  dk(  sJ |dk(  sJ |dk(  sJ 	 d	d	d	       y	# 1 sw Y   y	xY w)
z2Test :class:`humanfriendly.testing.MockedProgram`.z
            # This goes to stdout.
            tr a-z A-Z
            # This goes to stderr.
            echo Fake warning >&2
        rj   )name
returncodescript)stdinr   r   s   hello world
inputs   HELLO WORLD
s   Fake warning
N)rV   rS   rG   ospathisdirisfilejoin
subprocessPopenPIPEcommunicater   )rv   r   r   	directoryprogramr   r   s          rx   test_mocked_programz)HumanFriendlyTestCase.test_mocked_program   s       FCy77==+++77>>"'',,y$"?@@@ &&t:??:??cmcrcrsG$007G0HNFF%%+++----.... DCCs   CDDc                    t               5 }t        j                  j                  |      sJ t        j                  j	                  |d      }t        |d      5 }|j                  d       ddd       ddd       t        j                  j                        rJ t        j                  j                        rJ y# 1 sw Y   TxY w# 1 sw Y   XxY w)z7Test :class:`humanfriendly.testing.TemporaryDirectory`.z	some-filewzHello world!N)rJ   r   r   r   r   openr   exists)rv   r   temporary_filehandles       rx   test_temporary_directoryz.HumanFriendlyTestCase.test_temporary_directory   s    !Y77==+++WW\\)[ANnc*f^, + "
 77>>.11177>>),,,, +* "!s$   AC
B>+C
>C	C

Cc                 *   t               5 }t        j                  j                  |t	                     }t        j                  j                  |      rJ t        |       t        j                  j                  |      sJ t        j                  j                  |t	               t	                     }t        j                  j                  |      rJ t        |       t        j                  j                  |      sJ 	 ddd       y# 1 sw Y   yxY w)z+Test :func:`humanfriendly.testing.touch()`.N)rJ   r   r   r   rV   r   rO   )rv   r   filenames      rx   
test_touchz HumanFriendlyTestCase.test_touch
  s    !Yww||I}?Hww~~h///(O77>>(+++ww||I}PHww~~h///(O77>>(+++ "!!s   C4D		Dc                      G d dt               } |       }|j                  dk(  sJ t        |dd      5 }||u sJ |j                  dk(  sJ 	 ddd       |j                  dk(  sJ y# 1 sw Y   xY w)z5Test :class:`humanfriendly.testing.PatchedAttribute`.c                       e Zd ZdZy);HumanFriendlyTestCase.test_patch_attribute.<locals>.Subjectrj   N)__name__
__module____qualname__my_attributer   rz   rx   Subjectr     s    Lrz   r   rj   r      N)objectr   rH   )rv   r   instancereturn_values       rx   test_patch_attributez*HumanFriendlyTestCase.test_patch_attribute  s}    	f 	9$$***h;|8+++((B... < $$*** <;s   A((A1c                     t        d      }|d   du sJ t        |dd      5 }||u sJ |d   du sJ 	 ddd       |d   du sJ y# 1 sw Y   xY w)z0Test :class:`humanfriendly.testing.PatchedItem`.T)my_itemr   FN)rq   rI   )rv   r   r   s      rx   test_patch_itemz%HumanFriendlyTestCase.test_patch_item#  sq    %	"d***9e48+++I&%/// 5 	"d*** 54s   AAc                 F    t        d       \  }}| j                  |d       y)z*Test that run_cli() intercepts SystemExit.c                  ,    t        j                  d      S )Nrj   )r   exitr   rz   rx   r   zDHumanFriendlyTestCase.test_run_cli_intercepts_exit.<locals>.<lambda>.  s    SXXb\rz   rj   N)rM   assertEqualrv   r   r=   s      rx   test_run_cli_intercepts_exitz2HumanFriendlyTestCase.test_run_cli_intercepts_exit,  s"    $%9:
FR(rz   c                 X    t        | j                        \  }}| j                  |d       y)z*Test that run_cli() intercepts exceptions.rb   N)rM   run_cli_raise_otherr   r   s      rx   test_run_cli_intercepts_errorz3HumanFriendlyTestCase.test_run_cli_intercepts_error1  s'    $T%=%=>
FQ'rz   c                     t               )z*run_cli() sample that raises an exception.)
ValueErrorrv   s    rx   r   z)HumanFriendlyTestCase.run_cli_raise_other6  s
    lrz   c                     t               dz   t        fd      \  }}| j                  |d       | j                  |       y)z&Test that run_cli() intercepts output.
c                  B    t         j                  j                         S r   )r   r   r   )expected_outputs   rx   r   zFHumanFriendlyTestCase.test_run_cli_intercepts_output.<locals>.<lambda>=  s    SZZ-=-=o-Nrz   r   N)rV   rM   r   )rv   r   r=   r   s      @rx   test_run_cli_intercepts_outputz4HumanFriendlyTestCase.test_run_cli_intercepts_output:  s?    '/D0$%NO
FQ'1rz   c                     t        d       }t        d       } |        |       k(  sJ  |        |       k(  sJ  |        |       k7  sJ y)zTest the caching decorator.c                  *    t        j                          S r   randomr   rz   rx   r   z>HumanFriendlyTestCase.test_caching_decorator.<locals>.<lambda>D  
    6==?rz   c                  *    t        j                          S r   r   r   rz   rx   r   z>HumanFriendlyTestCase.test_caching_decorator.<locals>.<lambda>E  r   rz   Nr   )rv   abs      rx   test_caching_decoratorz,HumanFriendlyTestCase.test_caching_decoratorA  sJ     *+*+saczzsaczzsaczzrz   c                 j    t        d      dk(  sJ t        dd      dk(  sJ t        dd      d	k(  sJ y
)z*Test :func:`humanfriendly.text.compact()`.z a 

 b za bz*
            %s template notation
        SimplezSimple template notationz3
            More {type} template notation
        readable)typezMore readable template notationN)rP   r   s    rx   test_compactz"HumanFriendlyTestCase.test_compactK  s^    |$--- 45 	5 5  !BC 	C Crz   c                     t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ y)	z6Test :func:`humanfriendly.text.compact_empty_lines()`.fooz	foofoo
barzfoo

barz	foo


barz
foo



barzfoo




barN)rQ   r   s    rx   test_compact_empty_linesz.HumanFriendlyTestCase.test_compact_empty_linesU  s     #5)U222"7+w666":.*<<<"<0L@@@">2lBBB"#34DDD"#56,FFFrz   c                 j    t        d      dk(  sJ t        dd      dk(  sJ t        dd      d	k(  sJ y
)z)Test :func:`humanfriendly.text.dedent()`.z
 line 1
  line 2

zline 1
 line 2
z'
            Dedented, %s text
        interpolatedzDedented, interpolated text
z)
            Dedented, {op} text
        	formatted)opzDedented, formatted text
N)rS   r   s    rx   test_dedentz!HumanFriendlyTestCase.test_dedentd  s`    /04GGGG  ?@ 	@ @   <= 	= =rz   c                     t        dd      dk(  sJ t        dd      dk(  sJ t        ddd      dk(  sJ t        ddd      d	k(  sJ y
)z,Test :func:`humanfriendly.text.pluralize()`.rb   wordz1 wordrf   z2 wordsboxboxesz1 boxz2 boxesN)rU   r   s    rx   test_pluralizationz(HumanFriendlyTestCase.test_pluralizationn  sZ    F#x///F#y000E7+w666E7+y888rz   c                 D   | j                  dt        d             | j                  dt        d             | j                  t              5  t        d       ddd       | j                  t              5  t        d       ddd       y# 1 sw Y   3xY w# 1 sw Y   yxY w)z0Test :func:`humanfriendly.text.generate_slug()`.zsome-random-textzSome Random Text! N-)r   rT   r   r   r   s    rx   test_generate_slugz(HumanFriendlyTestCase.test_generate_slugu  s{     	+];N-OP+];M-NOz*# +z*# +* +***s   B
5B
BBc                     dD ]  }| j                  dt        |              dD ]  }| j                  dt        |              | j                  t              5  t        d       ddd       y# 1 sw Y   yxY w)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   )rv   values     rx   test_boolean_coercionz+HumanFriendlyTestCase.test_boolean_coercion  sd    EET>%#89 FIEUN5$9: Jz*?+ +**s   A//A8c                 P   t        j                  d      }t        t        d      t	        |            sJ |t        |      u sJ t        dt         j
                        }|j                  d      sJ | j                  t              5  t        g        ddd       y# 1 sw Y   yxY w)z,Test :func:`humanfriendly.coerce_pattern()`. foobarFOOBARN)	recompile
isinstancer	   r   
IGNORECASEmatchr   r   )rv   empty_patternpatterns      rx   test_pattern_coercionz+HumanFriendlyTestCase.test_pattern_coercion  s    

2.2D4GHHH} ==== 2==9}}X&&&z*2 +**s   BB%c                 r   d}|dz  }|dz  }|dz  }|dz  }dt        dd      k(  sJ d	t        d
d      k(  sJ dt        dd      k(  sJ dt        dd      k(  sJ dt        dd      k(  sJ dt        dd      k(  sJ dt        dd      k(  sJ dt        d      k(  sJ dt        d      k(  sJ dt        d      k(  sJ dt        t        j                        k(  sJ dt        |      k(  sJ dt        d      k(  sJ dt        |d z        k(  sJ d!t        |      k(  sJ d"t        |d z        k(  sJ d#t        |      k(  sJ d$t        |d z        k(  sJ d%t        |      k(  sJ d&t        |d z        k(  sJ d't        |      k(  sJ d(t        |d z        k(  sJ d)t        |d*z  |d+z  z   |d,z  z   |d-z  z   |d z  z   dz   d      k(  sJ d.t        ||d z  z   |d-z  z   |d/z  z         k(  sJ d0t        d1d      k(  sJ d2t        d1d      k(  sJ d3t        d4      k(  sJ d5t        d6      k(  sJ d7t        d8d      k(  sJ d9t        d:d      k(  sJ d;t        d<d      k(  sJ t        j                  j	                         }|t        j
                  d=>      z
  }d?t        ||z
        k(  sJ y@)Az-Test :func:`humanfriendly.format_timespan()`.<         4   z1 nanosecond&.>T)detailedz500 nanosecondsgƠ>z1 microsecondư>z500 microsecondsgMb@?1 millisecondMbP?500 milliseconds      ?0.5 secondsFz	0 secondsr   z0.54 secondsgna?1 secondrb   z3.14 seconds1 minutez1 minute and 20 secondsP   	2 minutesrf   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)rv   minutehourdayweekyearrA  thens           rx   test_format_timespanz*HumanFriendlyTestCase.test_format_timespan  sR   {RiQwbyt!LLLL OI$MMMM/(T"JJJJ!_Vd%KKKK/%$"GGGG!_S4%HHHHe DDDDoa0000!9999_Q////!9999_V4444(OB,????ofqj9999?40000OD1H5555/#....?373333?40000OD1H5555?40000OD1H5555RD1Htax/#'9D1HDvPQzQTWWbfgh 	h h+D4!8OcAg5r	ABC 	C C 9OE\`<aaaa)_UU-SSSS *_V-DDDD*og.FFFF-QU1VVVV/?6TX3YYYY1_ZZ^5____ ##%X''b11_S4Z8888rz   c                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d	             | j                  d
t        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d              | j                  d!t        d"             | j                  d!t        d#             | j                  t              5  t        d$       d%d%d%       y%# 1 sw Y   y%xY w)&z,Test :func:`humanfriendly.parse_timespan()`.r   r  0sr%  1nsgbak>51nsr'  1usg'eRC?52usr)  1msr(  r+  r*  r,  r8  5sz	5 secondsx   2mr0     z3 minz3 minsi0*  z3 hz3 hoursi F 4dz4 daysi$. z5 wz5 weeks1zN)r   r   r   r   r   s    rx   test_parse_timespanz)HumanFriendlyTestCase.test_parse_timespan  s   N3/0N401nU&;<nV&<=>%#89>&#9:u 56 ?@n-?@An];<N401N;78!56!<=!89!9:nU&;<nY&?@)>$+?@)>(+CD-~e/DE-~i/HI/4  0//s   (I==Jc                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  t              5  t        d       ddd       y# 1 sw Y   yxY w)	z(Test :func:`humanfriendly.parse_date()`.)  r7     r   r   r   z
2013-06-17)rY  r7  rZ  rf   /   rj   z2013-06-17 02:47:42)i  rn      r   r[  rZ  z2016-11-30 00:47:17z
2013-06-XYN)r   r   r   r   r   s    rx   test_parse_datez%HumanFriendlyTestCase.test_parse_date  sh    /L1IJ1:>S3TU2J?U4VW{+|$ ,++s   'A<<Bc                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  d	t        d
             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        dd             | j                  dt        dd             | j                  dt        dd             | j                  dt        d d             | j                  d!t        d"d             | j                  d#t        d$d             | j                  d%t        d&d             | j                  d't        d(d             | j                  d)t        d*             | j                  d+t        d,             y-).z)Test :func:`humanfriendly.format_size()`.z0 bytesr   z1 byterb   z42 bytesrj   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   s    rx   test_format_sizez&HumanFriendlyTestCase.test_format_size  s   KN3;q>2[_5Y!78Y!78Y!78Y!78Y!78Y!78Y!78Y!78+i"EF+i"EF+i"EF+i"EF+i"EF+i"EF+i"EF+i"EF+i"89;#?@rz   c                 v   | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        dd	
             | j                  dt        d             | j                  dt        d             | j                  dt        dd	
             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  t              5  t        d       d d d        | j                  t              5  t        d!       d d d        y # 1 sw Y   3xY w# 1 sw Y   y xY w)"z(Test :func:`humanfriendly.parse_size()`.r   0Brj   4242Br`  1krn  Tro  r_  z
1 kilobytei@z69 MBrc  rb  re  rd  rg  rf  ri  rh  rk  rj  rm  rl  g   ZAz1.5 GBg      Dz1.5 YiB1qNr   )r   r   r   r   r   s    rx   test_parse_sizez%HumanFriendlyTestCase.test_parse_size  s   Jt,-Z-.Z./z$/0z$t<=z&12z,78z,tDEG)<=Jv$67Jv$67Jv$67Jv$67Jv$67Jv$67*X*>?*Y*?@{+t ,{+sO ,+ ,+++s   %H#H/#H,/H8c                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  d	t        d
             | j                  dt        d             | j                  dt        d             | j                  dt        d             y)z+Test :func:`humanfriendly.format_length()`.z0 metresr   z1 metrerb   z	42 metresrj   z1 kmr`  15.3 cm/$?z1 cm{Gz?z1 mmr)  z1 nmr%  N)r   r
   r   s    rx   test_format_lengthz(HumanFriendlyTestCase.test_format_length  s    ]1%56M!$45mB&78x!89M%$89u!56u!56u!56rz   c                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        d	             | j                  d
t        d             | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  t              5  t        d       ddd       | j                  t              5  t        d       ddd       y# 1 sw Y   3xY w# 1 sw Y   yxY w)z*Test :func:`humanfriendly.parse_length()`.r   0mrj   ru        ?1.542mr`  1kmr|  r{  r}  1cmr)  1mmr%  1nmrV  Nr   )r   r   r   r   r   s    rx   test_parse_lengthz'HumanFriendlyTestCase.test_parse_length(  s   L./\$/0l512\%01|E23Y 78U 34U 34U 34}- .}- .- .---s   	E2EEEc                    | j                  dt        d             | j                  dt        d             | j                  dt        d             | j                  dt        dd             | j                  d	t        d
             | j                  d	t        dd             | j                  dt        d             | j                  dt        d             | j                  dt        d             y)z+Test :func:`humanfriendly.format_number()`.r  rb   r  r  z1.56gg?z1.567r:  z1,000r`  g)\@@r   z	1,000,000ra  z1,000,000.42gq=
׀.Az-285.67gQqN)r   r   r   s    rx   test_format_numberz(HumanFriendlyTestCase.test_format_number8  s    mA./c 23w!78-";<-"56-";<mG&<=z)BCM'$:;rz   c                     | j                  dt        d             | j                  dt        d             | j                  dt        dd             | j                  dt        d             y	)
z*Test :func:`humanfriendly.round_number()`.r  rb   g      ?1.00T
keep_widthz3.14g-DT!	@N)r   r   r   s    rx   test_round_numberz'HumanFriendlyTestCase.test_round_numberE  sX    l1o.l3/0aD!AB.?!@Arz   c                     t         j                  j                  dd      }t         j                  j                  t         j                  d   d      }| j	                  |t        |             y)z)Test :func:`humanfriendly.format_path()`.~.vimrcHOMEN)r   r   r   environr   r   rv   friendly_pathabsolute_paths      rx   test_format_pathz&HumanFriendlyTestCase.test_format_pathL  sH    S(3RZZ%7BM(BCrz   c                     t         j                  j                  dd      }t         j                  j                  t         j                  d   d      }| j	                  |t        |             y)z(Test :func:`humanfriendly.parse_path()`.r  r  r  N)r   r   r   r  r   r   r  s      rx   test_parse_pathz%HumanFriendlyTestCase.test_parse_pathR  sH    S(3RZZ%7B
=(ABrz   c                    dgg}t        |      t        d      j                         k(  sJ g dg dg}t        |      t        d      j                         k(  sJ g d}g dg dg}t        t        ||            t        d      j                         k(  sJ dd	g}d
dgddgg}t        t        ||            t        d      j                         k(  sJ y)z8Test :func:`humanfriendly.tables.format_pretty_table()`.zJust one columnzi
            -------------------
            | Just one column |
            -------------------
        rg   rh   Threer  23z
            ---------------------
            | One | Two | Three |
            | 1   | 2   | 3     |
            ---------------------
        r   r   c
            ---------------------
            | One | Two | Three |
            ---------------------
            | 1   | 2   | 3     |
            | a   | b   | c     |
            ---------------------
        zJust a labelzImportant numberszRow one15zRow two300a/  
            ------------------------------------
            | Just a label | Important numbers |
            ------------------------------------
            | Row one      |                15 |
            | Row two      |               300 |
            ------------------------------------
        N)r*   rS   stripr4   )rv   datacolumn_namess      rx   test_pretty_tablesz(HumanFriendlyTestCase.test_pretty_tablesX  s    ##$"4(F 4 - UW	 	  (9"4(F 4 -
 UW 	  /1-dLABf N G UW 	  '(;<D!Iu#56-dLABf N G UW 	 rz   c                     g d}g dg dg}t        t        ||            t        d      j                         k(  sJ g d}g dg dg}t        t        ||            t        d      j                         k(  sJ y)z8Test :func:`humanfriendly.tables.format_robust_table()`.r  r  r  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)r4   r+   rS   r  rv   r  r  s      rx   test_robust_tablesz(HumanFriendlyTestCase.test_robust_tables  s    .1-dLABf 
N 
G UW
 
	 
 /!OP-dLABf N G UW 	 rz   c                     g d}g dg dg}t        t        ||            t        d      j                         k(  sJ g d}g dg dg}t        t        ||            t        d      j                         k(  sJ y)z7Test :func:`humanfriendly.tables.format_smart_table()`.r  r  r  r  r  r  N)r4   r-   rS   r  r  s      rx   test_smart_tablesz'HumanFriendlyTestCase.test_smart_tables  s    .1,T<@AV M F UW 	  /!OP,T<@AV M F UW 	 rz   c                     g d}g dg dg}| j                  t        ||      t        d      j                                g dg dg}| j                  t        |      t        d      j                                y)z5Test :func:`humanfriendly.tables.format_rst_table()`.r  r  r  z
                ===  ===  =====
                One  Two  Three
                ===  ===  =====
                1    2    3
                a    b    c
                ===  ===  =====
            zm
                =  =  =
                1  2  3
                a  b  c
                =  =  =
            N)r   r,   rS   rstripr  s      rx   test_rst_tablesz%HumanFriendlyTestCase.test_rst_tables  sy     /1T<0   
	
  1T"  
 	
rz   c                     t        g       dk(  sJ t        dg      dk(  sJ t        ddg      dk(  sJ t        g d      dk(  sJ t        g dd      d	k(  sJ t        g dd
      dk(  sJ y)z.Test :func:`humanfriendly.text.concatenate()`.r  rc   re   zone and two)rc   re   threezone, two and threeor)conjunctionzone, two or threeT)serial_commazone, two, and threeNrR   r   s    rx   test_concatenatez&HumanFriendlyTestCase.test_concatenate  s    2"$$$E7#u,,,E5>*m;;;237KKKK2EI\\\\2FJ____rz   c                    ddl m} | j                   |d      g        | j                   |d      dg       | j                   |d      ddg       | j                   |d      g d       | j                   |d	      g d       y
)z(Test :func:`humanfriendly.text.split()`.r   )splitr  r   zfoo, barbarzfoo, bar, bazr   r  bazzfoo,bar,bazN)humanfriendly.textr  r   )rv   r  s     rx   
test_splitz HumanFriendlyTestCase.test_split  st    ,rB'uw/z*UEN;/1FG}-/DErz   c                    dD ]j  \  }}t        t        j                         |z
        }| j                  t        |j                  d      d|z         | j                  t        |      |       l t        t        j                         dz
        }| j                  |j                  d       t               }t        j                  d       | j                  t        |j                  d      d	       t        d
      }t        d      D ]"  }|5  t        j                  d       ddd       $ | j                  t        |j                  d      d       t        d
      5 }|J 	 ddd       y# 1 sw Y   oxY w# 1 sw Y   yxY w)z!Test :func:`humanfriendly.Timer`.)
)rb   r-  )rf   	2 seconds)r!  r.  )rR  r0  )i  r1  )i   r2  )iQ r3  )i  r4  )i:	 r5  )i u r6  Tr  z%i.00g@r  rb   r   r  )	resumablerf   Nz2.00)
r   timer   r   elapsed_timestrroundedsleepnormalize_timestamprange)rv   secondstexttautomatic_timerresumable_timeritimers           rx   
test_timerz HumanFriendlyTestCase.test_timer  s9   	AMGT diikG+,A\!..TJGV]L]^SVT*	A $))+#$K0'

1
 	,_-I-I1MvV$/qA 

1 !  	,_-I-I1MvVT"e$$$ #"	 ! #"s   E.E:.E7	:Fc                    t               }t        dd|d      }dD ])  }|j                  |       t        j                  d       + |j                          |j                         } |j                  t        d      j                  t        d      } |j                  t              D cg c]  }|s|	 }}| j                  t        |      d	kD         | j                  t        d
 |D                     | j                  t        d |D                     | j                  t!        t#        |            t!        |             yc c}w )z#Test :func:`humanfriendly.Spinner`.test spinnerr9  T)labeltotalstreaminteractive)rb   rf   r:  r9  )progressg?r  r   c              3   $   K   | ]  }d |v  
 yw)r  Nr   .0lines     rx   	<genexpr>z5HumanFriendlyTestCase.test_spinner.<locals>.<genexpr>  s     EutNd2u   c              3   $   K   | ]  }d |v  
 yw)%Nr   r  s     rx   r  z5HumanFriendlyTestCase.test_spinner.<locals>.<genexpr>  s     :EDC4KEr  N)r   rD   stepr  r  cleargetvaluereplacer3   r0   r  r/   
assertTruerp   allr   sortedset)rv   r  spinnerr  r=   r  liness          rx   test_spinnerz"HumanFriendlyTestCase.test_spinner  s    aTXY$HLL(L+JJsO % 	" &..!126 !126 	".&,,"?H"?$4"?HE
Q'EuEEF:E::;E
+VE];	 Is   +E3Ec                 p    t        d      5  t        j                  d       ddd       y# 1 sw Y   yxY w)a  
        Test :func:`humanfriendly.AutomaticSpinner`.

        There's not a lot to test about the :class:`.AutomaticSpinner` class,
        but by at least running it here we are assured that the code functions
        on all supported Python versions. :class:`.AutomaticSpinner` is built
        on top of the :class:`.Spinner` class so at least we also have the
        tests for the :class:`.Spinner` class to back us up.
        r  )r  rb   N)rC   r  r  r   s    rx   test_automatic_spinnerz,HumanFriendlyTestCase.test_automatic_spinner   s#     N3JJqM 433s   ,5c                 `   | j                  t              5  t        g        ddd       t        t        j
                        5 }t        t        d|      5  d}t        |g      |k(  sJ 	 ddd       ddd       t        t        dd       5  t        ddg      dk(  sJ 	 ddd       t        t        dd       5  t        ddg      dk(  sJ 	 ddd       t        t        dd	       5  t        ddg      dk(  sJ 	 ddd       t        t        dd
       5  t        ddgd      dk(  sJ 	 ddd       g dt        t        dfd      5  t        g d      dk(  sJ 	 ddd       ddgt        t        dfd      5  t        g d      dk(  sJ 	 ddd       ddgt        t        dfd      5  t        g d      dk(  sJ 	 ddd       t        t        dd       5  | j                  t              5  t        g d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ^xY w# 1 sw Y   ;xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)z7Test :func:`humanfriendly.prompts.prompt_for_choice()`.Nr   zonly one option (shortcut)interactive_promptc                      y)Nr   r   ps    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>:  s    urz   r   r  c                      y)Nfr   r  s    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>=      srz   c                      y)Nr  r   r  s    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>@  r  rz   c                      yNr  r   r  s    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>C      rrz   default)r  qzc                 &    j                  d      S Nr   rt   r  repliess    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>G      w{{ST~rz   r  r  r   r  c                 &    j                  d      S r  r  r  s    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>K  r  rz   )r   r  r  quxr  ru  r  c                 &    j                  d      S r  r  r  s    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>O  r  rz   c                      yr  r   r  s    rx   r   z>HumanFriendlyTestCase.test_prompt_for_choice.<locals>.<lambda>R  r  rz   r  )
r   r   r"   r   r   devnullrH   r   r   r    )rv   r   only_optionr  s      @rx   test_prompt_for_choicez,HumanFriendlyTestCase.test_prompt_for_choice-  sP    z*b! +
 "**!#w7:(+7;FFF 8 
 g';_M$eU^4=== N g';]K$eU^4=== L g';]K$eU^4=== L g';\J$eU^UCuLLL K !g';=UV$%:;uDDD W *g';=UV$%ABeKKK W +g';=UV$%:;uDDD W g';\J""#89!/2 : KJE +* 87 
 NM LK LK KJ WV WV WV :9 KJs   HH2H%+H2H?;I)II&I3J 5J#J$9JJ$H"%H/	*H22H<?I	II#&I03I= J	JJ!	J$$J-c                    dD ]/  t        t        dfd      5  t        d      du sJ 	 ddd       1 dD ]/  t        t        dfd      5  t        d      d	u sJ 	 ddd       1 d
D ]/  }t        t        dd       5  t        d|      |u sJ 	 ddd       1 ddgt        t        dfd      5  t        d      5 }t        d      du sJ d|j	                         v sJ 	 ddd       ddd       t        t        dd       5  dD ]@  \  }}t        d      5 }t        d|      du sJ ||j	                         v sJ 	 ddd       B 	 ddd       t        t        dd       5  | j                  t              5  t        d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   }xY w# 1 sw Y   VxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ixY w# 1 sw Y   yxY w)z=Test :func:`humanfriendly.prompts.prompt_for_confirmation()`.)r   YesYESyYr  c                     S r   r   r  replys    rx   r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>Z      5rz   zAre you sure?TN)r  NoNOnNc                     S r   r   r  s    rx   r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>^  r  rz   F)TFc                      yr  r   r  s    rx   r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>b  s    2rz   r  r  r  c                 &    j                  d      S r  r  r  s    rx   r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>f  r  rz   mergedzthere's no default choicec                      y)Nr  r   r  s    rx   r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>k  r  rz   ))TzY/n)Fzy/N)Nzy/nc                      yr  r   r  s    rx   r   zDHumanFriendlyTestCase.test_prompt_for_confirmation.<locals>.<lambda>q  r  rz   )rH   r   r!   rF   get_textr   r    )rv   default_choicer   default_valueexpected_textr  r  s        @@rx   test_prompt_for_confirmationz2HumanFriendlyTestCase.test_prompt_for_confirmationV  s    3E!'+?Q.?4GGG RQ 3 0E!'+?Q.?5HHH RQ 0 *N!'+?N.W[iiii ON * s)g';=UVd+x.?4GGG2h6G6G6IIII , W
 g';]K0\,}"$/82?MZ^bbbb(H,=,=,???? 0/ 1] L g';\J""#89'8 : KJ/ RQ RQ ON
 ,+ WV 0/ LK :9 KJs   FF,F97G$G)GG* &G
G*,HG6HF)	,F6	9G	G	GGG'#G**G36G?	;HHc                 >   t        t        j                        5 }t        t        d|      5  d}t        d|      |k(  sJ | j                  t              5  t        d       ddd       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)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
  rH   r   r#   r   EOFError)rv   r   r#  s      rx   test_prompt_for_inputz+HumanFriendlyTestCase.test_prompt_for_inputu  s~    "**!#w7 9'(=}UYffff &&x0$%CD 1 8  10 87 s:   B*BA;"B*B;B BB	BBc                    t        t              \  }}d|v sJ t        t        d      \  }}d|v sJ t        t        d      \  }}|dk7  sJ t        t        d      \  }} |j                         dk(  sJ t        j                  dd      }t        t        d	|z        \  }} |j                         t        |      k(  sJ t        j                  dd      }t        t        d	|z  d
      \  }} |j                         t        |d      k(  sJ t        j                  dd      }t        t        d|z        \  }} |j                         t        |      k(  sJ t        |      dz  }t        t        d|z        \  }} |j                         t        |      k(  sJ t        t        ddd      \  }} |j                         t        d      j                         k(  sJ t        j                  dd      }t        t        d|z        \  }} |j                         t        |      k(  sJ t        t        d      \  }}t        |      t        d      k(  sJ t        t        d      \  }}t        |      t        dd      k(  sJ t        t        d      \  }}t        |      t        d      k(  sJ t        t        d      \  }}t        |      t        d      k(  sJ t        t        d d!d"d#      \  }}|d$k(  sJ t        t        d%      \  }}|dk(  sJ  |j                         D cg c]  }t        |       }}d&|v sJ d'|v sJ d(|v sJ d)|v sJ d*|v sJ d+|v sJ d,|v sJ y-c c}w ).z Test the command line interface.zUsage:z--helpz--unsupported-optionr   z--format-number=1234567z	1,234,567rn  rq  z--format-size=%iz--binaryTro  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 |
            -------------
        r8  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 42rj   z--demoz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)rM   r   r  r   randintr   r
   floatrS   r   intr   r   
splitlinesr4   )rv   r   r=   random_byte_count
random_lenrandom_timespanr  r  s           rx   test_clizHumanFriendlyTestCase.test_cli  s    %T]
F6!!!$T84
F6!!!$T+AB
FQ$T+DE
Fv||~,,,"NN4=$T+=@Q+QR
Fv||~->!????"NN4=$T+=@Q+QS]^
Fv||~->t!LLLL^^D+6
$T+?*+LM
Fv||~z!:::::&0
$T+?*+LM
Fv||~z!::::$T+;=MUpq
Fv||~ ) " UW 	  !..C0$T+AO+ST
Fv||~!AAAA$T+>?
F6{j0000$T+?@
F6{j====$T+@A
F6{l62222$T+CD
FV}Y 7777$T?FDJ^_
FR %T84
FQ.?f.?.?.AB.AdD!.AB&&&#u,,,#u,,,2e;;;8EAAA-6664=== Cs   &M%c                    t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        d	t        k(  sJ t        d
      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        dd      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ t        d      t        dt        k(  sJ | j                  t              5  t        d       ddd       y# 1 sw Y   yxY w) z1Test :func:`humanfriendly.terminal.ansi_style()`.Tboldr  )faintr  )italicr  )	underline4)inverse7)strike_through9bluecolor34)
background44)r@  bright94   z38;5;214z39;5;214)r   r   r   z
38;2;0;0;0)   rG  rG  z38;2;255;255;255)2   d      z48;2;50;100;150unknownN)r5   r.   r2   r   r   r   s    rx   test_ansi_stylez%HumanFriendlyTestCase.test_ansi_style  sy   t$8X(FFFF%Hh)GGGG&Xx*HHHHD)(-KKKK$'h+IIII.Xx2PPPP'x+JJJJV,Hh0OOOOt4Hh8WWWW$(H(MMMMS)x-RRRR	*(H.UUUU0hX`4aaaa^4QY[c8ddddz*Y' +**s   ;GGc                     d}t        |      t        |      k(  sJ t        |d      }||k7  sJ t        |      t        |      kD  sJ t        |      t        |      k(  sJ y)z1Test :func:`humanfriendly.terminal.ansi_width()`.WhateverTr4  N)rp   r6   r7   )rv   r  wrappeds      rx   test_ansi_widthz%HumanFriendlyTestCase.test_ansi_width  sc    4yJt,,,,Dt,$7|c$i'''4yJw////rz   c                     d}|t        |      k(  sJ t        |d      j                  t              sJ t        |d      j                  t              sJ y)z0Test :func:`humanfriendly.terminal.ansi_wrap()`.rN  Tr4  N)r7   
startswithr.   endswithr1   rv   r  s     rx   test_ansi_wrapz$HumanFriendlyTestCase.test_ansi_wrap  sO    y&&&D)44X>>>D)22:>>>rz   c                    t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d	      d
k(  sJ t        d      d
k(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      dk(  sJ t        d      d k(  sJ t        d!      dk(  sJ d" }d#t        d$|%      vsJ d#t        d&|%      v sJ t        d'      sJ y())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                 &    | j                  dd      S )N:wink:z;-))r  )r  s    rx   callbackz9HumanFriendlyTestCase.test_html_to_ansi.<locals>.callback'  s    <<%00rz   r[  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>
        NrA   )rv   r\  s     rx   test_html_to_ansiz'HumanFriendlyTestCase.test_html_to_ansi  sR   237MMMMIJ]^ 	^ ^ ^_;< 	< < 348]]]]UV12 	2 2 5634 	4 4XY34 	4 4 <=67 	7 7cd67 	7 7 =>;< 	< <kl;< 	< < BC;< 	< < VWGH 	H H opJK 	K K >?*+ 	+ + G$+++G$+++F#s***F#s***H%,,,	1 |OhOOOO<(=QQQQ    	 rz   c                 
   d}t        d      5 }t        |       | j                  |g|j                  j	                                | j                  g |j
                  j	                                ddd       y# 1 sw Y   yxY w)z:Test the :func:`humanfriendly.terminal.output()` function.z%Standard output generated by output()Fr  N)rF   r=   r   r   r   r   rv   r  r   s      rx   test_generate_outputz*HumanFriendlyTestCase.test_generate_output9  s`    6%(H4LdVX__%>%>%@AR!:!:!<= )((   A!A99Bc                 
   d}t        d      5 }t        |       | j                  g |j                  j	                                | j                  |g|j
                  j	                                ddd       y# 1 sw Y   yxY w)z;Test the :func:`humanfriendly.terminal.message()` function.z%Standard error generated by message()Fr  N)rF   r<   r   r   r   r   r_  s      rx   test_generate_messagez+HumanFriendlyTestCase.test_generate_messageA  s`    6%(HDMR!:!:!<=dVX__%>%>%@A )((ra  c                 (   ddl m} d} |d      5 }t        |       | j                  g |j                  j                                | j                  t        |d      g| j                  |j                               ddd       y# 1 sw Y   yxY w)	z;Test the :func:`humanfriendly.terminal.warning()` function.r   rF   z%Standard error generated by warning()Fr  redr?  N)	r   rF   r@   r   r   r   r7   ignore_coverage_warningr   )rv   rF   r  r   s       rx   test_generate_warningz+HumanFriendlyTestCase.test_generate_warningI  sp    *6%(HDMR!:!:!<=iE:;T=Y=YZbZiZi=jk )((s   A-BBc                 R    |j                         D cg c]	  }d|vs| c}S c c}w )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)
        zno-data-collected)r   )rv   r  r  s      rx   rg  z-HumanFriendlyTestCase.ignore_coverage_warningR  s0     "(!1!1!3W!37JRV7V!3WWWs   	$$c                     t        d      dgk(  sJ t        d      ddgk(  sJ t        d      ddgk(  sJ t        d      dgk(  sJ t        d      dgk(  sJ t        d	      g d
k(  sJ y)z<Test :func:`humanfriendly.terminal.clean_terminal_output()`.r   r   r  zfoobar
bazr  zaaaababazaaabzfoo
bar
baz


r  N)r8   r   s    rx   test_clean_outputz'HumanFriendlyTestCase.test_clean_output]  s     %U+w666$Z0UENBBB$_5%GGG$Y/E7:::$Z0UG;;;$%:;?TTTTrz   c                    t               \  }}|dkD  sJ |dkD  sJ t        j                  }t        j                  }t        j                  }	 t               t        _        t               t        _        t               t        _        t               \  }}|dkD  sJ |dkD  sJ t        j                  d   }	 dt        j                  d<   t               \  }}|dkD  sJ |dkD  sJ 	 |t        j                  d<   	 |t        _        |t        _        |t        _        y# |t        j                  d<   w xY w# |t        _        |t        _        |t        _        w xY w)z9Test :func:`humanfriendly.terminal.find_terminal_size()`.r   PATHr  N)r:   r   r   r   r   r   r   r  )rv   r  columnssaved_stdinsaved_stdoutsaved_stderr
saved_paths          rx   test_find_terminal_sizez-HumanFriendlyTestCase.test_find_terminal_sizel  s   +-w qyy{{
 iizzzz	& 
CI!CJ!CJ 01NE7199Q;; F+J0%'

6"!3!5wqy y{"{%/

6"#CI%CJ%CJ	 &0

6"#CI%CJ%CJs%   A'D2 5.D $D2 D//D2 2#Ec                 `   ddl m} t        t        fD ]  }t        j
                  t        j                  fD ]  } |       5   ||      sJ 	 ddd        t        t        j                        5 } ||      rJ 	 ddd        |t                     sJ  y# 1 sw Y   kxY w# 1 sw Y   *xY w)z8Test the functions that check for terminal capabilities.r   re  N)r   rF   r9   r?   r   r   r   r   r   r
  r   )rv   rF   test_streamr  r   s        rx   test_terminal_capabilitiesz0HumanFriendlyTestCase.test_terminal_capabilities  s    *02JJK
 **cjj0"_&v... %_ 1 bjj!V&v.... " #68,,, K %_ "!s    B/B$B!$B-	c                 
   t         j                  j                  dd      }	 dt         j                  d<   dj                  d t	        d      D              }t               5 }t        |       ||j                         v sJ 	 ddd       ||t         j                  d<   yt         j                  j                  d       y# 1 sw Y   ?xY w# ||t         j                  d<   w t         j                  j                  d       w xY w)z1Test :func:`humanfriendly.terminal.show_pager()`.PAGERNcatr   c              3   2   K   | ]  }t        d         yw)   N)rV   )r  r  s     rx   r  z8HumanFriendlyTestCase.test_show_pager.<locals>.<genexpr>  s     #Iy!M"$5ys   rH  )	r   r  rs   r   r  rF   r>   r!  rt   )rv   original_pagerrandom_textr   s       rx   test_show_pagerz%HumanFriendlyTestCase.test_show_pager  s    6	( #(BJJw ))#IuRy#IIKH;'"h&7&7&9999 ! )&4

7# 

w' ! )&4

7# 

w's#   >C   B?C ?CC 7Dc                 *   dt        d      vsJ dt        t        dd            v sJ ddg}dD ]  }t        j                  j	                  dd	      }	 |t        j                  d<   t               |d
k(  rt        fd|D              sJ t        fd|D              rJ ||t        j                  d<   t        j                  j                  d        y	# ||t        j                  d<   w t        j                  j                  d       w xY w)z8Test :func:`humanfriendly.terminal.get_pager_command()`.z--RAW-CONTROL-CHARSzUsage messageTr4  z	--no-initz--quit-if-one-screen)rz  lessry  Nr  c              3   &   K   | ]  }|v  
 y wr   r   r  optcommand_lines     rx   r  z?HumanFriendlyTestCase.test_get_pager_command.<locals>.<genexpr>  s     W>Vssl2>V   c              3   &   K   | ]  }|v  
 y wr   r   r  s     rx   r  z?HumanFriendlyTestCase.test_get_pager_command.<locals>.<genexpr>  s     "[BZ33,#6BZr  )r;   r7   r   r  rs   r  anyrt   )rv   options_specific_to_lesspagerr}  r  s       @rx   test_get_pager_commandz,HumanFriendlyTestCase.test_get_pager_command  s     %,=o,NNNN$(9)OZ^:_(````$/1G#H "EZZ^^GT:N,&+

7#02F?W>VWWWW""[BZ"[[[[!-*8BJJw' JJNN7+% # "-*8BJJw' JJNN7+s   AC7Dc                 L    t        t        d            t        g d      k(  sJ y)z7Test :func:`humanfriendly.usage.find_meta_variables()`.z
            Here's one example: --format-number=VALUE
            Here's another example: --format-size=BYTES
            A final example: --format-timespan=SECONDS
            This line doesn't contain a META variable.
        )VALUEBYTESSECONDSN)r  rX   r   s    rx   test_find_meta_variablesz.HumanFriendlyTestCase.test_find_meta_variables  s1    ) +  
 567 	7 7rz   c                 h    | j                  d      \  }}d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ y)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rv   introductionoptionss      rx   test_parse_usage_simplez-HumanFriendlyTestCase.test_parse_usage_simple  sd     $ < < 
> 
!g /,>>>$444#|333w&&&,777rz   c                     | j                  d      \  }}d|v sJ t        d |D              sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ y	)
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              3   $   K   | ]  }d |v  
 yw)zstill part of the introductionNr   )r  r  s     rx   r  z@HumanFriendlyTestCase.test_parse_usage_tricky.<locals>.<genexpr>  s     O,Q3q8,r  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  s      rx   test_parse_usage_trickyz-HumanFriendlyTestCase.test_parse_usage_tricky  s     $ < < > !g, /,>>>O,OOOO#|333(G333;wFFF&'1119WDDDrz   c                     | j                  d      \  }}d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ d|v sJ y	)
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  s      rx   test_parse_usage_commasz-HumanFriendlyTestCase.test_parse_usage_commas  s     $ < < > !g  /,>>>-===#|333#w...-888/7:::@GKKKrz   c                 J    t        d t        t        |            D              S )z:Ignore leading/trailing whitespace in usage parsing tests.c              3   b   K   | ]"  }|D cg c]  }|j                          c} $ y c c}w wr   )r  )r  rr  s      rx   r  z@HumanFriendlyTestCase.preprocess_parse_result.<locals>.<genexpr>5  s+     O5N+Aaggi+5N+s   	/*/)tuplerZ   rS   rT  s     rx   r  z-HumanFriendlyTestCase.preprocess_parse_result3  s    O[5NOOOrz   c                 b   d}t        |      }t        |      t        |      kD  sJ |j                  d      sJ d}t        |      }t        |      t        |      kD  sJ ||v sJ |j                  |      rJ d}t        |      }|j                         }t        |d   v sJ t        |d   vsJ y)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
rb   rf   N)rY   rp   rR  r.  r.   )rv   
usage_textformatted_textformatted_liness       rx   test_format_usagez'HumanFriendlyTestCase.test_format_usage7  s     )
%j1>"S_444((5555
%j1>"S_444^+++!,,Z888: 	
 &j1(335?1----q1111rz   c                     t        d      dk(  sJ t        d      dk(  sJ dt        t        d            v sJ t        d dD              sJ y	)
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              3   H   K   | ]  }|t        t        d             v   yw)zm
            Supported options:

              -n, --dry-run

                Don't change anything.
        N)r[   rS   )r  tokens     rx   r  z:HumanFriendlyTestCase.test_render_usage.<locals>.<genexpr>[  s4      4 3% L 1 *   3s    ")z`-n`z`--dry-run`N)r[   rS   r  r   s    rx   test_render_usagez'HumanFriendlyTestCase.test_render_usageQ  st    ;<@eeee015MMMM|F 4 -    	   4 34 4 	4 4rz   c                 (   t        dd      d        }t               }t        t        d|      5   |dd      dk(  sJ | j	                  t
              5   |ddd       ddd       ddd       |j                  sJ y# 1 sw Y    xY w# 1 sw Y   $xY w)z.Test the deprecated_args() decorator function.r   r  c                  B    | d   dk(  sJ | j                  d      dv sJ y)Nr   r  )Nr  rj   )rs   )r  s    rx   test_functionzAHumanFriendlyTestCase.test_deprecated_args.<locals>.test_functione  s.    5>U***;;u%666rz   warnrj   r  N)r   r\   rH   warningsr   	TypeErrorr   )rv   r  fake_fns      rx   test_deprecated_argsz*HumanFriendlyTestCase.test_deprecated_argsc  s    		&	 
'	 +h8 ."444""9-eUE2 . 9 !!!! .- 98s#   $BA<B<B	BBc                 
   t               }t        t        d|      5  t        j                  t
           }t        d      }t        ||      }|j                  t        k(  sJ 	 ddd       |j                  sJ y# 1 sw Y   xY w)@Test that the DeprecationProxy class emits deprecation warnings.r  humanfriendly.text.concatenater  N)
r\   rH   r  r   modulesr   rq   r   rR   r   )rv   r  modulealiasesproxys        rx   $test_alias_proxy_deprecation_warningz:HumanFriendlyTestCase.test_alias_proxy_deprecation_warningq  sm    +h8[[*F'GHG$VW5E$$333	 9
 !!!! 98s   AA99Bc                    t        t        j                  dt        j                  d            5  t        t        d       dt        t        j                  t                 v sJ dt        t              v sJ 	 ddd       y# 1 sw Y   yxY w)r  sphinxr  r  rR   N)	rI   r   r  types
ModuleTyper   r   dirr   r   s    rx   $test_alias_proxy_sphinx_compensationz:HumanFriendlyTestCase.test_alias_proxy_sphinx_compensation{  sd    h0@0@0JK81QR CH(=$>>>> K$9999 LKKs   A	BBc                     t         j                  t           }t        t        d       |j                  j                         }t        ddd|d|       dj                  |      |j                  k7  sJ y)z?Test that aliases can be injected into generated documentation.r  r  Nappwhatr   rw   r  r  r   )r   r  r   r   __doc__r.  r$   r   )rv   r  r  s      rx   #test_alias_proxy_sphinx_integrationz9HumanFriendlyTestCase.test_alias_proxy_sphinx_integration  s\    X&x-MN))+!dDfVZbghyy6>>111rz   c                 B    G d dt               } |       }t        |       t        |j                  d   k(  sJ t        |j                  d   k(  sJ t
        |j                  d   v sJ t        |j                  d   v sJ t        |j                  d   v sJ t        ddd|j                  dd	      d
u sJ t        ddd|j                  dd	      du sJ ddlm}m} | j                  |      sJ | j                  |      rJ | j                  |j                        rJ y)z,Test the :mod:`humanfriendly.sphinx` module.c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)AHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeAppc                      i | _         i | _        y r   )	callbacksrolesr   s    rx   __init__zJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__init__  s    !#
rz   c                      y)z%Documented unofficial special method.Nr   r   s    rx   __documented_special_method__z_HumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__documented_special_method__      rz   c                      y r   r   r   s    rx   __undocumented_special_method__zaHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.__undocumented_special_method__  r  rz   c                 "    || j                   |<   y r   )r  )rv   r   r\  s      rx   add_rolezJHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.add_role  s    #+

4 rz   c                 Z    | j                   j                  |g       j                  |       y r   )r  ru   append)rv   eventr\  s      rx   connectzIHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.connect  s!    ))%4;;HErz   c                      y)z.Usage: This is not supposed to be reformatted!Nr   r   s    rx   bogus_usagezMHumanFriendlyTestCase.test_sphinx_customizations.<locals>.FakeApp.bogus_usage  r  rz   N)	r   r   r   r  r  r  r  r  r  r   rz   rx   FakeAppr    s!     ,Frz   r  manpypizautodoc-process-docstringzautodoc-skip-memberNT)r  r  r   rw   skipr  Fr   )clir  )r   r'   r%   r  r&   r$   r  r(   r)   r  r  humanfriendlyr  r  docstring_is_reformattedr  )rv   r  fake_appr  r  s        rx   test_sphinx_customizationsz0HumanFriendlyTestCase.test_sphinx_customizations  sN   	f 	2 9h8>>%0000HNN62222(H,>,>?Z,[[[['8+=+=>S+TTTT%););<W)XXXX'4d55t
 	 	  (4d77t
 	 	  	. ,,S111 00888 001E1EFFFFrz   c                     t        |j                        j                         }t        |      }t	        ddd|d|       ||k7  S )zOCheck whether :func:`.usage_message_callback()` reformats a module's docstring.Nr  )rW   r  r.  listr)   )rv   entityr  saved_liness       rx   r  z.HumanFriendlyTestCase.docstring_is_reformatted  sE     0;;=5k4dE	
 ##rz   N)Mr   r   r   r  ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  rI  rW  r]  rr  ry  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r(  r2  rL  rP  rU  r]  r`  rc  rh  rg  rl  rt  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rz   rx   r^   r^      s   7()T
!F;-$, /$-,	++)
(
2CG=9
,09d!6%A00	7 <BDC&P>8
8	`F"%H<"'3R9>
EG>R(&0?BH>Bl	XU(&T-"(,,878*EBL6P244$"":28Gt$rz   r^   c                 4    dt        t        |       |      z  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  s     rx   r  r    s     E%,888rz   )rb   )vr  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   humanfriendly.caser   r   humanfriendly.clir   humanfriendly.compatr   humanfriendly.decoratorsr   humanfriendly.deprecationr   r   r   r   humanfriendly.promptsr    r!   r"   r#   humanfriendly.sphinxr$   r%   r&   r'   r(   r)   humanfriendly.tablesr*   r+   r,   r-   humanfriendly.terminalr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   humanfriendly.terminal.htmlrB   humanfriendly.terminal.spinnersrC   rD   humanfriendly.testingrE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   r  rP   rQ   rR   rS   rT   rU   rV   rW   humanfriendly.usagerX   rY   rZ   r[   mockr\   r^   r  r   rz   rx   <module>r     s    2   	  	  
         * G " ) + d d        * 5 E   	 	 	  L$H L$^*9rz   