o
    °ƒðj7 ã                   @   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„ ZBd€d�„ ZCd‚dƒ„ ZDd„d…„ ZEd†d‡„ ZFdˆd‰„ ZGdŠd‹„ ZHdŒd�„ ZIdŽd�„ ZJd�d‘„ ZKd’d“„ ZLd”S )•ÚHumanFriendlyTestCasez-Container for the `humanfriendly` test suite.c                 C   s¢  t tddgƒƒdksJ ‚t tddgddd�ƒd	ksJ ‚t ttddd
�ƒƒdks)J ‚t ttddd�ddd�ƒd	ks:J ‚t tdddd�ƒd	ksGJ ‚t g d¢¡}t |ƒd	ksVJ ‚tdd�}| d¡dksdJ ‚tdd�}| d¡dksrJ ‚t |ƒdkszJ ‚tdd�}| d¡dksˆJ ‚| dd¡ |d dks–J ‚tdd�}d|v s¡J ‚tdd�}|d= t |ƒdks±J ‚tdd�}|d dks¾J ‚tdd�}d|d< |d dksÏJ ‚dS )z#Test the CaseInsensitiveDict class.)ÚkeyT)ÚKEYFé   )ÚoneT)ÚONEFFT)r`   Útwoé   )r]   r^   )r`   ra   )r`   ra   rb   )ÚOner`   ra   ÚTworb   ÚTWOé*   )Úexisting_keyÚExisting_Keyr   Ú	other_keyé   Ú	Other_Keyrh   N)Úlenr   ÚdictÚfromkeysÚgetÚpopÚ
setdefault)ÚselfÚobj© ru   ú•/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/humanfriendly/tests.pyÚtest_case_insensitive_dict…   s4   "






z0HumanFriendlyTestCase.test_case_insensitive_dictc                 C   sD   t dƒ}t dƒ}||ksJ ‚i }d||< d||< t|ƒdks J ‚dS )z"Test the CaseInsensitiveKey class.zPlease don't shoutzPLEASE DON'T SHOUTr_   rc   N)r   rm   )rs   ÚpoliteÚrudeÚmappingru   ru   rv   Útest_case_insensitive_key¯   s   z/HumanFriendlyTestCase.test_case_insensitive_keyc                 C   sl   t ƒ �)}tj d¡ tj d¡ |j ¡ dgksJ ‚|j ¡ dgks$J ‚W d  ƒ dS 1 s/w   Y  dS )zTest the CaptureOutput class.zSomething for stdout.
zAnd for stderr.
zSomething for stdout.zAnd for stderr.N)rE   ÚsysÚstdoutÚwriteÚstderrÚ	get_lines)rs   Úcapturerru   ru   rv   Útest_capture_output»   s   "üz)HumanFriendlyTestCase.test_capture_outputc                 C   s6   dd„ }t tƒ}||ƒ}|  t|¡ |  tj|¡ dS )z#Test the skip_on_raise() decorator.c                   S   ó   t ƒ ‚©N)ÚNotImplementedErrorru   ru   ru   rv   Útest_fnÅ   s   z9HumanFriendlyTestCase.test_skip_on_raise.<locals>.test_fnN)rM   r…   ÚassertRaisesÚunittestÚSkipTest)rs   r†   Údecorator_fnÚdecorated_fnru   ru   rv   Útest_skip_on_raiseÃ   s
   z(HumanFriendlyTestCase.test_skip_on_raisec                    s`   ‡ fdd„‰ t ˆ ƒdksJ ‚dd„ }|  t¡� t |dd� W d  ƒ dS 1 s)w   Y  dS )	zFTest :func:`~humanfriendly.testing.retry()` based on assertion errors.c                      s   t ˆ dƒstˆ ddƒ J ‚dS )NÚ
was_calledTFÚyes©ÚhasattrÚsetattrru   ©Úsuccess_helperru   rv   r“   Ð   s   
z>HumanFriendlyTestCase.test_retry_raise.<locals>.success_helperrŽ   c                   S   s   J ‚r„   ru   ru   ru   ru   rv   Úfailure_helperÙ   s   z>HumanFriendlyTestCase.test_retry_raise.<locals>.failure_helperr_   ©ÚtimeoutN)rK   r‡   ÚAssertionError)rs   r”   ru   r’   rv   Útest_retry_raiseÌ   s   "ÿz&HumanFriendlyTestCase.test_retry_raisec                    s\   ‡ fdd„‰ t ˆ ƒdksJ ‚|  t¡� t dd„ dd� W d  ƒ dS 1 s'w   Y  dS )	zCTest :func:`~humanfriendly.testing.retry()` based on return values.c                      s   t ˆ dƒstˆ ddƒ dS dS )Nr�   TFrg   r�   ru   r’   ru   rv   r“   â   s   
z?HumanFriendlyTestCase.test_retry_return.<locals>.success_helperrg   c                   S   ó   dS )NFru   ru   ru   ru   rv   Ú<lambda>ì   ó    z9HumanFriendlyTestCase.test_retry_return.<locals>.<lambda>r_   r•   N)rK   r‡   rD   ©rs   ru   r’   rv   Útest_retry_returnÞ   s
   "ÿz'HumanFriendlyTestCase.test_retry_returnc                 C   sº   t ƒ }tdƒ}t|d|d��E}tj |¡sJ ‚tj tj ||¡¡s$J ‚tj	|tj
tj
tj
d�}|jdd�\}}|jdks?J ‚|dksEJ ‚|dksKJ ‚W d	  ƒ d	S 1 sVw   Y  d	S )
z2Test :class:`humanfriendly.testing.MockedProgram`.zˆ
            # This goes to stdout.
            tr a-z A-Z
            # This goes to stderr.
            echo Fake warning >&2
        rg   )ÚnameÚ
returncodeÚscript)Ústdinr}   r   s   hello world
©Úinputs   HELLO WORLD
s   Fake warning
N)rU   rR   rF   ÚosÚpathÚisdirÚisfileÚjoinÚ
subprocessÚPopenÚPIPEÚcommunicaterŸ   )rs   rž   r    Ú	directoryÚprogramr}   r   ru   ru   rv   Útest_mocked_programî   s   "ùz)HumanFriendlyTestCase.test_mocked_programc              	   C   sœ   t ƒ �1}tj |¡sJ ‚tj |d¡}t|dƒ�}| d¡ W d  ƒ n1 s(w   Y  W d  ƒ n1 s7w   Y  tj |¡rDJ ‚tj |¡rLJ ‚dS )z7Test :class:`humanfriendly.testing.TemporaryDirectory`.z	some-fileÚwzHello world!N)rI   r¤   r¥   r¦   r¨   Úopenr~   Úexists)rs   r­   Útemporary_fileÚhandleru   ru   rv   Útest_temporary_directory   s   ÿ€ýz.HumanFriendlyTestCase.test_temporary_directoryc                 C   s    t ƒ �C}tj |tƒ ¡}tj |¡rJ ‚t|ƒ tj |¡s J ‚tj |tƒ tƒ ¡}tj |¡r2J ‚t|ƒ tj |¡s>J ‚W d  ƒ dS 1 sIw   Y  dS )z+Test :func:`humanfriendly.testing.touch()`.N)rI   r¤   r¥   r¨   rU   r§   rN   )rs   r­   Úfilenameru   ru   rv   Ú
test_touch
  s   "öz HumanFriendlyTestCase.test_touchc                 C   s|   G dd„ dt ƒ}|ƒ }|jdksJ ‚t|ddƒ�}||u sJ ‚|jdks&J ‚W d  ƒ n1 s0w   Y  |jdks<J ‚dS )z5Test :class:`humanfriendly.testing.PatchedAttribute`.c                   @   s   e Zd ZdZdS )z;HumanFriendlyTestCase.test_patch_attribute.<locals>.Subjectrg   N)Ú__name__Ú
__module__Ú__qualname__Úmy_attributeru   ru   ru   rv   ÚSubject  s    r¼   rg   r»   é   N)Úobjectr»   rG   )rs   r¼   ÚinstanceÚreturn_valueru   ru   rv   Útest_patch_attribute  s   þz*HumanFriendlyTestCase.test_patch_attributec                 C   sv   t dd�}|d du sJ ‚t|ddƒ�}||u sJ ‚|d du s"J ‚W d  ƒ n1 s,w   Y  |d du s9J ‚dS )z0Test :class:`humanfriendly.testing.PatchedItem`.T)Úmy_itemrÂ   FN)rn   rH   )rs   r¿   rÀ   ru   ru   rv   Útest_patch_item#  s   
þz%HumanFriendlyTestCase.test_patch_itemc                 C   s    t dd„ ƒ\}}|  |d¡ dS )z*Test that run_cli() intercepts SystemExit.c                   S   s
   t  d¡S )Nrg   )r|   Úexitru   ru   ru   rv   rš   .  ó   
 zDHumanFriendlyTestCase.test_run_cli_intercepts_exit.<locals>.<lambda>rg   N)rL   ÚassertEqual©rs   rŸ   r<   ru   ru   rv   Útest_run_cli_intercepts_exit,  s   z2HumanFriendlyTestCase.test_run_cli_intercepts_exitc                 C   s   t | jƒ\}}|  |d¡ dS )z*Test that run_cli() intercepts exceptions.r_   N)rL   Úrun_cli_raise_otherrÆ   rÇ   ru   ru   rv   Útest_run_cli_intercepts_error1  s   z3HumanFriendlyTestCase.test_run_cli_intercepts_errorc                 C   rƒ   )z*run_cli() sample that raises an exception.)Ú
ValueErrorrœ   ru   ru   rv   rÉ   6  s   z)HumanFriendlyTestCase.run_cli_raise_otherc                    s:   t ƒ d ‰ t‡ fdd„ƒ\}}|  |d¡ |  |ˆ ¡ dS )z&Test that run_cli() intercepts output.Ú
c                      s   t j ˆ ¡S r„   )r|   r}   r~   ru   ©Úexpected_outputru   rv   rš   =  s    zFHumanFriendlyTestCase.test_run_cli_intercepts_output.<locals>.<lambda>r   N)rU   rL   rÆ   rÇ   ru   rÍ   rv   Útest_run_cli_intercepts_output:  s   
z4HumanFriendlyTestCase.test_run_cli_intercepts_outputc                 C   sL   t dd„ ƒ}t dd„ ƒ}|ƒ |ƒ ksJ ‚|ƒ |ƒ ksJ ‚|ƒ |ƒ ks$J ‚dS )zTest the caching decorator.c                   S   ó   t   ¡ S r„   ©Úrandomru   ru   ru   rv   rš   D  ó    z>HumanFriendlyTestCase.test_caching_decorator.<locals>.<lambda>c                   S   rÐ   r„   rÑ   ru   ru   ru   rv   rš   E  rÓ   Nr   )rs   ÚaÚbru   ru   rv   Útest_caching_decoratorA  s
   z,HumanFriendlyTestCase.test_caching_decoratorc                 C   ó:   t dƒdksJ ‚t ddƒdksJ ‚t ddd�d	ksJ ‚d
S )z*Test :func:`humanfriendly.text.compact()`.z a 

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

barz	foo


barz
foo



barzfoo




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

zline 1
 line 2
z'
            Dedented, %s text
        ÚinterpolatedzDedented, interpolated text
z)
            Dedented, {op} text
        Ú	formatted)ÚopzDedented, formatted text
N)rR   rœ   ru   ru   rv   Útest_dedentd  rÜ   z!HumanFriendlyTestCase.test_dedentc                 C   sP   t ddƒdks	J ‚t ddƒdksJ ‚t dddƒdksJ ‚t dddƒd	ks&J ‚d
S )z,Test :func:`humanfriendly.text.pluralize()`.r_   Úwordz1 wordrc   z2 wordsÚboxÚboxesz1 boxz2 boxesN)rT   rœ   ru   ru   rv   Útest_pluralizationn  s   z(HumanFriendlyTestCase.test_pluralizationc                 C   sŠ   |   dtdƒ¡ |   dtdƒ¡ |  t¡� tdƒ W d  ƒ n1 s$w   Y  |  t¡� tdƒ W d  ƒ dS 1 s>w   Y  dS )z0Test :func:`humanfriendly.text.generate_slug()`.zsome-random-textzSome Random Text!ú Nú-)rÆ   rS   r‡   rË   rœ   ru   ru   rv   Útest_generate_slugu  s   
ÿ
"ÿz(HumanFriendlyTestCase.test_generate_slugc                 C   sl   dD ]
}|   dt|ƒ¡ qdD ]
}|   dt|ƒ¡ q|  t¡� tdƒ W d  ƒ dS 1 s/w   Y  dS )z,Test :func:`humanfriendly.coerce_boolean()`.)TÚTRUEÚTrueÚtrueÚonrŽ   Ú1T)FÚFALSEÚFalseÚfalseÚoffÚnoÚ0Fznot a booleanN)rÆ   r   r‡   rË   )rs   Úvalueru   ru   rv   Útest_boolean_coercion�  s   
"ÿz+HumanFriendlyTestCase.test_boolean_coercionc                 C   s‚   t  d¡}ttdƒt|ƒƒsJ ‚|t|ƒu sJ ‚tdt jƒ}| d¡s%J ‚|  t¡� tg ƒ W d  ƒ dS 1 s:w   Y  dS )z,Test :func:`humanfriendly.coerce_pattern()`.Ú ÚfoobarÚFOOBARN)	ÚreÚcompileÚ
isinstancer   rÚ   Ú
IGNORECASEÚmatchr‡   rË   )rs   Úempty_patternÚpatternru   ru   rv   Útest_pattern_coercionŠ  s   

"ÿz+HumanFriendlyTestCase.test_pattern_coercionc                 C   sâ  d}|d }|d }|d }|d }dt ddd�ksJ ‚d	t d
dd�ks&J ‚dt ddd�ks0J ‚dt ddd�ks:J ‚dt ddd�ksDJ ‚dt ddd�ksNJ ‚dt ddd�ksXJ ‚dt dƒks`J ‚dt dƒkshJ ‚dt dƒkspJ ‚dt tjƒksyJ ‚dt |ƒks�J ‚dt dƒks‰J ‚dt |d  ƒks“J ‚d!t |ƒks›J ‚d"t |d  ƒks¥J ‚d#t |ƒks­J ‚d$t |d  ƒks·J ‚d%t |ƒks¿J ‚d&t |d  ƒksÉJ ‚d't |ƒksÑJ ‚d(t |d  ƒksÛJ ‚d)t |d* |d+  |d,  |d-  |d   d dd�ksùJ ‚d.t ||d   |d-  |d/  ƒk�sJ ‚d0t d1dd�k�sJ ‚d2t d1dd�k�s$J ‚d3t d4ƒk�s-J ‚d5t d6ƒk�s6J ‚d7t d8dd�k�sAJ ‚d9t d:dd�k�sLJ ‚d;t d<dd�k�sWJ ‚tj ¡ }|tjd=d>� }d?t || ƒk�soJ ‚d@S )Az-Test :func:`humanfriendly.format_timespan()`.é<   é   é   é4   z1 nanosecondç•Ö&è.>T)Údetailedz500 nanosecondsg�íµ ÷Æ >z1 microsecondç�íµ ÷Æ°>z500 microsecondsgü©ñÒMb@?ú1 millisecondçü©ñÒMbP?ú500 millisecondsç      à?ú0.5 secondsFz	0 secondsr   z0.54 secondsgn†ðùaá?ú1 secondr_   z3.14 secondsú1 minutez1 minute and 20 secondséP   ú	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 secondsgÍÌÌÌÌÄr@z1 second and 15 millisecondsg=
×£p=ð?z10 seconds and 15 millisecondsgHáz®$@z 1 microsecond and 50 nanosecondsgÓ‹5·�±>é   )Úhoursz23 hoursN)r   ÚmathÚpiÚdatetimeÚnowÚ	timedelta)rs   ÚminuteÚhourÚdayÚweekÚyearr#  Úthenru   ru   rv   Útest_format_timespan˜  sV   2ÿ
ÿ
z*HumanFriendlyTestCase.test_format_timespanc                 C   s˜  |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtd	ƒ¡ |   d
tdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtd ƒ¡ |   d!td"ƒ¡ |   d!td#ƒ¡ |  t¡� td$ƒ W d%  ƒ d%S 1 sÅw   Y  d%S )&z,Test :func:`humanfriendly.parse_timespan()`.r   rõ   Ú0sr  Ú1nsgýåýùbak>Ú51nsr	  Ú1usg¢'eRC?Ú52usr  Ú1msr
  r  r  r  r  Ú5sz	5 secondséx   Ú2mr  é´   z3 minz3 minsi0*  z3 hz3 hoursi F Ú4dz4 daysi€$. z5 wz5 weeksÚ1zN)rÆ   r   r‡   r   rœ   ru   ru   rv   Útest_parse_timespanÊ  s2   
"ÿz)HumanFriendlyTestCase.test_parse_timespanc                 C   sh   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |  t¡� tdƒ W d  ƒ dS 1 s-w   Y  dS )	z(Test :func:`humanfriendly.parse_date()`.)éÝ  r  é   r   r   r   z
2013-06-17)r9  r  r:  rc   é/   rg   z2013-06-17 02:47:42)ià  rk   é   r   r;  r:  z2016-11-30 00:47:17z
2013-06-XYN)rÆ   r   r‡   r   rœ   ru   ru   rv   Útest_parse_dateå  s   
"ÿz%HumanFriendlyTestCase.test_parse_datec                 C   st  |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   d	td
ƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtddd�¡ |   dtddd�¡ |   dtddd�¡ |   dtd dd�¡ |   d!td"dd�¡ |   d#td$dd�¡ |   d%td&dd�¡ |   d'td(dd�¡ |   d)td*ƒ¡ |   d+td,ƒ¡ d-S ).z)Test :func:`humanfriendly.format_size()`.z0 bytesr   z1 byter_   z42 bytesrg   ú1 KBéè  z1 MBé@B ú1 GBé Êš;ú1 TBì    J)£ú1 PBì     �Iú5 ú1 EBì     ÈNÎZoú1 ZBì     @=7M.cú1 YBì      B¶3v^!< z1 KiBé   T©Úbinaryz1 MiBé   z1 GiBi   @z1 TiBl        z1 PiBl           z1 EiBl            z1 ZiBl            z1 YiBl               z45 KBiÈ¯  z2.9 TBg  @Â«…BN)rÆ   r   rœ   ru   ru   rv   Útest_format_sizeí  s*   z&HumanFriendlyTestCase.test_format_sizec                 C   s‚  |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdd	d
�¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdd	d
�¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |  t¡� tdƒ W d   ƒ n1 s w   Y  |  t¡� td!ƒ W d   ƒ d S 1 sºw   Y  d S )"z(Test :func:`humanfriendly.parse_size()`.r   Ú0Brg   Ú42Ú42Br?  Ú1krM  TrN  r>  z
1 kilobytei@Ûz69 MBrB  rA  rD  rC  rF  rE  rH  rG  rJ  rI  rL  rK  g   ÀZÖAz1.5 GBg      øDz1.5 YiBÚ1qNrÔ   )rÆ   r   r‡   r   rœ   ru   ru   rv   Útest_parse_size  s.   
ÿ
"ÿz%HumanFriendlyTestCase.test_parse_sizec                 C   s„   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   d	td
ƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ dS )z+Test :func:`humanfriendly.format_length()`.z0 metresr   z1 metrer_   z	42 metresrg   z1 kmr?  ú15.3 cmç/Ý$�•Ã?z1 cmç{®Gáz„?z1 mmr  z1 nmr  N)rÆ   r	   rœ   ru   ru   rv   Útest_format_length  s   z(HumanFriendlyTestCase.test_format_lengthc                 C   sú   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtd	ƒ¡ |   d
tdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |  t¡� tdƒ W d  ƒ n1 s\w   Y  |  t¡� tdƒ W d  ƒ dS 1 svw   Y  dS )z*Test :func:`humanfriendly.parse_length()`.r   Ú0mrg   rS  ç      ø?ú1.5Ú42mr?  Ú1kmrY  rX  rZ  Ú1cmr  Ú1mmr  Ú1nmr7  NrÔ   )rÆ   r   r‡   r   rœ   ru   ru   rv   Útest_parse_length(  s   
ÿ
"ÿz'HumanFriendlyTestCase.test_parse_lengthc                 C   s˜   |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtddƒ¡ |   d	td
ƒ¡ |   d	tddƒ¡ |   dtdƒ¡ |   dtdƒ¡ |   dtdƒ¡ dS )z+Test :func:`humanfriendly.format_number()`.rï   r_   r^  r]  z1.56gg›Óù?z1.567r  z1,000r?  g)\�Âõ@�@r   z	1,000,000r@  z1,000,000.42gq=
×€„.Az-285.67g…ëQ¸ÚqÀN)rÆ   r
   rœ   ru   ru   rv   Útest_format_number8  s   z(HumanFriendlyTestCase.test_format_numberc                 C   sH   |   dtdƒ¡ |   dtdƒ¡ |   dtddd�¡ |   dtdƒ¡ d	S )
z*Test :func:`humanfriendly.round_number()`.rï   r_   g      ð?ú1.00T©Ú
keep_widthz3.14g-DTû!	@N)rÆ   r   rœ   ru   ru   rv   Útest_round_numberE  s   z'HumanFriendlyTestCase.test_round_numberc                 C   s6   t j dd¡}t j t jd d¡}|  |t|ƒ¡ dS )z)Test :func:`humanfriendly.format_path()`.ú~ú.vimrcÚHOMEN)r¤   r¥   r¨   ÚenvironrÆ   r   ©rs   Úfriendly_pathÚabsolute_pathru   ru   rv   Útest_format_pathL  ó   z&HumanFriendlyTestCase.test_format_pathc                 C   s6   t j dd¡}t j t jd d¡}|  |t|ƒ¡ dS )z(Test :func:`humanfriendly.parse_path()`.rj  rk  rl  N)r¤   r¥   r¨   rm  rÆ   r   rn  ru   ru   rv   Útest_parse_pathR  rr  z%HumanFriendlyTestCase.test_parse_pathc                 C   s¸   dgg}t |ƒtdƒ ¡ ksJ ‚g d¢g d¢g}t |ƒtdƒ ¡ ks$J ‚g d¢}g d¢g d¢g}tt ||ƒƒtdƒ ¡ ks?J ‚dd	g}d
dgddgg}tt ||ƒƒtdƒ ¡ ksZJ ‚dS )z8Test :func:`humanfriendly.tables.format_pretty_table()`.zJust one columnzi
            -------------------
            | Just one column |
            -------------------
        ©rd   re   ÚThree©rï   Ú2Ú3z‘
            ---------------------
            | One | Two | Three |
            | 1   | 2   | 3     |
            ---------------------
        ©rÔ   rÕ   ÚcúÕ
            ---------------------
            | One | Two | Three |
            ---------------------
            | 1   | 2   | 3     |
            | a   | b   | c     |
            ---------------------
        zJust a labelzImportant numberszRow oneÚ15zRow twoÚ300a/  
            ------------------------------------
            | Just a label | Important numbers |
            ------------------------------------
            | Row one      |                15 |
            | Row two      |               300 |
            ------------------------------------
        N)r)   rR   Ústripr3   )rs   ÚdataÚcolumn_namesru   ru   rv   Útest_pretty_tablesX  s$   üûù	ùz(HumanFriendlyTestCase.test_pretty_tablesc                 C   óp   g d¢}g d¢g d¢g}t t||ƒƒtdƒ ¡ ksJ ‚g d¢}g d¢g d¢g}t t||ƒƒtdƒ ¡ ks6J ‚dS )z8Test :func:`humanfriendly.tables.format_robust_table()`.rt  rv  ry  z¾
            --------
            One: 1
            Two: 2
            Three: 3
            --------
            One: a
            Two: b
            Three: c
            --------
        ©rÔ   rÕ   zHere comes a
