From 585b21eace63cb42f8cd86c33179c3c7bcbbcf05 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Sat, 30 Jul 2022 03:34:23 +0200
Subject: [PATCH] Added mark_temporarily_disabled

---
 CHANGELOG.md        |  4 ++--
 docs/exceptions.rst |  2 ++
 satella/__init__.py |  2 +-
 satella/warnings.py | 28 +++++++++++++++++++++++++++-
 tests/test_db.py    |  3 +--
 tests/test_time.py  |  9 +++++++++
 6 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a0ee346b..2af0b596 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 249c6920..d5571979 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 2d04f7ae..6416f64c 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 4731e8b4..b5bba5a7 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 b1390b9b..1f8735c8 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 7cbe4094..258305ad 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
 
-- 
GitLab