def test_dir_object(): with example_app_process(): with gateway() as g: ex = g.getNewExample() print(sorted(dir(ex))) print(ExampleClassMethods) assert sorted(dir(ex)) == ExampleClassMethods
def test_help_class(): with example_app_process(): with gateway() as g: clazz = g.jvm.py4j.examples.ExampleClass doc = g.help(clazz, display=False) assert "Help on class ExampleClass in package py4j.examples" in doc assert "method1" in doc assert "method2" in doc
def test_help_object(): with example_app_process(): with gateway() as g: ex = g.getNewExample() doc = g.help(ex, display=False) assert "Help on class ExampleClass in package py4j.examples" in doc assert "method1" in doc assert "method2" in doc
def test_help_pattern_2(): with example_app_process(): with gateway() as g: ex = g.getNewExample() doc = g.help(ex, display=False, pattern="getField1(*") assert "Help on class ExampleClass in package py4j.examples" in doc assert "method1" not in doc assert "getField1" in doc
def test_doc_object(): with example_app_process(): with gateway() as g: ex = g.getNewExample() doc = ex.__doc__ assert "Help on class ExampleClass in package py4j.examples" in doc assert "method1" in doc assert "getField1" in doc
def test_not_callable(): with example_app_process(): with gateway() as g: ex = g.getNewExample() try: ex() raise AssertionError except TypeError as e: assert "object is not callable" in str(e)
def test_doc_class(): with example_app_process(): with gateway() as g: clazz = g.jvm.py4j.examples.ExampleClass doc = clazz.__doc__ # Make sure multiple method7s appear (overloaded method) assert "Help on class ExampleClass in package py4j.examples" in doc assert "method1" in doc assert "method2" in doc
def test_doc_method(): with example_app_process(): with gateway() as g: ex = g.getNewExample() doc = ex.method7.__doc__ # Make sure multiple method7s appear (overloaded method) assert "method7(int)" in doc assert "method7(Object)" in doc assert "method1" not in doc
def test_help_method(): with example_app_process(): with gateway() as g: ex = g.getNewExample() doc = g.help(ex.method7, display=False) # Make sure multiple method7s appear (overloaded method) assert "method7(int)" in doc assert "method7(Object)" in doc assert "method1" not in doc
def test_dir_object_shows_manually_called_before_dir(): with example_app_process(): with gateway() as g: ex = g.getNewExample() try: ex.does_not_exist_in_example() raise AssertionError("Method should not have succeeded") except Py4JError: pass # Make sure the manually called method now shows up assert sorted(dir(ex)) == sorted(ExampleClassMethods + ["does_not_exist_in_example"])
def test_dir_jvmview_two(): with example_app_process(): with gateway() as g: view1 = g.new_jvm_view() view2 = g.new_jvm_view() helper_dir_jvmview(view1) helper_dir_jvmview(view2) # now give them different contents java_import(view1, "com.fourth.Class4") java_import(view2, "com.fiftg.Class5") assert sorted(dir(view1)) == [UserHelpAutoCompletion.KEY, "Class1", "Class2", "Class3", "Class4"] assert sorted(dir(view2)) == [UserHelpAutoCompletion.KEY, "Class1", "Class2", "Class3", "Class5"]
def test_dir_jvmview_two(): with example_app_process(): with gateway() as g: view1 = g.new_jvm_view() view2 = g.new_jvm_view() helper_dir_jvmview(view1) helper_dir_jvmview(view2) # now give them different contents java_import(view1, "com.fourth.Class4") java_import(view2, "com.fiftg.Class5") assert sorted(dir(view1)) == [ UserHelpAutoCompletion.KEY, "Class1", "Class2", "Class3", "Class4"] assert sorted(dir(view2)) == [ UserHelpAutoCompletion.KEY, "Class1", "Class2", "Class3", "Class5"]
def test_dir_object_fields(): with example_app_process(): with gateway(auto_field=True) as g: ex = g.getNewExample() assert sorted(dir(ex)) == sorted(ExampleClassMethods + ExampleClassFields)
def test_dir_package(): with example_app_process(): with gateway() as g: assert sorted(dir(g.jvm)) == [UserHelpAutoCompletion.KEY] assert sorted(dir(g.jvm.java)) == [UserHelpAutoCompletion.KEY] assert sorted(dir(g.jvm.java.util)) == [UserHelpAutoCompletion.KEY]
def test_dir_jvmview_default(): with example_app_process(): with gateway() as g: helper_dir_jvmview(g.jvm)
def test_dir_jvmview_new(): with example_app_process(): with gateway() as g: view = g.new_jvm_view() helper_dir_jvmview(view)
def test_dir_object_fields(): with example_app_process(): with gateway(auto_field=True) as g: ex = g.getNewExample() assert sorted(dir(ex)) == sorted( ExampleClassMethods + ExampleClassFields)
def test_dir_class(): with example_app_process(): with gateway() as g: exclass = g.jvm.py4j.examples.ExampleClass assert sorted(dir(exclass)) == ExampleClassStatics