multi line column!á  
            ------------------
            One: 1
            Two: 2
            Three: 3
            ------------------
            One: a
            Two: b
            Three:
            Here comes a
            multi line column!
            ------------------
        N)r3   r*   rR   r~  ©rs   r€  r  ru   ru   rv   Útest_robust_tables€  s   
öôz(HumanFriendlyTestCase.test_robust_tablesc                 C   r‚  )z7Test :func:`humanfriendly.tables.format_smart_table()`.rt  rv  ry  r{  rƒ  r„  N)r3   r,   rR   r~  r…  ru   ru   rv   Útest_smart_tablesŸ  s   ùôz'HumanFriendlyTestCase.test_smart_tablesc                 C   s^   g d¢}g d¢g d¢g}|   t||ƒtdƒ ¡ ¡ g d¢g d¢g}|   t|ƒtdƒ ¡ ¡ dS )z5Test :func:`humanfriendly.tables.format_rst_table()`.rt  rv  ry  zÅ
                ===  ===  =====
                One  Two  Three
                ===  ===  =====
                1    2    3
                a    b    c
                ===  ===  =====
            zm
                =  =  =
                1  2  3
                a  b  c
                =  =  =
            N)rÆ   r+   rR   Úrstripr…  ru   ru   rv   Útest_rst_tables»  s   ÷ùz%HumanFriendlyTestCase.test_rst_tablesc                 C   s~   t g ƒdksJ ‚t dgƒdksJ ‚t ddgƒdksJ ‚t g d¢ƒdks%J ‚t g d¢dd�d	ks1J ‚t g d¢d
