Skip to content

Update test_district_scripts to test against compiled Java #25

Description

@adamkorynta

Under the first pass of tests, simple source code checks were created (test_district_scripts.py) to ensure that scripts are calling real java methods. This did not go so far as to check arguments or do any Java reflection and spin up the JVM.

Doing so would provide more robust testing going forward and help ensure public API contracts are enforced via CI/CD tests. The following checks should be performed:

  • Arity + overloads: Method.getParameterTypes() gives you the exact parameter list per method. Since Java allows overloads, _load_java_api() would need to change from name -> set of names to name -> list of parameter-type-tuples, one entry per overload found via clazz.getDeclaredMethods().
  • Validating calls: FakeJavaObject._getattr_ currently returns _noop(*args, **kwargs) unconditionally. It'd need to become a stub that checks the incoming arg count against at least one registered overload's parameter count, and raises if none match — catching "called with wrong number of args" the way the compiler would.
  • Type checking: JPype does implicit Python→Java conversion (int→int/long/double, str→String, etc.), so exactly replicating the JVM's overload resolution from the Python side is nontrivial. What's realistic and still valuable: categorical checks — numeric-vs-numeric, string-vs-CharSequence/String, bool-vs-boolean — rather than exact type match. That catches "passed a string where a number was expected" without trying to fully replicate javac's overload resolution.
  • Cost of doing this: it means starting a real JVM in this test (reusing regi_session's LIB_PATH pattern — JPype only allows one JVM per process, so it must share that mechanism, not start a second one) and it needs the actual dependency jars on classpath, not just the compiled classes, because ScriptableInflowImpl etc. reference hec./usace.rowcps. types from other jars. That means smokeTestDistrictScripts also needs dependsOn bundlePython (or jar + runtimeClasspath) so the jars are guaranteed fresh, which is a real Gradle graph change, not just a Python edit. The test also gets slower since it now boots a JVM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions