From 769494ba68f8c82bd22d7080bf97308cd586cce6 Mon Sep 17 00:00:00 2001 From: Raffi Khatchadourian Date: Wed, 10 Jul 2024 13:17:15 -0400 Subject: [PATCH] Add test for https://github.com/wala/ML/issues/202. --- .../cast/python/ml/test/TestTensorflow2Model.java | 14 ++++++++++++++ com.ibm.wala.cast.python.test/.pydevproject | 1 + com.ibm.wala.cast.python.test/data/proj56/A.py | 13 +++++++++++++ com.ibm.wala.cast.python.test/data/proj56/src/B.py | 9 +++++++++ .../data/proj56/src/__init__.py | 1 + 5 files changed, 38 insertions(+) create mode 100644 com.ibm.wala.cast.python.test/data/proj56/A.py create mode 100644 com.ibm.wala.cast.python.test/data/proj56/src/B.py create mode 100644 com.ibm.wala.cast.python.test/data/proj56/src/__init__.py diff --git a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java b/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java index 55950c46f..5a8210b1f 100644 --- a/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java +++ b/com.ibm.wala.cast.python.ml.test/source/com/ibm/wala/cast/python/ml/test/TestTensorflow2Model.java @@ -2704,6 +2704,20 @@ public void testModule60() new int[] {2}); } + /** Test https://github.com/wala/ML/issues/202. */ + @Test + public void testModule61() + throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { + test( + new String[] {"proj56/src/__init__.py", "proj56/src/B.py", "proj56/A.py"}, + "src/B.py", + "C.f", + "proj56", + 1, + 1, + new int[] {3}); + } + @Test public void testStaticMethod() throws ClassHierarchyException, CancelException, IOException { test("tf2_test_static_method.py", "MyClass.the_static_method", 1, 1, 2); diff --git a/com.ibm.wala.cast.python.test/.pydevproject b/com.ibm.wala.cast.python.test/.pydevproject index 82e8670dd..47c85339d 100644 --- a/com.ibm.wala.cast.python.test/.pydevproject +++ b/com.ibm.wala.cast.python.test/.pydevproject @@ -19,5 +19,6 @@ /${PROJECT_DIR_NAME}/data/proj51 /${PROJECT_DIR_NAME}/data/proj52 /${PROJECT_DIR_NAME}/data/proj55 + /${PROJECT_DIR_NAME}/data/proj56 diff --git a/com.ibm.wala.cast.python.test/data/proj56/A.py b/com.ibm.wala.cast.python.test/data/proj56/A.py new file mode 100644 index 000000000..67730deeb --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/proj56/A.py @@ -0,0 +1,13 @@ +# Test https://github.com/wala/ML/issues/163. + +from tensorflow import ones +from src import C + + +class D: + + def __init__(self): + C().f(ones([1, 2])) + + +D() diff --git a/com.ibm.wala.cast.python.test/data/proj56/src/B.py b/com.ibm.wala.cast.python.test/data/proj56/src/B.py new file mode 100644 index 000000000..bd4e3285a --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/proj56/src/B.py @@ -0,0 +1,9 @@ +# Test https://github.com/wala/ML/issues/163. + +from tensorflow import Tensor + + +class C: + + def f(self, a): + assert isinstance(a, Tensor) diff --git a/com.ibm.wala.cast.python.test/data/proj56/src/__init__.py b/com.ibm.wala.cast.python.test/data/proj56/src/__init__.py new file mode 100644 index 000000000..43795f312 --- /dev/null +++ b/com.ibm.wala.cast.python.test/data/proj56/src/__init__.py @@ -0,0 +1 @@ +from .B import C