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

Moving numpy check into test/Examples_Tests #7808

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/Examples_Tests/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ from Standard.Base import all
from Standard.Test import Test_Suite

import project.Examples_Spec
import project.Python_Examples_Spec

main = Test_Suite.run_main <|
Examples_Spec.spec
Python_Examples_Spec.spec
85 changes: 85 additions & 0 deletions test/Examples_Tests/src/Python_Examples_Spec.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from Standard.Base import all

from Standard.Test import Test, Test_Suite
import Standard.Test.Extensions

polyglot java import java.lang.System as Java_System
polyglot java import java.io.File as Java_File

pending_python_missing = if Polyglot.is_language_installed "python" then Nothing else """
Can't run Python tests, Python is not installed.


spec = Test.group "Python Examples" <|
enso_bin =
p = Java_System.getProperty "truffle.class.path.append"
s = p.split Java_File.separator
paths = s.take (Index_Sub_Range.While _!="..")
j = paths . join Java_File.separator
File.new j / if Platform.os == Platform.OS.Windows then "enso.bat" else "enso"

create_new_enso_project =
bin = enso_bin

tmp_file = File.create_temporary_file "enso_prj" ""
dir = tmp_file/".."/(tmp_file.name+".dir") . normalize
res = Process.run bin.path [ "--new", dir.path ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success
dir

Test.specify "Create Enso Project with numpy" pending=pending_python_missing <|
setup_venv dir =
gvm = File.new <| Java_System.getProperty "java.home"
python = gvm/"bin"/"graalpy"
res = Process.run python.path [ "-m", "venv", dir.path ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success

install_num_py dir =
python = dir/"bin"/"graalpy"
res = Process.run python.path [ "-m", "pip", "install", "numpy" ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success

rewrite_main_file dir =
main = dir/"src"/"Main.enso"
main.exists . should_be_true
code = """
foreign python random_array s = """
import numpy
return numpy.random.normal(size=s)

main = random_array 10

code . write main on_existing_file=Existing_File_Behavior.Overwrite

IO.println "==== Generating Enso Project ===="
prj = create_new_enso_project
IO.println "Project ready at "+prj.path

IO.println "==== Changing Main.enso ===="
rewrite_main_file prj

IO.println "==== Preparing Python Virtual Environment ===="
setup_venv prj/"polyglot"/"python"

IO.println "==== Installing numpy ===="
install_num_py prj/"polyglot"/"python"

IO.println "==== Executing project ===="

res = Process.run enso_bin.path [ "--run", prj.path ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success

IO.println "==== Done ===="

res.stdout.should_contain "array(["
res.stdout.should_contain "])"

main = Test_Suite.run_main spec
77 changes: 0 additions & 77 deletions test/Tests/src/System/Process_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ from Standard.Base import all
from Standard.Test import Test, Test_Suite
import Standard.Test.Extensions

polyglot java import java.lang.System as Java_System
polyglot java import java.io.File as Java_File

pending_python_missing = if Polyglot.is_language_installed "python" then Nothing else """
Can't run Python tests, Python is not installed.

spec =
Test.group "Process" <|
Test.specify "should call simple command" <|
Expand Down Expand Up @@ -112,76 +106,5 @@ spec =
run_result.exit_code.to_number . should_equal 0
run_result.stdout . should_equal 'sample'
run_result.stderr . should_equal ""
Test.group "Enso on Enso" <|
enso_bin =
p = Java_System.getProperty "truffle.class.path.append"
s = p.split Java_File.separator
paths = s.take (Index_Sub_Range.While _!="..")
j = paths . join Java_File.separator
File.new j / if Platform.os == Platform.OS.Windows then "enso.bat" else "enso"

create_new_enso_project =
bin = enso_bin

tmp_file = File.create_temporary_file "enso_prj" ""
dir = tmp_file/".."/(tmp_file.name+".dir") . normalize
res = Process.run bin.path [ "--new", dir.path ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success
dir

Test.specify "Create Enso Project with numpy" pending=pending_python_missing <|
setup_venv dir =
gvm = File.new <| Java_System.getProperty "java.home"
python = gvm/"bin"/"graalpy"
res = Process.run python.path [ "-m", "venv", dir.path ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success

install_num_py dir =
python = dir/"bin"/"graalpy"
res = Process.run python.path [ "-m", "pip", "install", "numpy" ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success

rewrite_main_file dir =
main = dir/"src"/"Main.enso"
main.exists . should_be_true
code = """
foreign python random_array s = """
import numpy
return numpy.random.normal(size=s)

main = random_array 10

code . write main on_existing_file=Existing_File_Behavior.Overwrite

IO.println "==== Generating Enso Project ===="
prj = create_new_enso_project
IO.println "Project ready at "+prj.path

IO.println "==== Changing Main.enso ===="
rewrite_main_file prj

IO.println "==== Preparing Python Virtual Environment ===="
setup_venv prj/"polyglot"/"python"

IO.println "==== Installing numpy ===="
install_num_py prj/"polyglot"/"python"

IO.println "==== Executing project ===="

res = Process.run enso_bin.path [ "--run", prj.path ]
IO.println res.stdout
IO.println res.stderr
res.exit_code . should_equal Exit_Code.Success

IO.println "==== Done ===="

res.stdout.should_contain "array(["
res.stdout.should_contain "])"

main = Test_Suite.run_main spec