4646import unittest
4747import pathlib
4848import util
49+ import time
4950
5051is_enabled = 'ENABLE_JBANG_INTEGRATION_UNITTESTS' in os .environ and os .environ ['ENABLE_JBANG_INTEGRATION_UNITTESTS' ] == "true"
5152MAVEN_REPO_LOCAL_URL = os .environ .get ('org.graalvm.maven.downloader.repository' )
5253GRAAL_VERSION = os .environ .get ('org.graalvm.maven.downloader.version' )
53- CATALOG_ALIAS = "tested_catalog"
5454
5555# whole folder will be deleted after the tests finished
5656WORK_DIR = os .path .join (tempfile .gettempdir (),tempfile .mkdtemp ())
@@ -78,7 +78,6 @@ def setUpClass(self):
7878 self .ensureLocalMavenRepo ()
7979 self .clearCache ()
8080 self .catalog_file = self .getCatalogFile ()
81- self .registerCatalog (self .catalog_file )
8281
8382 def tearDownClass (self ):
8483 if not is_enabled :
@@ -161,16 +160,6 @@ def addLocalMavenRepo(self, file):
161160 else :
162161 self .fail (f"Not found any dependecies in: { file } " )
163162
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-
174163 def prepare_hello_example (self , work_dir ):
175164 hello_java_file = os .path .join (work_dir , "hello.java" )
176165 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):
180169 shutil .copyfile (template , target )
181170 self .addLocalMavenRepo (target )
182171
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+
183187 @unittest .skipUnless (is_enabled , "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true" )
184188 def test_catalog (self ):
185189 json_data = self .getCatalogData (self .catalog_file )
@@ -199,7 +203,7 @@ def test_graalpy_template(self):
199203 test_file = "graalpy_test.java"
200204 work_dir = self .tmpdir
201205
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 ]
203207 out , result = run_cmd (command , cwd = work_dir )
204208 self .assertTrue (result == 0 , f"Creating template { template_name } failed" )
205209
@@ -222,7 +226,7 @@ def test_graalpy_template_native(self):
222226 test_file = "graalpy_test.java"
223227 work_dir = self .tmpdir
224228
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 ]
226230 out , result = run_cmd (command , cwd = work_dir )
227231 self .assertTrue (result == 0 , f"Creating template { template_name } failed" )
228232
@@ -243,7 +247,7 @@ def test_graalpy_local_repo_template(self):
243247 test_file = "graalpy_test_local_repo.java"
244248 work_dir = self .tmpdir
245249
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 ]
247251 out , result = run_cmd (command , cwd = work_dir )
248252 self .assertTrue (result == 0 , f"Creating template { template_name } failed" )
249253
@@ -279,9 +283,9 @@ def test_hello_example(self):
279283
280284 @unittest .skipUnless (is_enabled , "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true" )
281285 def test_external_dir (self ):
282- work_dir = self .tmpdir
286+ work_dir = self .tmpdir
283287 hello_java_file = self .prepare_hello_example (work_dir )
284-
288+
285289 # patch hello.java file to use external dir for resources
286290 resources_dir = os .path .join (work_dir , "python-resources" )
287291 src_dir = os .path .join (resources_dir , "src" )
@@ -291,7 +295,7 @@ def test_external_dir(self):
291295from termcolor import colored
292296def hello():
293297 print(print(colored('hello java', 'red', attrs=['reverse', 'blink'])))
294- """ )
298+ """ )
295299 util .replace_in_file (hello_java_file ,
296300 "//PIP termcolor==2.2" ,
297301 f"//PIP termcolor==2.2\n //PYTHON_RESOURCES_DIRECTORY { resources_dir } " )
@@ -319,7 +323,7 @@ def hello():
319323 self .assertTrue (result == 0 , f"Execution failed with code { result } \n command: { command } \n stdout: { out } " )
320324 self .assertTrue ("Successfully installed ujson" in out , f"Expected text:\n Successfully installed ujson" )
321325 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 } " )
323327
324328 # remove ujson from PIP comment
325329 util .replace_in_file (hello_java_file ,
@@ -332,7 +336,7 @@ def hello():
332336 self .assertTrue (result == 0 , f"Execution failed with code { result } \n command: { command } \n stdout: { out } " )
333337 self .assertTrue ("Uninstalling ujson" in out , f"Expected text:\n Uninstalling ujson" )
334338 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 } " )
336340
337341 # add ujson in additional PIP comment
338342 util .replace_in_file (hello_java_file ,
@@ -345,7 +349,7 @@ def hello():
345349 self .assertTrue (result == 0 , f"Execution failed with code { result } \n command: { command } \n stdout: { out } " )
346350 self .assertTrue ("Successfully installed ujson" in out , f"Expected text:\n Successfully installed ujson" )
347351 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 } " )
349353
350354 if not 'win32' in sys .platform :
351355 command = [JBANG_CMD , "--verbose" , "--native" , hello_java_file , tested_code ]
0 commit comments