mirror of
https://github.com/apache/superset.git
synced 2026-04-21 17:14:57 +00:00
chore(python-testing): move memoized tests to unit tests (#15507)
* chore: move memoized test into a separated file create integration test workflow * chore: create unit test workflow to run purely pytest * fix: bad reference * fix: remove pip requirements bc there aren't any yet * temp: install unit dependencies directly * fix: --rootdir= * fix: try to run only unit test * chore: decouple memoized as separated module * fix: bring back dependencies bc superset top-level module is coupled to flask and others so no reason no to do it * fix: reference * fix: pre-commit * fix: pylint
This commit is contained in:
@@ -57,7 +57,6 @@ from superset.utils.core import (
|
||||
json_int_dttm_ser,
|
||||
json_iso_dttm_ser,
|
||||
JSONEncodedDict,
|
||||
memoized,
|
||||
merge_extra_filters,
|
||||
merge_extra_form_data,
|
||||
merge_request_params,
|
||||
@@ -581,79 +580,6 @@ class TestUtils(SupersetTestCase):
|
||||
with self.assertRaises(SupersetException):
|
||||
validate_json(invalid)
|
||||
|
||||
def test_memoized_on_functions(self):
|
||||
watcher = {"val": 0}
|
||||
|
||||
@memoized
|
||||
def test_function(a, b, c):
|
||||
watcher["val"] += 1
|
||||
return a * b * c
|
||||
|
||||
result1 = test_function(1, 2, 3)
|
||||
result2 = test_function(1, 2, 3)
|
||||
self.assertEqual(result1, result2)
|
||||
self.assertEqual(watcher["val"], 1)
|
||||
|
||||
def test_memoized_on_methods(self):
|
||||
class test_class:
|
||||
def __init__(self, num):
|
||||
self.num = num
|
||||
self.watcher = 0
|
||||
|
||||
@memoized
|
||||
def test_method(self, a, b, c):
|
||||
self.watcher += 1
|
||||
return a * b * c * self.num
|
||||
|
||||
instance = test_class(5)
|
||||
result1 = instance.test_method(1, 2, 3)
|
||||
result2 = instance.test_method(1, 2, 3)
|
||||
self.assertEqual(result1, result2)
|
||||
self.assertEqual(instance.watcher, 1)
|
||||
instance.num = 10
|
||||
self.assertEqual(result2, instance.test_method(1, 2, 3))
|
||||
|
||||
def test_memoized_on_methods_with_watches(self):
|
||||
class test_class:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.watcher = 0
|
||||
|
||||
@memoized(watch=("x", "y"))
|
||||
def test_method(self, a, b, c):
|
||||
self.watcher += 1
|
||||
return a * b * c * self.x * self.y
|
||||
|
||||
instance = test_class(3, 12)
|
||||
result1 = instance.test_method(1, 2, 3)
|
||||
result2 = instance.test_method(1, 2, 3)
|
||||
self.assertEqual(result1, result2)
|
||||
self.assertEqual(instance.watcher, 1)
|
||||
result3 = instance.test_method(2, 3, 4)
|
||||
self.assertEqual(instance.watcher, 2)
|
||||
result4 = instance.test_method(2, 3, 4)
|
||||
self.assertEqual(instance.watcher, 2)
|
||||
self.assertEqual(result3, result4)
|
||||
self.assertNotEqual(result3, result1)
|
||||
instance.x = 1
|
||||
result5 = instance.test_method(2, 3, 4)
|
||||
self.assertEqual(instance.watcher, 3)
|
||||
self.assertNotEqual(result5, result4)
|
||||
result6 = instance.test_method(2, 3, 4)
|
||||
self.assertEqual(instance.watcher, 3)
|
||||
self.assertEqual(result6, result5)
|
||||
instance.x = 10
|
||||
instance.y = 10
|
||||
result7 = instance.test_method(2, 3, 4)
|
||||
self.assertEqual(instance.watcher, 4)
|
||||
self.assertNotEqual(result7, result6)
|
||||
instance.x = 3
|
||||
instance.y = 12
|
||||
result8 = instance.test_method(1, 2, 3)
|
||||
self.assertEqual(instance.watcher, 4)
|
||||
self.assertEqual(result1, result8)
|
||||
|
||||
@patch("superset.utils.core.to_adhoc", mock_to_adhoc)
|
||||
def test_convert_legacy_filters_into_adhoc_where(self):
|
||||
form_data = {"where": "a = 1"}
|
||||
|
||||
Reference in New Issue
Block a user