B u `¸ã@srddlZddlZddlmmZddlmZddlTddlTddl m Z m Z ej ddgZ Gdd„dej ƒZ dS) éN)Úunittest)Ú*)ÚMappingÚSequenceÚcategoryZnottestc@s.eZdZdZeejj7Zddd„Zdd„ZdS) ÚTestCaseaoA Pyomo-specific class whose instances are single test cases. This class derives from unittest.TestCase and provides the following additional functionality: - extended suport for test categories - additional assertions: * :py:meth:`assertStructuredAlmostEqual` unittest.TestCase documentation ------------------------------- NFc CsØtdd„|||fDƒƒdkr$tdƒ‚|dk r6d| }|dk rB|}|dkrV|dkrVd}d} y| ||||| ¡WnR|jk rÄ} z2| |dt| ƒ||tj |¡tj |¡f¡} Wdd} ~ XYnX| rÔ| | ¡‚dS) a Test that first and second are equal up to a tolerance This compares first and second using both an absolute (`abstol`) and relative (`reltol`) tolerance. It will recursively descend into Sequence and Mapping containers (allowing for the relative comparison of structured data including lists and dicts). `places` and `delta` is supported for compatibility with assertAlmostEqual. If `places` is supplied, `abstol` is computed as `10**-places`. `delta` is an alias for `abstol`. If none of {`abstol`, `reltol`, `places`, `delta`} are specified, `reltol` defaults to 1e-7. If `allow_second_superset` is True, then: - only key/value pairs found in mappings in `first` are compared to `second` (allowing mappings in `second` to contain extra keys) - only values found in sequences in `first` are compared to `second` (allowing sequences in `second` to contain extra values) The relative error is computed for numerical values as `abs(first - second) / max(abs(first), abs(second))`, only when first != second (thereby avoiding divide-by-zero errors). Parameters ---------- first: the first value to compare second: the second value to compare places: int `first` and `second` are considered equivalent if their difference is between `places` decimal places; equivalent to `abstol = 10**-places` (included for compatibility with assertAlmostEqual) msg: str the message to raise on failure delta: float alias for `abstol` abstol: float the absolute tolerance. `first` and `second` are considered equivalent if their absolute difference is less than `abstol` reltol: float the relative tolerance. `first` and `second` are considered equivalent if their absolute difference divided by the larget of `first` and `second` is less than `reltol` allow_second_superset: bool If True, then extra entries in containers found on second will not trigger a failure. css|]}|dk rdVqdS)Né©)Ú.0Ú_r r ú9/tmp/pip-unpacked-wheel-n62dbgi3/pyomo/common/unittest.pyú esz7TestCase.assertStructuredAlmostEqual..rz7Cannot specify more than one of {places, delta, abstol}Né gH¯¼šò×z>z_%s Found when comparing with tolerance (abs=%s, rel=%s): first=%s second=%s) ÚsumÚ ValueErrorÚ_assertStructuredAlmostEqualÚfailureExceptionZ_formatMessageÚstrÚ _unittestÚcaseÚ safe_repr) ÚselfÚfirstÚsecondZplacesÚmsgÚdeltaÚreltolÚabstolZallow_second_supersetZfailÚer r r ÚassertStructuredAlmostEqual*s.;  $z$TestCase.assertStructuredAlmostEqualc Csf||f}tdd„|DƒƒrÜ|rHt|ƒt|ƒkrH| dt|ƒt|ƒf¡‚xŽ|D]†}||krr| dtj |¡f¡‚y| |||||||¡WqN|jk rÒ}z"| dt|ƒtj |¡f¡‚Wdd}~XYqNXqNWdStdd„|Dƒƒ�r||k�r@dS�n>tdd„|Dƒƒ�rÂ|�rHt|ƒt|ƒk�rH| d t|ƒt|ƒf¡‚xtt t ||ƒƒD]b\} \} } y| | | |||¡Wn<|jk �r¶}z| d t|ƒ| f¡‚Wdd}~XYnX�qXWdS||k�rÐdSybt |ƒ} t |ƒ} t | | ƒ} |dk �r| |k�rdS|dk �r0| t t | ƒt | ƒƒ|k�r0dSWn YnX| d tj |¡tj |¡f¡‚dS) z7Recursive implementation of assertStructuredAlmostEqualcss|]}t|tƒVqdS)N)Ú isinstancer)r r r r r r Šsz8TestCase._assertStructuredAlmostEqual..z'mappings are different sizes (%s != %s)z'key (%s) from first not found in secondz"%s Found when comparing key %sNcss|]}t|tjƒVqdS)N)r ÚsixÚ string_types)r r r r r r  scss|]}t|tƒVqdS)N)r r)r r r r r r ¤sz(sequences are different sizes (%s != %s)z%s Found at position %sz %s !~= %s)ÚallÚlenrrrrrrÚanyÚ enumerateÚzipÚfloatÚabsÚmax) rrrrrÚexactÚargsÚkeyrÚiÚfÚsZdiffr r r r…sj . *  & z%TestCase._assertStructuredAlmostEqual)NNNNNF)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrr r r r rs    Xr)Úmathr!Zpyutilib.th.pyunitÚthZpyunitZ_pyunitrrZ pyutilib.thZpyomo.common.collectionsrrÚ__all__rr r r r Ú s