d�dks=J ‚dS )z.Test :func:`humanfriendly.text.concatenate()`.rø   r`   rb   zone and two)r`   rb   Úthreezone, two and threeÚor)Úconjunctionzone, two or threeT)Úserial_commazone, two, and threeN©rQ   rœ   ru   ru   rv   Útest_concatenate×  s   z&HumanFriendlyTestCase.test_concatenatec                 C   sn   ddl m} |  |dƒg ¡ |  |dƒdg¡ |  |dƒddg¡ |  |dƒg d¢¡ |  |d	ƒg d¢¡ d
S )z(Test :func:`humanfriendly.text.split()`.r   )Úsplitrø   rÝ   zfoo, barÚbarzfoo, bar, baz©rÝ   r‘  Úbazzfoo,bar,bazN)Úhumanfriendly.textr�  rÆ   )rs   r�  ru   ru   rv   Ú
test_splitâ  s   z HumanFriendlyTestCase.test_splitc              	   C   s   dD ]!\}}t t ¡ | ƒ}|  t|jdd�d| ¡ |  t|ƒ|¡ qt t ¡ d ƒ}|  |jd¡ t ƒ }t d¡ |  t|jdƒd	¡ t dd
�}t	dƒD ]}|� t d¡ W d  ƒ n1 sbw   Y  qN|  t|jdƒd¡ t dd
��}|dus~J ‚W d  ƒ dS 1 s‰w   Y  dS )z!Test :func:`humanfriendly.Timer`.)
)r_   r  )rc   ú	2 seconds)r  r  )r3  r  )i  r  )i   r  )i€Q r  )i £ r  )i€:	 r  )i u r  Trg  z%i.00gš™™™™™@r–  r_   r   rf  )Ú	resumablerc   Nz2.00)
r   ÚtimerÆ   r   Úelapsed_timeÚstrÚroundedÚsleepÚnormalize_timestampÚrange)rs   ÚsecondsÚtextÚtÚautomatic_timerÚresumable_timerÚiÚtimerru   ru   rv   Ú
test_timerë  s&   


