forked from wala/ML
-
Notifications
You must be signed in to change notification settings - Fork 1
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 (#102)
- 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
19 changed files
with
310 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)) |
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)) |
9 changes: 9 additions & 0 deletions
9
com.ibm.wala.cast.python.test/data/tf2_test_decorated_method9.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,9 @@ | ||
import tensorflow as tf | ||
|
||
|
||
@mama | ||
def f(x): | ||
assert isinstance(x, tf.Tensor) | ||
|
||
|
||
f(tf.constant(1)) |
16 changes: 16 additions & 0 deletions
16
com.ibm.wala.cast.python.test/data/tf2_testing_decorator11.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,16 @@ | ||
import tensorflow as tf | ||
|
||
|
||
class C: | ||
|
||
@tf.function() | ||
def returned(self, a): | ||
assert isinstance(a, tf.Tensor) | ||
return a | ||
|
||
|
||
a = tf.range(5) | ||
assert isinstance(a, tf.Tensor) | ||
c = C() | ||
b = c.returned(a) | ||
assert isinstance(b, tf.Tensor) |
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