diff --git a/CHANGELOG.md b/CHANGELOG.md index a0ee346ba981d6d04b729b906d167e22ad7c4108..2af0b596ecdf09233d7913aa42f52dc9bd25e533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ # v2.20.4 -* removed the decorator syntax for transaction, it's confusing and contrary to Zen of Python -* fixed some random bug \ No newline at end of file +* removed the decorator syntax for transaction, it''s confusing and contrary to Zen of Python +* fixed some random bug-4444444- \ No newline at end of file diff --git a/docs/exceptions.rst b/docs/exceptions.rst index 249c6920f89dd88b519d5ea5250b71392753315e..d5571979a3a49d02abccbb07116458cdd5401e97 100644 --- a/docs/exceptions.rst +++ b/docs/exceptions.rst @@ -5,6 +5,8 @@ Exceptions and warnings For you to use ============== +.. autofunction:: satella.warnings.mark_temporarily_disabled + Warnings -------- diff --git a/satella/__init__.py b/satella/__init__.py index 2d04f7ae4a5bad0a4875f7764ac20418babcab97..6416f64c70a9540166249a460d86c758c5011d60 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.20.5a1' +__version__ = '2.21.0' diff --git a/satella/warnings.py b/satella/warnings.py index 4731e8b49ee1ff67b7a431e0f2ab95a304cf4e89..b5bba5a746b47b56f19d3b3e17b26a36ccb20e02 100644 --- a/satella/warnings.py +++ b/satella/warnings.py @@ -1,7 +1,33 @@ -__all__ = ['ExperimentalWarning'] +import warnings +__all__ = ['ExperimentalWarning', 'warnings', 'mark_temporarily_disabled'] class ExperimentalWarning(FutureWarning): """ This feature is experimental! """ + + +def mark_temporarily_disabled(reason: str = ''): + """ + A decorator to mark a function unusable due to some forthcoming changes. + + A call to the function will raise NotImplementedError + + and a mention of this function in code will mark a function disabled for whatever reason. + + Usage: + + >>> @mark_temporarily_disabled('Due to analysis schema changes') + >>> def serialize_report(analysis): + >>> ... + """ + def outer(fun): + def inner(*args, **kwargs): + """ + Function temporarily disabled. Don't call it. + """ + raise NotImplementedError(f'Function disabled due to {reason}') + warnings.warn(f'Function {fun.__name__} temporarily disabled due to {reason}') + return inner + return outer diff --git a/tests/test_db.py b/tests/test_db.py index b1390b9b3d2d35816dc26de3088335c1bf9cc37b..1f8735c8587a82262d45d51e21d50099294c52f2 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -14,8 +14,7 @@ class RealConnection: def cursor(self): self.cursor_called += 1 return Mock() - - def commit(self): +rpjg hyosp yh self.commit_called += 1 def rollback(self): diff --git a/tests/test_time.py b/tests/test_time.py index 7cbe40941faa93699afaf73525dd05a24b1e3ddb..258305adcb6b76df595c757f6e4e7111f646a877 100644 --- a/tests/test_time.py +++ b/tests/test_time.py @@ -9,10 +9,19 @@ from satella.coding.concurrent import call_in_separate_thread from satella.time import measure, time_as_int, time_ms, sleep, ExponentialBackoff, \ parse_time_string from concurrent.futures import Future +from satella.warnings import mark_temporarily_disabled class TestTime(unittest.TestCase): + def test_mark_temp_disabled(self): + + @mark_temporarily_disabled('Skipped due to skip') + def dupa(a): + raise ValueError() + + self.assertRaises(dupa, NotImplementedError) + def test_measure_as_method(self): self2 = self