ÿ€"ÿz HumanFriendlyTestCase.test_timerc                 C   sÌ   t ƒ }tdd|dd�}dD ]}|j|d� t d¡ q| ¡  | ¡ }| td¡ t	d¡}d	d
„ | 
t¡D ƒ}|  t|ƒdk¡ |  tdd„ |D ƒƒ¡ |  tdd„ |D ƒƒ¡ |  tt|ƒƒt|ƒ¡ dS )z#Test :func:`humanfriendly.Spinner`.útest spinnerr  T)ÚlabelÚtotalÚstreamÚinteractive)r_   rc   r  r  )Úprogressgš™™™™™É?rø   c                 S   s   g | ]}|r|‘qS ru   ru   ©Ú.0Úlineru   ru   rv   Ú
<listcomp>  ó    z6HumanFriendlyTestCase.test_spinner.<locals>.<listcomp>r   c                 s   ó   � | ]}d |v V  qdS )r§  Nru   r­  ru   ru   rv   Ú	<genexpr>  ó   € z5HumanFriendlyTestCase.test_spinner.<locals>.<genexpr>c                 s   r²  )ú%Nru   r­  ru   ru   rv   r³    r´  N)r   rC   Ústepr˜  rœ  ÚclearÚgetvalueÚreplacer2   r/   r�  r.   Ú
assertTruerm   ÚallrÆ   ÚsortedÚset)rs   rª  Úspinnerr¬  r<   Úlinesru   ru   rv   Útest_spinner  s   
ÿz"HumanFriendlyTestCase.test_spinnerc                 C   s:   t dd�� t d¡ W d  ƒ dS 1 sw   Y  dS )a²  
        Test :func:`humanfriendly.AutomaticSpinner`.

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

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

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


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

            Boring description.

            Supported options:

              -h, --help

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

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

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

            Supported options:

              -a, --an-awesome-option

                Explanation why this is an awesome option.

              -b, --a-boring-option

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

            Some introduction goes here.

            Supported options:

              -f, --first-option

                Explanation of first option.

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

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

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

              -n, --dry-run

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

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