-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests and changes for decorators (#193)
- Decorator testing. - Actually capture the decorated function for @tf.function decorated functions. - Add `pytest.mark.skip` summary. - Use pytest summary for all Python analysis. There are some decorators it may work for. - Test pytest decorator.
- Loading branch information
Showing
20 changed files
with
404 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
com.ibm.wala.cast.python.test/data/tf2_test_abstract_method3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# From https://blog.teclado.com/python-abc-abstract-base-classes/#introducing-abstract-classes. | ||
import tensorflow as tf | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class C(ABC): | ||
|
||
@abstractmethod | ||
def f(self, x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
c = C() | ||
c.f(tf.constant(1)) |
41 changes: 41 additions & 0 deletions
41
com.ibm.wala.cast.python.test/data/tf2_test_decorated_functions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import tensorflow | ||
import pytest | ||
import sys | ||
|
||
|
||
@tensorflow.autograph.experimental.do_not_convert | ||
def dummy_fun(a): | ||
pass | ||
|
||
|
||
@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)]) | ||
def dummy_test(x, test_input, expected): | ||
pass | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") | ||
def test_function(x): | ||
pass | ||
|
||
|
||
@pytest.mark.skip(reason="requires python3.10 or higher") | ||
def test_function2(x): | ||
pass | ||
|
||
|
||
@pytest.mark.skip("requires python3.10 or higher") | ||
def test_function3(x): | ||
pass | ||
|
||
|
||
@pytest.mark.skip | ||
def test_function4(x): | ||
pass | ||
|
||
|
||
dummy_fun(tensorflow.constant(1)) | ||
dummy_test(tensorflow.constant(1), "1", "1") | ||
test_function(tensorflow.constant(1)) | ||
test_function2(tensorflow.constant(1)) | ||
test_function3(tensorflow.constant(1)) | ||
test_function4(tensorflow.constant(1)) |
8 changes: 8 additions & 0 deletions
8
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
13 changes: 13 additions & 0 deletions
13
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method10.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(my_func): | ||
return my_func | ||
|
||
|
||
@mama | ||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
10 changes: 10 additions & 0 deletions
10
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method11.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import tensorflow as tf | ||
import pytest | ||
|
||
|
||
@pytest.mark.skip | ||
def f(a): | ||
assert isinstance(a, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
27 changes: 27 additions & 0 deletions
27
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method12.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Test https://github.com/wala/ML/issues/188. | ||
|
||
import tensorflow as tf | ||
|
||
|
||
def mama(test=None): | ||
assert test == "Hello" | ||
|
||
def _mama(func): | ||
|
||
def core(*args, **kwargs): | ||
assert isinstance(args[0], tf.Tensor) | ||
return func(*args, **kwargs) | ||
|
||
return core | ||
|
||
return _mama | ||
|
||
|
||
@mama(test="Hello") | ||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
return 5 | ||
|
||
|
||
res = f(tf.constant(1)) | ||
assert res == 5 |
13 changes: 13 additions & 0 deletions
13
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method13.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(my_func=None): | ||
return my_func | ||
|
||
|
||
@mama | ||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
20 changes: 20 additions & 0 deletions
20
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Test for https://github.com/wala/ML/issues/188. | ||
|
||
import tensorflow as tf | ||
|
||
|
||
def mama(fun): | ||
|
||
def wrapper_fun(*args, **kwargs): | ||
assert isinstance(args[0], tf.Tensor) | ||
fun(*args, **kwargs) | ||
|
||
return wrapper_fun | ||
|
||
|
||
@mama | ||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
13 changes: 13 additions & 0 deletions
13
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method3.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(fun): | ||
return fun | ||
|
||
|
||
@mama | ||
def raffi(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
raffi(tf.constant(1)) |
12 changes: 12 additions & 0 deletions
12
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method4.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(fun): | ||
return fun | ||
|
||
|
||
def raffi(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
raffi(tf.constant(1)) |
12 changes: 12 additions & 0 deletions
12
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method5.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(fun): | ||
return fun | ||
|
||
|
||
def raffi(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
mama(raffi(tf.constant(1))) |
17 changes: 17 additions & 0 deletions
17
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method6.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(fun): | ||
|
||
def wrapper_fun(*args, **kwargs): | ||
assert isinstance(args[0], tf.Tensor) | ||
fun(*args, **kwargs) | ||
|
||
return wrapper_fun | ||
|
||
|
||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
17 changes: 17 additions & 0 deletions
17
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method7.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def mama(fun): | ||
|
||
def wrapper_fun(*args, **kwargs): | ||
assert isinstance(args[0], tf.Tensor) | ||
fun(*args, **kwargs) | ||
|
||
return wrapper_fun | ||
|
||
|
||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
mama(f(tf.constant(1))) |
8 changes: 8 additions & 0 deletions
8
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method8.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import tensorflow as tf | ||
|
||
|
||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
Oops, something went wrong.