1- # Copyright (c) 2023, 2024 , Oracle and/or its affiliates. All rights reserved.
1+ # Copyright (c) 2023, 2025 , Oracle and/or its affiliates. All rights reserved.
22# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33#
44# The Universal Permissive License (UPL), Version 1.0
4444from tests .standalone import util
4545
4646is_enabled = 'ENABLE_STANDALONE_UNITTESTS' in os .environ and os .environ ['ENABLE_STANDALONE_UNITTESTS' ] == "true"
47+ constraints_file = os .path .join (os .path .dirname (os .path .abspath (__file__ )), 'constraints.txt' )
48+
49+ def create_test_env ():
50+ env = os .environ .copy ()
51+ env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
52+ env ["PIP_CONSTRAINT" ] = constraints_file
53+ return env
4754
4855@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
4956def test_native_executable_one_file ():
5057 graalpy = util .get_gp ()
5158 if graalpy is None :
5259 return
53- env = os .environ .copy ()
54- env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
5560
61+ env = create_test_env ()
5662 with tempfile .TemporaryDirectory () as tmpdir :
5763
5864 source_file = os .path .join (tmpdir , "hello.py" )
5965 with open (source_file , 'w' ) as f :
6066 f .write ("import sys\n " )
6167 f .write ("print('hello world, argv[1:]:', sys.argv[1:])" )
6268
69+ log = util .Logger ()
70+
6371 target_file = os .path .join (tmpdir , "hello" )
6472 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-ce" , "-m" , source_file , "-o" , target_file ]
6573
66- out , return_code = util .run_cmd (cmd , env , print_out = True )
67- util .check_ouput ("Bundling Python resources into" , out )
68- util .check_ouput ("Finished generating 'hello' in" , out )
74+ out , return_code = util .run_cmd (cmd , env , print_out = True , logger = log )
75+ assert return_code == 0 , log
76+ util .check_ouput ("Bundling Python resources into" , out , logger = log )
77+ util .check_ouput ("Finished generating 'hello' in" , out , logger = log )
6978
7079 cmd = [target_file , "arg1" , "arg2" ]
71- out , return_code = util .run_cmd (cmd , env )
72- util .check_ouput ("hello world, argv[1:]: " + str (cmd [1 :]), out )
80+ out , return_code = util .run_cmd (cmd , env , logger = log )
81+ assert return_code == 0 , log
82+ util .check_ouput ("hello world, argv[1:]: " + str (cmd [1 :]), out , logger = log )
7383
7484@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
7585def test_native_executable_venv_and_one_file ():
7686 graalpy = util .get_gp ()
7787 if graalpy is None :
7888 return
79- env = os .environ .copy ()
80- env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
8189
90+ env = create_test_env ()
8291 with tempfile .TemporaryDirectory () as target_dir :
8392 source_file = os .path .join (target_dir , "hello.py" )
8493 with open (source_file , 'w' ) as f :
@@ -89,33 +98,38 @@ def test_native_executable_venv_and_one_file():
8998 f .write ('d = ujson.loads("""{"key": "value"}""")\n ' )
9099 f .write ("print('key=' + d['key'])\n " )
91100
101+ log = util .Logger ()
102+
92103 venv_dir = os .path .join (target_dir , "venv" )
93104 cmd = [graalpy , "-m" , "venv" , venv_dir ]
94- out , return_code = util .run_cmd (cmd , env )
105+ out , return_code = util .run_cmd (cmd , env , logger = log )
106+ assert return_code == 0 , log
95107
96108 venv_python = os .path .join (venv_dir , "Scripts" , "python.exe" ) if os .name == "nt" else os .path .join (venv_dir , "bin" , "python" )
97109 cmd = [venv_python , "-m" , "pip" , "install" , "termcolor" , "ujson" ]
98- out , return_code = util .run_cmd (cmd , env )
110+ _ , return_code = util .run_cmd (cmd , env , logger = log )
111+ assert return_code == 0 , log
99112
100113 target_file = os .path .join (target_dir , "hello" )
101114 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-ce" , "-Os" , "-m" , source_file , "--venv" , venv_dir , "-o" , target_file ]
102- out , return_code = util .run_cmd (cmd , env )
103- util .check_ouput ("Bundling Python resources into" , out )
104- util .check_ouput ("Finished generating 'hello' in" , out )
115+ out , return_code = util .run_cmd (cmd , env , logger = log )
116+ assert return_code == 0 , log
117+ util .check_ouput ("Bundling Python resources into" , out , logger = log )
118+ util .check_ouput ("Finished generating 'hello' in" , out , logger = log )
105119
106120 cmd = [target_file ]
107- out , return_code = util .run_cmd (cmd , env )
108- util .check_ouput ("hello standalone world" , out )
109- util .check_ouput ("key=value" , out )
121+ out , return_code = util .run_cmd (cmd , env , logger = log )
122+ assert return_code == 0 , log
123+ util .check_ouput ("hello standalone world" , out , logger = log )
124+ util .check_ouput ("key=value" , out , logger = log )
110125
111126@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
112127def test_native_executable_module ():
113128 graalpy = util .get_gp ()
114129 if graalpy is None :
115130 return
116- env = os .environ .copy ()
117- env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
118131
132+ env = create_test_env ()
119133 with tempfile .TemporaryDirectory () as tmp_dir :
120134
121135 module_dir = os .path .join (tmp_dir , "hello_app" )
@@ -131,12 +145,16 @@ def test_native_executable_module():
131145 f .write ("import hello\n " )
132146 f .write ("hello.print_hello()\n " )
133147
148+ log = util .Logger ()
149+
134150 target_file = os .path .join (tmp_dir , "hello" )
135151 cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-ce" , "-Os" , "-m" , module_dir , "-o" , target_file ]
136- out , return_code = util .run_cmd (cmd , env )
137- util .check_ouput ("Bundling Python resources into" , out )
138- util .check_ouput ("Finished generating 'hello' in" , out )
152+ out , return_code = util .run_cmd (cmd , env , logger = log )
153+ assert return_code == 0 , log
154+ util .check_ouput ("Bundling Python resources into" , out , logger = log )
155+ util .check_ouput ("Finished generating 'hello' in" , out , logger = log )
139156
140157 cmd = [target_file ]
141- out , return_code = util .run_cmd (cmd , env )
142- util .check_ouput ("hello standalone world" , out )
158+ out , return_code = util .run_cmd (cmd , env , logger = log )
159+ assert return_code == 0 , log
160+ util .check_ouput ("hello standalone world" , out , logger = log )
0 commit comments