46
46
import unittest
47
47
import pathlib
48
48
import util
49
+ import time
49
50
50
51
is_enabled = 'ENABLE_JBANG_INTEGRATION_UNITTESTS' in os .environ and os .environ ['ENABLE_JBANG_INTEGRATION_UNITTESTS' ] == "true"
51
52
MAVEN_REPO_LOCAL_URL = os .environ .get ('org.graalvm.maven.downloader.repository' )
52
53
GRAAL_VERSION = os .environ .get ('org.graalvm.maven.downloader.version' )
53
- CATALOG_ALIAS = "tested_catalog"
54
54
55
55
# whole folder will be deleted after the tests finished
56
56
WORK_DIR = os .path .join (tempfile .gettempdir (),tempfile .mkdtemp ())
@@ -78,7 +78,6 @@ def setUpClass(self):
78
78
self .ensureLocalMavenRepo ()
79
79
self .clearCache ()
80
80
self .catalog_file = self .getCatalogFile ()
81
- self .registerCatalog (self .catalog_file )
82
81
83
82
def tearDownClass (self ):
84
83
if not is_enabled :
@@ -161,16 +160,6 @@ def addLocalMavenRepo(self, file):
161
160
else :
162
161
self .fail (f"Not found any dependecies in: { file } " )
163
162
164
- def registerCatalog (self , catalog_file ):
165
- # we need to be sure that the current dir is not dir, where is the catalog defined
166
- command = [JBANG_CMD , "catalog" , "remove" , "--verbose" , CATALOG_ALIAS ]
167
- out , result = run_cmd (command , cwd = WORK_DIR )
168
-
169
- command = [JBANG_CMD , "catalog" , "add" , "--verbose" , "--name" , CATALOG_ALIAS , catalog_file ]
170
- out , result = run_cmd (command , cwd = WORK_DIR )
171
- if result != 0 :
172
- self .fail (f"Problem during registering catalog: { out } " )
173
-
174
163
def prepare_hello_example (self , work_dir ):
175
164
hello_java_file = os .path .join (work_dir , "hello.java" )
176
165
self .prepare_template (os .path .join (os .path .dirname (os .path .abspath (__file__ )), "../../../../graalpy-jbang/examples/hello.java" ), hello_java_file )
@@ -180,6 +169,21 @@ def prepare_template(self, template, target):
180
169
shutil .copyfile (template , target )
181
170
self .addLocalMavenRepo (target )
182
171
172
+ @unittest .skipUnless (is_enabled , "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true" )
173
+ def test_register_catalog (self ):
174
+ alias = "graalpy_test_catalog_" + str (int (time .time ()))
175
+
176
+ # jbang checks catalog file sanity when adding
177
+ command = [JBANG_CMD , "catalog" , "add" , "--verbose" , "--name" , alias , self .catalog_file ]
178
+ out , result = run_cmd (command , cwd = WORK_DIR )
179
+ if result != 0 :
180
+ self .fail (f"Problem during registering catalog" )
181
+
182
+ command = [JBANG_CMD , "catalog" , "remove" , "--verbose" , alias ]
183
+ out , result = run_cmd (command , cwd = WORK_DIR )
184
+ if result != 0 :
185
+ self .fail (f"Problem during removing catalog" )
186
+
183
187
@unittest .skipUnless (is_enabled , "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true" )
184
188
def test_catalog (self ):
185
189
json_data = self .getCatalogData (self .catalog_file )
@@ -199,7 +203,7 @@ def test_graalpy_template(self):
199
203
test_file = "graalpy_test.java"
200
204
work_dir = self .tmpdir
201
205
202
- command = [JBANG_CMD , "--verbose" , "init" , f"--template={ template_name } @{ CATALOG_ALIAS } " , test_file ]
206
+ command = [JBANG_CMD , "--verbose" , "init" , f"--template={ template_name } @{ self . catalog_file } " , test_file ]
203
207
out , result = run_cmd (command , cwd = work_dir )
204
208
self .assertTrue (result == 0 , f"Creating template { template_name } failed" )
205
209
@@ -222,7 +226,7 @@ def test_graalpy_template_native(self):
222
226
test_file = "graalpy_test.java"
223
227
work_dir = self .tmpdir
224
228
225
- command = [JBANG_CMD , "--verbose" , "init" , f"--template={ template_name } @{ CATALOG_ALIAS } " , test_file ]
229
+ command = [JBANG_CMD , "--verbose" , "init" , f"--template={ template_name } @{ self . catalog_file } " , test_file ]
226
230
out , result = run_cmd (command , cwd = work_dir )
227
231
self .assertTrue (result == 0 , f"Creating template { template_name } failed" )
228
232
@@ -243,7 +247,7 @@ def test_graalpy_local_repo_template(self):
243
247
test_file = "graalpy_test_local_repo.java"
244
248
work_dir = self .tmpdir
245
249
246
- command = [JBANG_CMD , "--verbose" , "init" , f"--template={ template_name } @{ CATALOG_ALIAS } " , f"-Dpath_to_local_repo={ MAVEN_REPO_LOCAL_URL } " , test_file ]
250
+ command = [JBANG_CMD , "--verbose" , "init" , f"--template={ template_name } @{ self . catalog_file } " , f"-Dpath_to_local_repo={ MAVEN_REPO_LOCAL_URL } " , test_file ]
247
251
out , result = run_cmd (command , cwd = work_dir )
248
252
self .assertTrue (result == 0 , f"Creating template { template_name } failed" )
249
253
@@ -279,9 +283,9 @@ def test_hello_example(self):
279
283
280
284
@unittest .skipUnless (is_enabled , "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true" )
281
285
def test_external_dir (self ):
282
- work_dir = self .tmpdir
286
+ work_dir = self .tmpdir
283
287
hello_java_file = self .prepare_hello_example (work_dir )
284
-
288
+
285
289
# patch hello.java file to use external dir for resources
286
290
resources_dir = os .path .join (work_dir , "python-resources" )
287
291
src_dir = os .path .join (resources_dir , "src" )
@@ -291,7 +295,7 @@ def test_external_dir(self):
291
295
from termcolor import colored
292
296
def hello():
293
297
print(print(colored('hello java', 'red', attrs=['reverse', 'blink'])))
294
- """ )
298
+ """ )
295
299
util .replace_in_file (hello_java_file ,
296
300
"//PIP termcolor==2.2" ,
297
301
f"//PIP termcolor==2.2\n //PYTHON_RESOURCES_DIRECTORY { resources_dir } " )
@@ -319,7 +323,7 @@ def hello():
319
323
self .assertTrue (result == 0 , f"Execution failed with code { result } \n command: { command } \n stdout: { out } " )
320
324
self .assertTrue ("Successfully installed ujson" in out , f"Expected text:\n Successfully installed ujson" )
321
325
self .assertFalse ("Successfully installed termcolor" in out , f"Did not expect text:\n Successfully installed termcolor" )
322
- self .assertTrue ("hello java" in out , f"Expected text:\n hello java\n but in stdout was:\n { out } " )
326
+ self .assertTrue ("hello java" in out , f"Expected text:\n hello java\n but in stdout was:\n { out } " )
323
327
324
328
# remove ujson from PIP comment
325
329
util .replace_in_file (hello_java_file ,
@@ -332,7 +336,7 @@ def hello():
332
336
self .assertTrue (result == 0 , f"Execution failed with code { result } \n command: { command } \n stdout: { out } " )
333
337
self .assertTrue ("Uninstalling ujson" in out , f"Expected text:\n Uninstalling ujson" )
334
338
self .assertFalse ("Successfully installed termcolor" in out , f"Did not expect text:\n Successfully installed termcolor" )
335
- self .assertTrue ("hello java" in out , f"Expected text:\n hello java\n but in stdout was:\n { out } " )
339
+ self .assertTrue ("hello java" in out , f"Expected text:\n hello java\n but in stdout was:\n { out } " )
336
340
337
341
# add ujson in additional PIP comment
338
342
util .replace_in_file (hello_java_file ,
@@ -345,7 +349,7 @@ def hello():
345
349
self .assertTrue (result == 0 , f"Execution failed with code { result } \n command: { command } \n stdout: { out } " )
346
350
self .assertTrue ("Successfully installed ujson" in out , f"Expected text:\n Successfully installed ujson" )
347
351
self .assertFalse ("Successfully installed termcolor" in out , f"Did not expect text:\n Successfully installed termcolor" )
348
- self .assertTrue ("hello java" in out , f"Expected text:\n hello java\n but in stdout was:\n { out } " )
352
+ self .assertTrue ("hello java" in out , f"Expected text:\n hello java\n but in stdout was:\n { out } " )
349
353
350
354
if not 'win32' in sys .platform :
351
355
command = [JBANG_CMD , "--verbose" , "--native" , hello_java_file , tested_code ]
0 commit comments