46
46
import shutil
47
47
48
48
is_enabled = 'ENABLE_STANDALONE_UNITTESTS' in os .environ and os .environ ['ENABLE_STANDALONE_UNITTESTS' ] == "true"
49
- skip_purge = 'SKIP_STANDALONE_UNITTESTS_PURGE' in os .environ and os .environ ['SKIP_STANDALONE_UNITTESTS_PURGE' ] == "true"
50
49
51
50
MVN_CMD = [shutil .which ('mvn' ), "--batch-mode" ]
52
51
@@ -252,53 +251,39 @@ def create_test_pom(self, template, pom):
252
251
line = line .replace ("{graalpy-maven-plugin-version}" , self .graalvmVersion )
253
252
f .write (line )
254
253
255
- def purge_local_repo (self , target_dir , resolve = True ):
256
- if not skip_purge :
257
- self .env ["MVN" ] = " " .join (MVN_CMD + [f"-Dgraalpy.version={ self .graalvmVersion } " , "-Dgraalpy.edition=python-community" ])
258
- if resolve :
259
- cmd = MVN_CMD + ["dependency:purge-local-repository" , f"-Dinclude=org.graalvm.python:graalpy-maven-plugin" , f"-Dgraalpy.version={ self .graalvmVersion } " , "-Dgraalpy.edition=python-community" ]
260
- else :
261
- cmd = MVN_CMD + ["dependency:purge-local-repository" , "-DreResolve=false" , f"-Dinclude=org.graalvm.python:graalpy-maven-plugin" , f"-Dgraalpy.version={ self .graalvmVersion } " , "-Dgraalpy.edition=python-community" ]
262
- run_cmd (cmd , self .env , cwd = target_dir )
263
-
264
254
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
265
255
def test_generated_app (self ):
266
256
with tempfile .TemporaryDirectory () as tmpdir :
267
257
target_name = "generated_app_test"
268
258
target_dir = os .path .join (str (tmpdir ), target_name )
269
259
self .generate_app (tmpdir , target_dir , target_name )
270
- self .purge_local_repo (target_dir )
271
-
272
- try :
273
- # build
274
- cmd = MVN_CMD + ["package" , "-Pnative" , "-DmainClass=it.pkg.GraalPy" ] #, f"-Dgraalpy.version={self.graalvmVersion}", "-Dgraalpy.edition=python-community"]
275
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
276
- assert "BUILD SUCCESS" in out
277
-
278
- # check fileslist.txt
279
- fl_path = os .path .join (target_dir , "target" , "classes" , "vfs" , "fileslist.txt" )
280
- with open (fl_path ) as f :
281
- lines = f .readlines ()
282
- assert "/vfs/\n " in lines
283
- assert "/vfs/home/\n " in lines
284
- assert "/vfs/home/lib-graalpython/\n " in lines
285
- assert "/vfs/home/lib-python/\n " in lines
286
-
287
- # execute and check native image
288
- cmd = [os .path .join (target_dir , "target" , target_name )]
289
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
290
- assert "hello java" in out
291
-
292
- # execute with java and check
293
- cmd = MVN_CMD + ["exec:java" , "-Dexec.mainClass=it.pkg.GraalPy" ]
294
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
295
- assert "hello java" in out
296
-
297
- #GR-51132 - NoClassDefFoundError when running polyglot app in java mode
298
- assert "java.lang.NoClassDefFoundError" not in out
299
-
300
- finally :
301
- self .purge_local_repo (target_dir , False )
260
+
261
+ # build
262
+ cmd = MVN_CMD + ["package" , "-Pnative" , "-DmainClass=it.pkg.GraalPy" ] #, f"-Dgraalpy.version={self.graalvmVersion}", "-Dgraalpy.edition=python-community"]
263
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
264
+ assert "BUILD SUCCESS" in out
265
+
266
+ # check fileslist.txt
267
+ fl_path = os .path .join (target_dir , "target" , "classes" , "vfs" , "fileslist.txt" )
268
+ with open (fl_path ) as f :
269
+ lines = f .readlines ()
270
+ assert "/vfs/\n " in lines
271
+ assert "/vfs/home/\n " in lines
272
+ assert "/vfs/home/lib-graalpython/\n " in lines
273
+ assert "/vfs/home/lib-python/\n " in lines
274
+
275
+ # execute and check native image
276
+ cmd = [os .path .join (target_dir , "target" , target_name )]
277
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
278
+ assert "hello java" in out
279
+
280
+ # execute with java and check
281
+ cmd = MVN_CMD + ["exec:java" , "-Dexec.mainClass=it.pkg.GraalPy" ]
282
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
283
+ assert "hello java" in out
284
+
285
+ #GR-51132 - NoClassDefFoundError when running polyglot app in java mode
286
+ assert "java.lang.NoClassDefFoundError" not in out
302
287
303
288
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
304
289
def test_fail_without_graalpy_dep (self ):
@@ -307,19 +292,10 @@ def test_fail_without_graalpy_dep(self):
307
292
target_dir = os .path .join (str (tmpdir ), target_name )
308
293
pom_template = os .path .join (os .path .dirname (__file__ ), "fail_without_graalpy_dep_pom.xml" )
309
294
self .generate_app (tmpdir , target_dir , target_name , pom_template )
310
- self .purge_local_repo (target_dir )
311
295
312
- if not skip_purge :
313
- self .env ["MVN" ] = " " .join (MVN_CMD + [f"-Dgraalpy.version={ self .graalvmVersion } " , "-Dgraalpy.edition=python-community" ])
314
- cmd = MVN_CMD + ["dependency:purge-local-repository" , f"-Dgraalpy.version={ self .graalvmVersion } " , "-Dgraalpy.edition=python-community" ]
315
- run_cmd (cmd , self .env , cwd = target_dir )
316
- try :
317
- cmd = MVN_CMD + ["process-resources" ]
318
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
319
- assert "Missing GraalPy dependency. Please add to your pom either org.graalvm.polyglot:python-community or org.graalvm.polyglot:python" in out
320
-
321
- finally :
322
- self .purge_local_repo (target_dir , False )
296
+ cmd = MVN_CMD + ["process-resources" ]
297
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
298
+ assert "Missing GraalPy dependency. Please add to your pom either org.graalvm.polyglot:python-community or org.graalvm.polyglot:python" in out
323
299
324
300
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
325
301
def test_gen_launcher_and_venv (self ):
@@ -328,40 +304,35 @@ def test_gen_launcher_and_venv(self):
328
304
target_dir = os .path .join (str (tmpdir ), target_name )
329
305
pom_template = os .path .join (os .path .dirname (__file__ ), "prepare_venv_pom.xml" )
330
306
self .generate_app (tmpdir , target_dir , target_name , pom_template )
331
- self .purge_local_repo (target_dir )
332
-
333
- try :
334
- cmd = MVN_CMD + ["process-resources" ]
335
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
336
- assert "-m venv" in out
337
- assert "-m ensurepip" in out
338
- assert "ujson" in out
339
- assert "termcolor" in out
340
-
341
- # run again and assert that we do not regenerate the venv
342
- cmd = MVN_CMD + ["process-resources" ]
343
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
344
- assert "-m venv" not in out
345
- assert "-m ensurepip" not in out
346
- assert "ujson" not in out
347
- assert "termcolor" not in out
348
-
349
- # remove ujson pkg from plugin config and check if unistalled
350
- with open (os .path .join (target_dir , "pom.xml" ), "r" ) as f :
351
- contents = f .read ()
352
-
353
- with open (os .path .join (target_dir , "pom.xml" ), "w" ) as f :
354
- f .write (contents .replace ("<package>ujson</package>" , "" ))
355
-
356
- cmd = MVN_CMD + ["process-resources" ]
357
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
358
- assert "-m venv" not in out
359
- assert "-m ensurepip" not in out
360
- assert "Uninstalling ujson" in out
361
- assert "termcolor" not in out
362
-
363
- finally :
364
- self .purge_local_repo (target_dir , False )
307
+
308
+ cmd = MVN_CMD + ["process-resources" ]
309
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
310
+ assert "-m venv" in out
311
+ assert "-m ensurepip" in out
312
+ assert "ujson" in out
313
+ assert "termcolor" in out
314
+
315
+ # run again and assert that we do not regenerate the venv
316
+ cmd = MVN_CMD + ["process-resources" ]
317
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
318
+ assert "-m venv" not in out
319
+ assert "-m ensurepip" not in out
320
+ assert "ujson" not in out
321
+ assert "termcolor" not in out
322
+
323
+ # remove ujson pkg from plugin config and check if unistalled
324
+ with open (os .path .join (target_dir , "pom.xml" ), "r" ) as f :
325
+ contents = f .read ()
326
+
327
+ with open (os .path .join (target_dir , "pom.xml" ), "w" ) as f :
328
+ f .write (contents .replace ("<package>ujson</package>" , "" ))
329
+
330
+ cmd = MVN_CMD + ["process-resources" ]
331
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
332
+ assert "-m venv" not in out
333
+ assert "-m ensurepip" not in out
334
+ assert "Uninstalling ujson" in out
335
+ assert "termcolor" not in out
365
336
366
337
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
367
338
def test_check_home (self ):
@@ -370,25 +341,21 @@ def test_check_home(self):
370
341
target_dir = os .path .join (str (tmpdir ), target_name )
371
342
pom_template = os .path .join (os .path .dirname (__file__ ), "check_home_pom.xml" )
372
343
self .generate_app (tmpdir , target_dir , target_name , pom_template )
373
- self .purge_local_repo (target_dir )
374
-
375
- try :
376
- cmd = MVN_CMD + ["process-resources" ]
377
- out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
378
-
379
- # check fileslist.txt
380
- fl_path = os .path .join (target_dir , "target" , "classes" , "vfs" , "fileslist.txt" )
381
- with open (fl_path ) as f :
382
- for line in f :
383
- line = f .readline ()
384
- # string \n
385
- line = line [:len (line )- 1 ]
386
- if line .endswith ("/" ) or line == "/vfs/home/tagfile" or line == "/vfs/proj/hello.py" :
387
- continue
388
- assert line .endswith ("/__init__.py" )
389
- assert not line .endswith ("html/__init__.py" )
390
- finally :
391
- self .purge_local_repo (target_dir , False )
344
+
345
+ cmd = MVN_CMD + ["process-resources" ]
346
+ out , return_code = run_cmd (cmd , self .env , cwd = target_dir )
347
+
348
+ # check fileslist.txt
349
+ fl_path = os .path .join (target_dir , "target" , "classes" , "vfs" , "fileslist.txt" )
350
+ with open (fl_path ) as f :
351
+ for line in f :
352
+ line = f .readline ()
353
+ # string \n
354
+ line = line [:len (line )- 1 ]
355
+ if line .endswith ("/" ) or line == "/vfs/home/tagfile" or line == "/vfs/proj/hello.py" :
356
+ continue
357
+ assert line .endswith ("/__init__.py" )
358
+ assert not line .endswith ("html/__init__.py" )
392
359
393
360
@unittest .skipUnless (is_enabled , "ENABLE_STANDALONE_UNITTESTS is not true" )
394
361
def test_native_executable_one_file ():
0 commit comments