Skip to content

Commit d4d9a38

Browse files
authored
fix: flaky test on windows (#1936)
1 parent 4bae5a1 commit d4d9a38

File tree

6 files changed

+114
-15
lines changed

6 files changed

+114
-15
lines changed

.github/workflows/rust.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@ jobs:
4444
if: ${{ contains(github.event.pull_request.labels.*.name, 'need-patch-apply-tests') && matrix.os == 'windows-latest' }}
4545
run: Add-Content $env:GITHUB_PATH "C:\Program Files\Git\usr\bin"
4646
- uses: prefix-dev/[email protected]
47-
if: ${{ contains(github.event.pull_request.labels.*.name, 'need-patch-apply-tests') && matrix.os == 'macos-latest' }}
47+
if: ${{ matrix.os == 'macos-latest' }}
4848
with:
4949
cache: true
5050
- name: Set up GNU patch on MacOS
5151
# Needed to use GNU patch instead of whatever is builtin on macos (1 test fails)
5252
if: ${{ contains(github.event.pull_request.labels.*.name, 'need-patch-apply-tests') && matrix.os == 'macos-latest' }}
5353
run: pixi global install patch=2.7.6
54+
- name: Set up patchelf on MacOS
55+
if: ${{ matrix.os == 'macos-latest' }}
56+
run: pixi global install patchelf
5457
- name: Run tests
55-
run: cargo test --features=tui,recipe-generation --verbose -- --nocapture
58+
run: cargo test --all --features=tui,recipe-generation --verbose -- --nocapture
5659
- name: Run patch apply tests
5760
# https://github.com/orgs/community/discussions/26261#discussioncomment-3251039
5861
if: ${{ contains(github.event.pull_request.labels.*.name, 'need-patch-apply-tests') }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
source: crates/rattler_build_recipe_generator/src/pypi.rs
3+
expression: recipe
4+
---
5+
context:
6+
version: 3.1.0
7+
package:
8+
name: flask
9+
version: "${{ version }}"
10+
source:
11+
- url: "https://pypi.org/packages/source/f/flask/flask-${{ version }}.tar.gz"
12+
sha256: 5f873c5184c897c8d9d1b05df1e3d01b14910ce69607a117bd3277098a5836ac
13+
build:
14+
script: "${{ PYTHON }} -m pip install ."
15+
python:
16+
entry_points:
17+
- "flask = flask.cli:main"
18+
noarch: python
19+
requirements:
20+
host:
21+
- python >=3.9
22+
- flit_core<4
23+
- pip
24+
run:
25+
- python >=3.9
26+
- werkzeug >=3.1
27+
- jinja2 >=3.1.2
28+
- itsdangerous >=2.2
29+
- click >=8.1.3
30+
- blinker >=1.9
31+
- "importlib-metadata >=3.6 ;MARKER; python_version < \"3.10\""
32+
- "asgiref >=3.2 ;MARKER; extra == \"async\""
33+
- "python-dotenv ;MARKER; extra == \"dotenv\""
34+
tests:
35+
- python:
36+
imports:
37+
- Flask
38+
pip_check: true
39+
about:
40+
summary: A simple framework for building complex web applications.
41+
description: "# Flask\n\nFlask is a lightweight [WSGI][] web application framework. It is designed\nto make getting started quick and easy, with the ability to scale up to\ncomplex applications. It began as a simple wrapper around [Werkzeug][]\nand [Jinja][], and has become one of the most popular Python web\napplication frameworks.\n\nFlask offers suggestions, but doesn't enforce any dependencies or\nproject layout. It is up to the developer to choose the tools and\nlibraries they want to use. There are many extensions provided by the\ncommunity that make adding new functionality easy.\n\n[WSGI]: https://wsgi.readthedocs.io/\n[Werkzeug]: https://werkzeug.palletsprojects.com/\n[Jinja]: https://jinja.palletsprojects.com/\n\n\n## A Simple Example\n\n```python\n# save this as app.py\nfrom flask import Flask\n\napp = Flask(__name__)\n\[email protected](\"/\")\ndef hello():\n return \"Hello, World!\"\n```\n\n```\n$ flask run\n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n```\n\n\n## Donate\n\nThe Pallets organization develops and supports Flask and the libraries\nit uses. In order to grow the community of contributors and users, and\nallow the maintainers to devote more time to the projects, [please\ndonate today][].\n\n[please donate today]: https://palletsprojects.com/donate\n\n"
42+
documentation: "https://flask.palletsprojects.com/"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
source: crates/rattler_build_recipe_generator/src/pypi.rs
3+
expression: recipe
4+
---
5+
context:
6+
version: 1.24.0
7+
package:
8+
name: numpy
9+
version: "${{ version }}"
10+
source:
11+
- url: "https://pypi.org/packages/source/n/numpy/numpy-${{ version }}.tar.gz"
12+
sha256: c4ab7c9711fe6b235e86487ca74c1b092a6dd59a3cb45b63241ea0a148501853
13+
build:
14+
script: "${{ PYTHON }} -m pip install ."
15+
python:
16+
entry_points:
17+
- "f2py = numpy.f2py.f2py2e:main"
18+
- "f2py3 = numpy.f2py.f2py2e:main"
19+
- "f2py3.10 = numpy.f2py.f2py2e:main"
20+
requirements:
21+
host:
22+
- python >=3.8
23+
- setuptools==59.2.0
24+
- wheel==0.37.0
25+
- "Cython>=0.29.30,<3.0"
26+
- pip
27+
run:
28+
- python >=3.8
29+
tests:
30+
- python:
31+
imports:
32+
- numpy
33+
pip_check: true
34+
about:
35+
homepage: "https://www.numpy.org"
36+
summary: Fundamental package for array computing in Python
37+
description: "<h1 align=\"center\">\n<img src=\"/branding/logo/primary/numpylogo.svg\" width=\"300\">\n</h1><br>\n\n\n[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](\nhttps://numfocus.org)\n[![PyPI Downloads](https://img.shields.io/pypi/dm/numpy.svg?label=PyPI%20downloads)](\nhttps://pypi.org/project/numpy/)\n[![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/numpy.svg?label=Conda%20downloads)](\nhttps://anaconda.org/conda-forge/numpy)\n[![Stack Overflow](https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg)](\nhttps://stackoverflow.com/questions/tagged/numpy)\n[![Nature Paper](https://img.shields.io/badge/DOI-10.1038%2Fs41592--019--0686--2-blue)](\nhttps://doi.org/10.1038/s41586-020-2649-2)\n[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/numpy/numpy/badge)](https://api.securityscorecards.dev/projects/github.com/numpy/numpy)\n\n\nNumPy is the fundamental package for scientific computing with Python.\n\n- **Website:** https://www.numpy.org\n- **Documentation:** https://numpy.org/doc\n- **Mailing list:** https://mail.python.org/mailman/listinfo/numpy-discussion\n- **Source code:** https://github.com/numpy/numpy\n- **Contributing:** https://www.numpy.org/devdocs/dev/index.html\n- **Bug reports:** https://github.com/numpy/numpy/issues\n- **Report a security vulnerability:** https://tidelift.com/docs/security\n\nIt provides:\n\n- a powerful N-dimensional array object\n- sophisticated (broadcasting) functions\n- tools for integrating C/C++ and Fortran code\n- useful linear algebra, Fourier transform, and random number capabilities\n\nTesting:\n\nNumPy requires `pytest` and `hypothesis`. Tests can then be run after installation with:\n\n python -c 'import numpy; numpy.test()'\n\nCode of Conduct\n----------------------\n\nNumPy is a community-driven open source project developed by a diverse group of\n[contributors](https://numpy.org/teams/). The NumPy leadership has made a strong\ncommitment to creating an open, inclusive, and positive community. Please read the\n[NumPy Code of Conduct](https://numpy.org/code-of-conduct/) for guidance on how to interact\nwith others in a way that makes our community thrive.\n\nCall for Contributions\n----------------------\n\nThe NumPy project welcomes your expertise and enthusiasm!\n\nSmall improvements or fixes are always appreciated. If you are considering larger contributions\nto the source code, please contact us through the [mailing\nlist](https://mail.python.org/mailman/listinfo/numpy-discussion) first.\n\nWriting code isn’t the only way to contribute to NumPy. You can also:\n- review pull requests\n- help us stay on top of new and old issues\n- develop tutorials, presentations, and other educational materials\n- maintain and improve [our website](https://github.com/numpy/numpy.org)\n- develop graphic design for our brand assets and promotional materials\n- translate website content\n- help with outreach and onboard new contributors\n- write grant proposals and help with other fundraising efforts\n\nFor more information about the ways you can contribute to NumPy, visit [our website](https://numpy.org/contribute/). \nIf you’re unsure where to start or how your skills fit in, reach out! You can\nask on the mailing list or here, on GitHub, by opening a new issue or leaving a\ncomment on a relevant issue that is already open.\n\nOur preferred channels of communication are all public, but if you’d like to\nspeak to us in private first, contact our community coordinators at\[email protected] or on Slack (write [email protected] for\nan invitation).\n\nWe also have a biweekly community call, details of which are announced on the\nmailing list. You are very welcome to join.\n\nIf you are new to contributing to open source, [this\nguide](https://opensource.guide/how-to-contribute/) helps explain why, what,\nand how to successfully get involved.\n\n\n"
38+
license: BSD-3-Clause
39+
repository: "https://github.com/numpy/numpy"
40+
documentation: "https://numpy.org/doc/1.24"

test-data/recipes/binary_prefix_test/recipe.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ build:
3333
- |
3434
setlocal enabledelayedexpansion
3535
set "PREFIX_ESC=%PREFIX:\=\\%"
36-
echo #include ^<stdio.h^> > test_binary.c
37-
echo int main() { >> test_binary.c
38-
echo const char* prefix = "!PREFIX_ESC!"; >> test_binary.c
39-
echo printf("Prefix is: %%s\\n", prefix); >> test_binary.c
40-
echo return 0; >> test_binary.c
41-
echo } >> test_binary.c
36+
(
37+
echo #include ^<stdio.h^>
38+
echo int main() {
39+
echo const char* prefix = "!PREFIX_ESC!";
40+
echo printf("Prefix is: %%s\\n", prefix^);
41+
echo return 0;
42+
echo }
43+
) > test_binary.c
4244
gcc test_binary.c -o "%PREFIX%\Library\bin\test_binary.exe"
45+
if %errorlevel% neq 0 exit /b %errorlevel%
4346
4447
requirements:
4548
build:

test/end-to-end/helpers.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ def __call__(self, *args: Any, **kwds: Any) -> Any:
2828
return result
2929
else:
3030
try:
31-
output = check_output([str(self.path), *args], **kwds)
32-
if "text" not in kwds:
33-
return output.decode("utf-8")
31+
# Explicitly handle encoding for UTF-8 output on all platforms
32+
kwds_copy = dict(kwds)
33+
# Check if we need to add encoding
34+
needs_encoding = "text" not in kwds_copy and "encoding" not in kwds_copy
35+
if needs_encoding:
36+
kwds_copy["encoding"] = "utf-8"
37+
kwds_copy["errors"] = "replace"
38+
39+
output = check_output([str(self.path), *args], **kwds_copy)
40+
41+
# If we added encoding, output is already a string
42+
# If text was in kwds, output is also a string
43+
# Otherwise, it's bytes and needs decoding (but we added encoding, so this won't happen)
3444
return output
3545
except CalledProcessError as e:
3646
if kwds.get("stderr") is None:

test/end-to-end/test_simple.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ def test_missing_pin_subpackage(
14641464
tmp_path,
14651465
stderr=STDOUT,
14661466
)
1467-
stdout = e.value.output.decode("utf-8")
1467+
stdout = e.value.output
14681468
assert "Missing output: test1 (used in pin_subpackage)" in stdout
14691469

14701470

@@ -1476,7 +1476,7 @@ def test_cycle_detection(rattler_build: RattlerBuild, recipes: Path, tmp_path: P
14761476
tmp_path,
14771477
stderr=STDOUT,
14781478
)
1479-
stdout = e.value.output.decode("utf-8")
1479+
stdout = e.value.output
14801480
assert "Found a cycle in the recipe outputs: bazbus" in stdout
14811481

14821482

@@ -1694,7 +1694,7 @@ def test_python_version_spec(
16941694
args = rattler_build.build_args(recipes / "python-version-spec", tmp_path)
16951695
rattler_build(*args, stderr=STDOUT)
16961696

1697-
error_output = exc_info.value.output.decode("utf-8")
1697+
error_output = exc_info.value.output
16981698
assert (
16991699
"failed to parse match spec: unable to parse version spec: =.*" in error_output
17001700
)
@@ -2048,6 +2048,7 @@ def test_merge_build_and_host(
20482048
)
20492049

20502050

2051+
@pytest.mark.skipif(os.name == "nt", reason="Not applicable on Windows")
20512052
def test_error_on_binary_prefix(
20522053
rattler_build: RattlerBuild, recipes: Path, tmp_path: Path
20532054
):
@@ -2071,7 +2072,7 @@ def test_error_on_binary_prefix(
20712072
rattler_build(*args, stderr=STDOUT)
20722073
pytest.fail("Expected build to fail with binary prefix error")
20732074
except CalledProcessError as e:
2074-
output = e.output.decode("utf-8") if e.output else ""
2075+
output = e.output
20752076
assert "Binary file" in output and "contains host prefix" in output
20762077

20772078

0 commit comments

Comments
 (0)