Repository navigation
Conversation
|
With this PR success-rate of unit tests on MS Windows is up to 87% (from 80%), with 243 tests passing (almost as many as on Linux). There are a couple of tests left (e.g. Anyway, I am happy about all sorts of feedback on this PR. |
| python3 $GISBASE/gui/wxpython/core/toolboxes.py doctest | ||
| python3 $GISBASE/gui/wxpython/core/toolboxes.py test |
There was a problem hiding this comment.
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.
| import __builtin__ | ||
| if sys.version_info[0] == 2: | ||
| import __builtin__ | ||
|
|
||
| __builtin__._ = new_translator | ||
| __builtin__._ = new_translator |
There was a problem hiding this comment.
The "underscore" issue should still apply, so I would be surprised if doing it just for 2 is enough. Besides that, if there is 2-only code somewhere, it should be deleted. (But I think that's not the case here.)
There was a problem hiding this comment.
Right. We do not support Python 2 anymore, so it is probably even better to remove Python 2 specific code to cleanup (also other places where Python 2 code pops up)?
|
|
||
| # 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.
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.
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.
subprocess.run is just an interface to Popen like all the others. I don't expect it would help. shutil.which needs grass to be on path to work which is likely not fulfilled.
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 grass.script.setup.executable later is the way to go.
There was a problem hiding this comment.
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.
| # Make sure that universal newlines are returned | ||
| output = ( | ||
| output.replace(os.linesep, "\n") | ||
| if os.linesep != "\n" and type(output) == str |
| @@ -1,4 +1,4 @@ | |||
| from tempfile import NamedTemporaryFile | |||
| import grass.script as gscript | |||
| def create_filter(self, options): | ||
| """Create a temporary filter file with the given name and options.""" | ||
| f = NamedTemporaryFile() | ||
| f = gscript.tempfile(create=False) |
There was a problem hiding this comment.
Returns string, the original is an IO object.
| # Prebuild C-modules for MS Windows are unlikely to run | ||
| # on fresh compiled GRASS GIS |
There was a problem hiding this comment.
I thought this should fail at g.extension step already.
There was a problem hiding this comment.
Addons are pre-build for MS Windows also for the development version:
https://wingrass.fsv.cvut.cz/grass83/addons/grass-8.3.dev/logs/
However, getting the addon-help fails because build versions differ...
There was a problem hiding this comment.
Oh, I missed what test_github_install_official is. That makes sense. Mention the different build versions in the comment.
| expected="10 | ||
| 10" | ||
| out=$(v.category option=print layer=2 input=vedit_test) | ||
| out=$(v.category option=print layer=2 input=vedit_test| tr -d '\r') |
There was a problem hiding this comment.
BTW, skipping all .sh-based tests on Windows would be a fair solution I think.
There was a problem hiding this comment.
I have no strong opinion here. MSYS has been dropped, so it is very unlikely that users will run shell scripts in real world cases. And I am not sure this is a real MS Windows test in that sense.
However, most of the shell tests work. So maybe it does not hurt to have them running for MS Windows as well...
There was a problem hiding this comment.
Okay, please add comment that the \r part is for Windows, so we know when to remove it.
However, I think the role of Bash/sh/... tests is to provide option for "quick and dirty" tests and for very specific cases, so supporting only Linux or unix is fine. Something to keep in mind.
| stdout, stderr = subprocess.Popen(args, stdout=subprocess.PIPE).communicate() | ||
| stdout, stderr = subprocess.Popen( | ||
| args, stdout=subprocess.PIPE, shell=sys.platform == "win32" | ||
| ).communicate() |
There was a problem hiding this comment.
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?
| expected="10 | ||
| 10" | ||
| out=$(v.category option=print layer=2 input=vedit_test) | ||
| out=$(v.category option=print layer=2 input=vedit_test| tr -d '\r') |
There was a problem hiding this comment.
Okay, please add comment that the \r part is for Windows, so we know when to remove it.
However, I think the role of Bash/sh/... tests is to provide option for "quick and dirty" tests and for very specific cases, so supporting only Linux or unix is fine. Something to keep in mind.
|
Do you still think this PR is the way forward? It has conflicts, but for instance the builtins import issue has need fixed in another PR in January, and there was a PR recently that changed a temporary file/NamedTemporaryFile, and it was the only usage in the code at the time. |
|
I've skimmed through very quickly, and I think cutting out some line endings in the tests only for Windows is maybe not the right approach. It is something that we should probably fix for real instead, and to not care too much about io with Python, as it is handled way more transparently than on Python 2 |
|
Is there still something useful and relevant here that should be kept, 3 years later? Our testing situation is a bit better now, our Python code quality is way up since more than a year and a half, grass start up and initialization, especially for usage as a Python library is recently better, etc. |
|
AI analysis of this PR, what is possibly still relevant:
These would be better as individual PRs. |
We can keep the PR open for reference or open an issue, close this PR and point to the PR in the issue... Both is fine with me. I agree it should be implemented in separate, smaller PRs... |
On Windows, a file opened via tempfile.NamedTemporaryFile() cannot be reopened by another process while the Python handle is still open, so r.mfilter failed to read the filter file created this way. Write the filter contents to a path from grass.script.tempfile() instead, which does not hold the file open, and drop the @xfail_windows markers this fix should resolve. Extracted and reworked as a standalone change from PR OSGeo#2616 (by Stefan Blumentrath / @ninsbl), which combined this fix with many other Windows-specific testsuite changes and has been open, unrebased, since 2022. Re-derived against current main rather than cherry-picked, because @ninsbl's branch predates unrelated fixes already merged to this same test file (a docstring/variance correction and other @xfail_windows additions), which a direct cherry-pick would have clobbered. This has not been verified on an actual Windows run; CI on this PR should confirm whether the @xfail_windows markers can indeed be removed. Analysis of PR OSGeo#2616 assisted by AI (Claude), including identifying this as an easily isolated, self-contained candidate for its own PR; verify before merging. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HjAoKyq8bFN7cnNaZkwtV6
On Windows, a file opened via tempfile.NamedTemporaryFile() cannot be reopened by another process while the Python handle is still open, so r.mfilter failed to read the filter file created this way. Write the filter contents to a path from grass.script.tempfile() instead, which does not hold the file open, and drop the @xfail_windows markers this fix should resolve. Extracted and reworked as a standalone change from PR OSGeo#2616 (by Stefan Blumentrath / @ninsbl), which combined this fix with many other Windows-specific testsuite changes and has been open, unrebased, since 2022. Re-derived against current main rather than cherry-picked, because @ninsbl's branch predates unrelated fixes already merged to this same test file (a docstring/variance correction and other @xfail_windows additions), which a direct cherry-pick would have clobbered. This has not been verified on an actual Windows run; CI on this PR should confirm whether the @xfail_windows markers can indeed be removed. Analysis of PR OSGeo#2616 assisted by AI (Claude), including identifying this as an easily isolated, self-contained candidate for its own PR; verify before merging. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Python's default text-mode writing translates "\n" to os.linesep, which on Windows turns the MD5 test fixtures into "\r\n" files. Two tests hash them in binary mode against MD5 sums computed from "\n" content: test_text_file_binary in test_checkers.py and test_assertFileMd5 in test_assertions.py. Write these fixtures with newline="" so the bytes match the hardcoded sums on every platform. Do the same for the other fixtures written next to file_with_md5, since test_assertFilesEqualMd5 compares their hashes against it. Remove the now obsolete @xfail_windows markers from the two tests, because an unexpected success makes the gunittest run fail. Also fix the "platfrom" typos in the test_text_file_platform test name and the platform_newline attribute. Based on the newline handling in OSGeo#2616 by Stefan Blumentrath, reworked against current main with AI assistance. Co-authored-by: Stefan Blumentrath <4246620+ninsbl@users.noreply.github.com>
Python's default text-mode writing translates "\n" to os.linesep, which on Windows turns the MD5 test fixtures into "\r\n" files. Two tests hash them in binary mode against MD5 sums computed from "\n" content: test_text_file_binary in test_checkers.py and test_assertFileMd5 in test_assertions.py. Write these fixtures with newline="" so the bytes match the hardcoded sums on every platform. Do the same for the other fixtures written next to file_with_md5, since test_assertFilesEqualMd5 compares their hashes against it. Remove the now obsolete @xfail_windows markers from the two tests, because an unexpected success makes the gunittest run fail. Also fix the "platfrom" typos in the test_text_file_platform test name and the platform_newline attribute. Based on the newline handling in #2616 by Stefan Blumentrath, reworked against current main with AI assistance. Co-authored-by: Stefan Blumentrath <4246620+ninsbl@users.noreply.github.com>
…dows pathlib uses os.sep in the string form of paths, so the tests that compare against forward-slash strings failed on Windows. Compare against the same strings with os.sep and drop the xfail_windows markers from the four tests which this fixes. Extracted from OSGeo#2616 by Stefan Blumentrath.
…dows pathlib uses os.sep in the string form of paths, so the tests that compare against forward-slash strings failed on Windows. Compare against the same strings with os.sep and drop the xfail_windows markers from the four tests which this fixes. Extracted from OSGeo#2616 by Stefan Blumentrath.
…dows pathlib uses os.sep in the string form of paths, so the tests that compare against forward-slash strings failed on Windows. Compare against the same strings with os.sep and drop the xfail_windows markers from the four tests which this fixes. Extracted from OSGeo#2616 by Stefan Blumentrath.
…dows (#8050) pathlib uses os.sep in the string form of paths, so the tests that compare against forward-slash strings failed on Windows. Compare against the same strings with os.sep and drop the xfail_windows markers from the four tests which this fixes. Extracted from #2616 by Stefan Blumentrath. Co-authored-by: Stefan Blumentrath <stefan.blumentrath@gmx.de>
Replaces: #1683
July 2026 AI analysis of what is possibly still relevant:
r.mfilter: the NamedTemporaryFile → gs.tempfile fix is a textbook Windows bug (can't reopen an open NamedTemporaryFile) and directly explains the 6 xfail'd tests there.r.mfilter: Avoid reopening NamedTemporaryFile on Windows in testsuite #7878grassdb/test_manage.py: the os.sep-aware assertions map one-to-one onto the 4 xfail'd tests.grass.grassdb: Fix path separator expectations in manage tests on Windows #8050test_checkers.py / test_assertions.py: the newline="" fixes for MD5-checked files still apply, though test_assertions.py now writes via Path.write_text(), so the fix needs rewriting.grass.gunittest: Preserve exact bytes in MD5 test fixtures #8039These would be better as individual PRs.