|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +""" |
| 4 | +Created on Fri Mar 28 13:58:54 2025 |
| 5 | +
|
| 6 | +@author: ian |
| 7 | +""" |
| 8 | + |
| 9 | +import scyjava |
| 10 | +from scyjava.config import Mode, mode |
| 11 | + |
| 12 | +scyjava.config.endpoints.append("net.imagej:imagej") |
| 13 | +scyjava.config.endpoints.append("net.imagej:imagej-legacy:MANAGED") |
| 14 | + |
| 15 | + |
| 16 | +class TestIntrospection(object): |
| 17 | + """ |
| 18 | + Test introspection functionality. |
| 19 | + """ |
| 20 | + |
| 21 | + def test_find_java_methods(self): |
| 22 | + if mode == Mode.JEP: |
| 23 | + # JEP does not support the jclass function. |
| 24 | + return |
| 25 | + str_String = "java.lang.String" |
| 26 | + String = scyjava.jimport(str_String) |
| 27 | + str_Obj = scyjava.find_java(str_String, "methods") |
| 28 | + jimport_Obj = scyjava.find_java(String, "methods") |
| 29 | + assert len(str_Obj) > 0 |
| 30 | + assert len(jimport_Obj) > 0 |
| 31 | + assert jimport_Obj is not None |
| 32 | + assert jimport_Obj == str_Obj |
| 33 | + |
| 34 | + def test_find_java_fields(self): |
| 35 | + if mode == Mode.JEP: |
| 36 | + # JEP does not support the jclass function. |
| 37 | + return |
| 38 | + str_BitSet = "java.util.BitSet" |
| 39 | + BitSet = scyjava.jimport(str_BitSet) |
| 40 | + str_Obj = scyjava.find_java(str_BitSet, "fields") |
| 41 | + bitset_Obj = scyjava.find_java(BitSet, "fields") |
| 42 | + assert len(str_Obj) == 0 |
| 43 | + assert len(bitset_Obj) == 0 |
| 44 | + assert bitset_Obj is not None |
| 45 | + assert bitset_Obj == str_Obj |
| 46 | + |
| 47 | + def test_find_source(self): |
| 48 | + if mode == Mode.JEP: |
| 49 | + # JEP does not support the jclass function. |
| 50 | + return |
| 51 | + str_SF = "org.scijava.search.SourceFinder" |
| 52 | + SF = scyjava.jimport(str_SF) |
| 53 | + source_strSF = scyjava.java_source(str_SF) |
| 54 | + source_SF = scyjava.java_source(SF) |
| 55 | + github_home = "https://github.com/" |
| 56 | + assert source_strSF.startsWith(github_home) |
| 57 | + assert source_SF.startsWith(github_home) |
| 58 | + assert source_strSF == source_SF |
| 59 | + |
| 60 | + def test_imagej_legacy(self): |
| 61 | + if mode == Mode.JEP: |
| 62 | + # JEP does not support the jclass function. |
| 63 | + return |
| 64 | + str_RE = "ij.plugin.RoiEnlarger" |
| 65 | + table = scyjava.find_java(str_RE, aspect="methods") |
| 66 | + assert len([entry for entry in table if entry["static"]]) == 3 |
| 67 | + github_home = "https://github.com/" |
| 68 | + assert scyjava.java_source(str_RE).startsWith(github_home) |
0 commit comments