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.
2
2
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3
3
#
4
4
# The Universal Permissive License (UPL), Version 1.0
44
44
from tests .standalone import util
45
45
46
46
is_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
47
54
48
55
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
49
56
def test_native_executable_one_file ():
50
57
graalpy = util .get_gp ()
51
58
if graalpy is None :
52
59
return
53
- env = os .environ .copy ()
54
- env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
55
60
61
+ env = create_test_env ()
56
62
with tempfile .TemporaryDirectory () as tmpdir :
57
63
58
64
source_file = os .path .join (tmpdir , "hello.py" )
59
65
with open (source_file , 'w' ) as f :
60
66
f .write ("import sys\n " )
61
67
f .write ("print('hello world, argv[1:]:', sys.argv[1:])" )
62
68
69
+ log = util .Logger ()
70
+
63
71
target_file = os .path .join (tmpdir , "hello" )
64
72
cmd = [graalpy , "-m" , "standalone" , "--verbose" , "native" , "-ce" , "-m" , source_file , "-o" , target_file ]
65
73
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 )
69
78
70
79
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 )
73
83
74
84
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
75
85
def test_native_executable_venv_and_one_file ():
76
86
graalpy = util .get_gp ()
77
87
if graalpy is None :
78
88
return
79
- env = os .environ .copy ()
80
- env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
81
89
90
+ env = create_test_env ()
82
91
with tempfile .TemporaryDirectory () as target_dir :
83
92
source_file = os .path .join (target_dir , "hello.py" )
84
93
with open (source_file , 'w' ) as f :
@@ -89,33 +98,38 @@ def test_native_executable_venv_and_one_file():
89
98
f .write ('d = ujson.loads("""{"key": "value"}""")\n ' )
90
99
f .write ("print('key=' + d['key'])\n " )
91
100
101
+ log = util .Logger ()
102
+
92
103
venv_dir = os .path .join (target_dir , "venv" )
93
104
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
95
107
96
108
venv_python = os .path .join (venv_dir , "Scripts" , "python.exe" ) if os .name == "nt" else os .path .join (venv_dir , "bin" , "python" )
97
109
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
99
112
100
113
target_file = os .path .join (target_dir , "hello" )
101
114
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 )
105
119
106
120
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 )
110
125
111
126
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
112
127
def test_native_executable_module ():
113
128
graalpy = util .get_gp ()
114
129
if graalpy is None :
115
130
return
116
- env = os .environ .copy ()
117
- env ["MVN_GRAALPY_VERSION" ] = util .get_graalvm_version ()
118
131
132
+ env = create_test_env ()
119
133
with tempfile .TemporaryDirectory () as tmp_dir :
120
134
121
135
module_dir = os .path .join (tmp_dir , "hello_app" )
@@ -131,12 +145,16 @@ def test_native_executable_module():
131
145
f .write ("import hello\n " )
132
146
f .write ("hello.print_hello()\n " )
133
147
148
+ log = util .Logger ()
149
+
134
150
target_file = os .path .join (tmp_dir , "hello" )
135
151
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 )
139
156
140
157
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