Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Jan 21, 2021
1 parent d660d9c commit 5759363
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions tests/utils/decorators_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import warnings
from unittest.mock import call, Mock

from superset.utils import decorators
Expand Down Expand Up @@ -41,3 +42,81 @@ def myfunc(arg1: int, arg2: int, kwarg1: str = "abc", kwarg2: int = 2):
result = myfunc(1, 0, kwarg1="haha", kwarg2=2)
mock.assert_has_calls([call(1, "abc"), call(1, "haha")])
self.assertEqual(result, 3)

def test_guard_func(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

@decorators.guard("`x=c{#?3CakO9ObP>|Wn")
def some_function(a, b):
return a + b

# should trigger no warnings
assert len(w) == 0

def test_guard_func_modified(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

@decorators.guard("`x=c{#?3CakO9ObP>|Wn")
def some_function(a, b, c):
return a + b

assert len(w) == 1

def test_guard_class(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

@decorators.guard("x-@vK+|sloQN3GFZK8l<")
class SomeClass:
def __init__(self, a, b):
self.a = a
self.b = b

# should trigger no warnings
assert len(w) == 0

def test_guard_class_change_init(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

@decorators.guard("x-@vK+|sloQN3GFZK8l<")
class SomeClass:
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c

assert len(w) == 1

def test_guard_class_add_public_method(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

@decorators.guard("x-@vK+|sloQN3GFZK8l<")
class SomeClass:
def __init__(self, a, b):
self.a = a
self.b = b

def add(self):
return self.a + self.b

assert len(w) == 1

def test_guard_class_add_private_method(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")

@decorators.guard("x-@vK+|sloQN3GFZK8l<")
class SomeClass:
def __init__(self, a, b):
self.a = a
self.b = b

def _add(self):
return self.a + self.b

# should trigger no warnings
assert len(w) == 0

0 comments on commit 5759363

Please sign in to comment.