-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CI: Address Windows specific issues in testsuite #2616
base: main
Are you sure you want to change the base?
Changes from all commits
939e42a
0a2f004
9ecbb2d
edea1f9
e2092cb
c08635c
fb075bf
45bb9d7
6de276a
50ddaad
590cfd4
a7198dc
8951dc3
dd1d610
31a2a3c
1cdc0fd
4998aec
128d3ea
39fc866
7eb95cb
74511ae
f89774f
1f96842
01abed3
0a0d009
646d238
6b72a10
086cc65
b219310
9e7706f
5a3fd3e
0114994
5d4864e
80fd808
db1473c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,12 @@ | |
@author Soeren Gebbert | ||
""" | ||
|
||
import json | ||
import subprocess | ||
import sys | ||
|
||
from grass.gunittest.case import TestCase | ||
from grass.script import decode | ||
import json | ||
|
||
|
||
class TestParserJson(TestCase): | ||
|
@@ -50,7 +52,9 @@ def test_r_slope_aspect_json(self): | |
}, | ||
] | ||
|
||
stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate() | ||
stdout, stderr = subprocess.Popen( | ||
args, stdout=subprocess.PIPE, shell=sys.platform == "win32" | ||
).communicate() | ||
Comment on lines
-53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would probably make more sense with direct support for this in grass.script, but to limit the solution only to here, would shutil.which work here at line 22? |
||
print(stdout) | ||
json_code = json.loads(decode(stdout)) | ||
self.assertEqual(json_code["module"], "r.slope.aspect") | ||
|
@@ -83,7 +87,9 @@ def test_v_out_ascii(self): | |
} | ||
] | ||
|
||
stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate() | ||
stdout, stderr = subprocess.Popen( | ||
args, stdout=subprocess.PIPE, shell=sys.platform == "win32" | ||
).communicate() | ||
print(stdout) | ||
json_code = json.loads(decode(stdout)) | ||
self.assertEqual(json_code["module"], "v.out.ascii") | ||
|
@@ -99,7 +105,9 @@ def test_v_info(self): | |
{"param": "layer", "value": "1"}, | ||
] | ||
|
||
stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate() | ||
stdout, stderr = subprocess.Popen( | ||
args, stdout=subprocess.PIPE, shell=sys.platform == "win32" | ||
).communicate() | ||
print(stdout) | ||
json_code = json.loads(decode(stdout)) | ||
self.assertEqual(json_code["module"], "v.info") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
import os | ||
import shutil | ||
import subprocess | ||
|
||
import sys | ||
|
||
# Note that unlike rest of GRASS GIS, here we are using unittest package | ||
# directly. The grass.gunittest machinery for mapsets is not needed here. | ||
|
@@ -30,13 +30,16 @@ class TestTmpMapset(unittest.TestCase): | |
"""Tests --tmp-mapset option of grass command""" | ||
|
||
# TODO: here we need a name of or path to the main GRASS GIS executable | ||
executable = "grass" | ||
executable = shutil.which("grass") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would think only shutil.which or shell=True are needed for Windows, not both. I would prefer shutil.which or some equivalent of sys.executable in the grass package (e.g., grass.script.setup.executable). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Unfortunately, both shutil.which and shell do not seem to help. Maybe better to switch to subprocess.run? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. subprocess.run is just an interface to Popen like all the others. I don't expect it would help. shutil.which needs This test is now unique - we don't have other tests which test the executable - we we may have more in the future or even write such code, so perhaps ignoring it now and adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is one the of things for a separate PR. Getting the grass.script.setup.executable piece working would be nice to have. get_install_path is perhaps a good starting point (Python package path is known, path to installation is not). Lazy-loading seems appropriate, but there are still no properties for modules yet (?), but there is getattr. |
||
# an arbitrary, but identifiable and fairly unique name | ||
location = "test_tmp_mapset_xy" | ||
|
||
def setUp(self): | ||
"""Creates a location used in the tests""" | ||
subprocess.check_call([self.executable, "-c", "XY", self.location, "-e"]) | ||
subprocess.check_call( | ||
[self.executable, "-c", "XY", self.location, "-e"], | ||
shell=sys.platform == "win32", | ||
) | ||
self.subdirs = os.listdir(self.location) | ||
|
||
def tearDown(self): | ||
|
@@ -46,7 +49,8 @@ def tearDown(self): | |
def test_command_runs(self): | ||
"""Check that correct parameters are accepted""" | ||
return_code = subprocess.call( | ||
[self.executable, "--tmp-mapset", self.location, "--exec", "g.proj", "-g"] | ||
[self.executable, "--tmp-mapset", self.location, "--exec", "g.proj", "-g"], | ||
shell=sys.platform == "win32", | ||
) | ||
self.assertEqual( | ||
return_code, | ||
|
@@ -67,7 +71,8 @@ def test_command_fails_without_location(self): | |
"--exec", | ||
"g.proj", | ||
"-g", | ||
] | ||
], | ||
shell=sys.platform == "win32", | ||
) | ||
self.assertNotEqual( | ||
return_code, | ||
|
@@ -81,7 +86,8 @@ def test_command_fails_without_location(self): | |
def test_mapset_metadata_correct(self): | ||
"""Check that metadata is readable and have expected value (XY CRS)""" | ||
output = subprocess.check_output( | ||
[self.executable, "--tmp-mapset", self.location, "--exec", "g.proj", "-g"] | ||
[self.executable, "--tmp-mapset", self.location, "--exec", "g.proj", "-g"], | ||
shell=sys.platform == "win32", | ||
) | ||
self.assertEqual( | ||
output.strip(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have GRASS_PYTHON defined here or not? If yes, that might be the best choice, although I would prefer solution where plain python just works.