def warns_deprecated_sympy(): '''Shorthand for ``warns(SymPyDeprecationWarning)`` This is the recommended way to test that ``SymPyDeprecationWarning`` is emitted for deprecated features in SymPy. To test for other warnings use ``warns``. To suppress warnings without asserting that they are emitted use ``ignore_warnings``. >>> from sympy.utilities.pytest import warns_deprecated_sympy >>> from sympy.utilities.exceptions import SymPyDeprecationWarning >>> import warnings >>> with warns_deprecated_sympy(): ... SymPyDeprecationWarning("Don't use", feature="old thing", ... deprecated_since_version="1.0", issue=123).warn() >>> with warns_deprecated_sympy(): ... pass Traceback (most recent call last): ... Failed: DID NOT WARN. No warnings of type \ SymPyDeprecationWarning was emitted. The list of emitted warnings is: []. ''' with warns(SymPyDeprecationWarning): yield
def test_compact_mode_unspecified(): # Other tests may have raised deprecation warning, so reset the cache here numpy_encode._warned_compact = False data = [ array([[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]]), array([pi, exp(1)]) ] with warns(JsonTricksDeprecation): gz_json_1 = dumps(data, compression=True) # noinspection PyTypeChecker with warns(None) as captured: gz_json_2 = dumps(data, compression=True) assert len(captured) == 0 assert gz_json_1 == gz_json_2 json = gzip_decompress(gz_json_1).decode('ascii') assert json == '[{"__ndarray__": [[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]], "dtype": "float64", "shape": [2, 4], "Corder": true}, ' \ '{"__ndarray__": [3.141592653589793, 2.718281828459045], "dtype": "float64", "shape": [2]}]'
def test_ignore_comments_deprecation(): # https://github.com/mverleg/pyjson_tricks/issues/74 # First time should have deprecation warning loads._ignore_comments_warned_ = False with warns(JsonTricksDeprecation): loads(test_json_with_comments) # Second time there should be no warning # noinspection PyTypeChecker with warns(None) as captured: loaded = loads(test_json_with_comments) assert len(captured) == 0 assert loaded == test_object_for_comment_strings # Passing a string without comments should not have a warning loads._ignore_comments_warned_ = False # noinspection PyTypeChecker with warns(None) as captured: loaded = loads(test_json_without_comments) assert len(captured) == 0 # Passing True for argument explicitly should not have a warning loads._ignore_comments_warned_ = False # noinspection PyTypeChecker with warns(None) as captured: loaded = loads(test_json_with_comments, ignore_comments=True) assert len(captured) == 0 assert loaded == test_object_for_comment_strings # Passing False for argument explicitly should not have a warning loads._ignore_comments_warned_ = False # noinspection PyTypeChecker with warns(None) as captured: loaded = loads(test_json_without_comments, ignore_comments=False) assert len(captured) == 0 assert loaded == test_object_for_comment_strings