Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pytest entrypoints #86

Merged
merged 13 commits into from
Feb 23, 2024
Merged

Fix pytest entrypoints #86

merged 13 commits into from
Feb 23, 2024

Conversation

khatchad
Copy link
Member

@khatchad khatchad commented Feb 22, 2024

Not previously working.

Need to the following:

@khatchad khatchad added bug Something isn't working entrypoints labels Feb 22, 2024
@khatchad khatchad self-assigned this Feb 22, 2024
@khatchad khatchad marked this pull request as ready for review February 23, 2024 16:42
@khatchad khatchad enabled auto-merge (squash) February 23, 2024 16:43
khatchad pushed a commit that referenced this pull request Feb 23, 2024
Currently, we are using jython2 in `com.ibm.wala.cast.python.ml.test`,
where we don't encounter decorator problems when running the tests. But
when we use jython3, we do encounter problems with decorator
`tf.function`. Therefore we are adding initial support for the decorator
`tf.function` in `tensorflow.xml`. Initial support for `tf.function`
because after this change, in jython3, can now process the decorator
that has parenthesis e.g. `tf.function()` or `tf.function(...)`.

Refer to wala#33 for the issue with
inconsistent jython versions.

After this change we see:
Test code with parenthesis: 

```python
import tensorflow as tf

@tf.function()
def returned(a):
  return a

a = tf.range(5)
b = returned(a)
```
The analysis of the test with parenthesis:
```
answer:
[Node: <Code body of function Lscript tf2_testing_decorator.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v251][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Ret-V:Node: synthetic < PythonLoader, Ltensorflow/functions/range, do()LRoot; > Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@96 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: synthetic < PythonLoader, Ltensorflow/functions/range, do()LRoot; > Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@96 ], v6][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_testing_decorator.py/returned> Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@98 ], v2][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_testing_decorator.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v257][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Ret-V:Node: <Code body of function Lscript tf2_testing_decorator.py/returned> Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@98 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
```

Test code with parenthesis: 

```python
import tensorflow as tf

@tf.function
def returned(a):
  return a

a = tf.range(5)
b = returned(a)
```

The analysis of the test without parenthesis:
```
answer:
[Node: <Code body of function Lscript tf2_testing_decorator.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v249][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Ret-V:Node: synthetic < PythonLoader, Ltensorflow/functions/range, do()LRoot; > Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@95 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: synthetic < PythonLoader, Ltensorflow/functions/range, do()LRoot; > Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@95 ], v6][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: synthetic < PythonLoader, Ltensorflow/class/Function, do()LRoot; > Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@97 ], v2][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Node: <Code body of function Lscript tf2_testing_decorator.py> Context: CallStringContext: [ com.ibm.wala.FakeRootClass.fakeRootMethod()V@2 ], v255][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
[Ret-V:Node: synthetic < PythonLoader, Ltensorflow/class/Function, do()LRoot; > Context: CallStringContext: [ script tf2_testing_decorator.py.do()LRoot;@97 ]][{[D:Symbolic,n, D:Compound,[D:Constant,28, D:Constant,28]] of pixel}]
```

We see that with the decorator, `expr` is classified as a `CALL`, and
without it is classified as an `Attribute`.
@khatchad khatchad merged commit cec9124 into master Feb 23, 2024
3 checks passed
@khatchad khatchad deleted the fix_pytest_entrypoints branch February 23, 2024 16:46
khatchad added a commit that referenced this pull request Feb 23, 2024
* Initial fix.

* Use Guava to merge the iterables.

Looks a lot cleaner.

* Cleaning.

* Log entrypoints.

* Enhance.

* Add pytest calls to methods test.

* Update .gitignore.

* Move to new class.

* Add pytest test class with an explicit ctor.

* Simply assertions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working entrypoints
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant