Skip to content

Commit

Permalink
Decorator fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
khatchad committed May 2, 2024
1 parent 767b419 commit d40186b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3691,6 +3691,17 @@ public void testDecoratedMethod13() throws ClassHierarchyException, CancelExcept
test("tf2_test_decorated_method13.py", "f", 0, 0);
}

@Test
public void testDecoratedFunctions()
throws ClassHierarchyException, CancelException, IOException {
test("tf2_test_decorated_functions.py", "dummy_fun", 1, 1, 2);
test("tf2_test_decorated_functions.py", "dummy_test", 1, 1, 2);
test("tf2_test_decorated_functions.py", "test_function", 1, 1, 2);
test("tf2_test_decorated_functions.py", "test_function2", 1, 1, 2);
test("tf2_test_decorated_functions.py", "test_function3", 1, 1, 2);
test("tf2_test_decorated_functions.py", "test_function4", 1, 1, 2);
}

private void test(
String filename,
String functionName,
Expand Down
22 changes: 22 additions & 0 deletions com.ibm.wala.cast.python.ml/data/tensorflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@
<putfield class="LRoot" field="from_row_starts" fieldType="LRoot" ref="RaggedTensor" value="from_row_starts" />
<new def="from_value_rowids" class="Ltensorflow/functions/from_value_rowids" />
<putfield class="LRoot" field="from_value_rowids" fieldType="LRoot" ref="RaggedTensor" value="from_value_rowids" />
<new def="autograph" class="Lobject" />
<putfield class="LRoot" field="autograph" fieldType="LRoot" ref="x" value="autograph" />
<putfield class="LRoot" field="experimental" fieldType="LRoot" ref="autograph" value="experimental" />
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/autograph/experimental/do_not_convert -->
<new def="do_not_convert" class="Ltensorflow/class/do_not_convert" />
<putfield class="LRoot" field="do_not_convert" fieldType="LRoot" ref="experimental" value="do_not_convert" />
<return value="x" />
</method>
</class>
Expand Down Expand Up @@ -291,6 +297,22 @@
<return value="params" />
</method>
</class>
<class name="Do_not_convert" allocatable="true">
<method name="do" descriptor="()LRoot;" numArgs="2" paramNames="self test">
<putfield class="LRoot" field="params" fieldType="LRoot" ref="test" value="self" />
<return value="test" />
</method>
</class>
<class name="do_not_convert" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/autograph/experimental/do_not_convert -->
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self params values extra">
<new def="closure" class="Ltensorflow/class/Do_not_convert" />
<putfield class="LRoot" field="test" fieldType="LRoot" ref="closure" value="self" />
<putfield class="LRoot" field="params" fieldType="LRoot" ref="closure" value="params" />
<putfield class="LRoot" field="values" fieldType="LRoot" ref="closure" value="values" />
<return value="closure" />
</method>
</class>
</package>
<package name="tensorflow/objects">
<class name="feature" allocatable="true" />
Expand Down
41 changes: 41 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_decorated_functions.py
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))
23 changes: 21 additions & 2 deletions com.ibm.wala.cast.python/data/pytest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<putfield class="LRoot" field="parametrize" fieldType="LRoot" ref="mark" value="parametrize" />
<new def="skip" class="Lpytest/class/skip" />
<putfield class="LRoot" field="skip" fieldType="LRoot" ref="mark" value="skip" />
<new def="skipif" class="Lpytest/class/skipif" />
<putfield class="LRoot" field="skipif" fieldType="LRoot" ref="mark" value="skipif" />
<return value="x" />
</method>
</class>
Expand Down Expand Up @@ -39,10 +41,27 @@
</class>
<class name="skip" allocatable="true">
<!-- https://docs.pytest.org/en/8.2.x/reference/reference.html#pytest.mark.skip -->
<method name="do" descriptor="()LRoot;" numArgs="2" paramNames="self reason">
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self params values extra">
<new def="closure" class="Lpytest/class/Skip" />
<putfield class="LRoot" field="test" fieldType="LRoot" ref="closure" value="self" />
<putfield class="LRoot" field="params" fieldType="LRoot" ref="closure" value="reason" />
<putfield class="LRoot" field="params" fieldType="LRoot" ref="closure" value="params" />
<putfield class="LRoot" field="values" fieldType="LRoot" ref="closure" value="values" />
<return value="closure" />
</method>
</class>
<class name="Skipif" allocatable="true">
<method name="do" descriptor="()LRoot;" numArgs="2" paramNames="self test">
<putfield class="LRoot" field="params" fieldType="LRoot" ref="test" value="self" />
<return value="test" />
</method>
</class>
<class name="skipif" allocatable="true">
<!-- https://docs.pytest.org/en/8.2.x/reference/reference.html#pytest.mark.skipif -->
<method name="do" descriptor="()LRoot;" numArgs="4" paramNames="self params values extra">
<new def="closure" class="Lpytest/class/Skipif" />
<putfield class="LRoot" field="test" fieldType="LRoot" ref="closure" value="self" />
<putfield class="LRoot" field="params" fieldType="LRoot" ref="closure" value="params" />
<putfield class="LRoot" field="values" fieldType="LRoot" ref="closure" value="values" />
<return value="closure" />
</method>
</class>
Expand Down

0 comments on commit d40186b

Please sign in to comment.