From 10fc32e3ef17ad5bdb1989383c38efddc84cf614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 20 Aug 2023 17:00:59 +0300 Subject: [PATCH] Simplify virtualenv testing (#10035) Co-authored-by: Stefan Holderbach Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com> --- .github/workflows/ci.yml | 13 ++------- scripts/test_virtualenv.nu | 56 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 scripts/test_virtualenv.nu diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d29a66c67b..94adb20990 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,21 +115,12 @@ jobs: with: python-version: "3.10" - - run: python -m pip install tox - - name: Install virtualenv - run: git clone https://github.com/pypa/virtualenv.git + run: pip install virtualenv shell: bash - name: Test Nushell in virtualenv - run: | - cd virtualenv - # if we encounter problems with bleeding edge tests pin to the latest tag - # git checkout $(git describe --tags | cut -d - -f 1) - # We need to disable failing on coverage levels. - nu -c "open pyproject.toml | upsert tool.coverage.report.fail_under 1 | save patchproject.toml" - mv patchproject.toml pyproject.toml - tox -e ${{ matrix.py }} -- -k nushell + run: nu scripts/test_virtualenv.nu shell: bash plugins: diff --git a/scripts/test_virtualenv.nu b/scripts/test_virtualenv.nu new file mode 100644 index 0000000000..e6628ea537 --- /dev/null +++ b/scripts/test_virtualenv.nu @@ -0,0 +1,56 @@ +if $nu.os-info.family == 'windows' { + # fix encoding on Windows https://stackoverflow.com/a/63573649 + load-env { + PYTHONIOENCODING: utf-8 + PYTHONLEGACYWINDOWSSTDIO: utf-8 + } +} + +let env_name = 'e-$ Γ¨Ρ€Ρ‚πŸš’β™žδΈ­η‰‡-j' + +let paths = if $nu.os-info.family == 'windows' { + ['Scripts', 'python.exe'] +} else { + ['bin', 'python'] +} + +let subdir = $paths.0 +let exe = $paths.1 + +let test_lines = [ + "python -c 'import sys; print(sys.executable)'" # 1 + "python -c 'import os; import sys; v = os.environ.get("VIRTUAL_ENV"); print(v)'" # 2 + $"overlay use '([$env.PWD $env_name $subdir activate.nu] | path join)'" + "python -c 'import sys; print(sys.executable)'" # 3 + "python -c 'import os; import sys; v = os.environ.get("VIRTUAL_ENV"); print(v)'" # 4 + "print $env.VIRTUAL_ENV_PROMPT" # 5 + "deactivate" + "python -c 'import sys; print(sys.executable)'" # 6 + "python -c 'import os; import sys; v = os.environ.get("VIRTUAL_ENV"); print(v)'" # 7 +] + +def main [] { + let orig_python_interpreter = (python -c 'import sys; print(sys.executable)') + + let expected = [ + $orig_python_interpreter # 1 + "None" # 2 + ([$env.PWD $env_name $subdir $exe] | path join) # 3 + ([$env.PWD $env_name] | path join) # 4 + $env_name # 5 + $orig_python_interpreter # 6 + "None" # 7 + ] + + virtualenv $env_name + + $test_lines | save script.nu + let out = (nu script.nu | lines) + + let o = ($out | str trim | str join (char nl)) + let e = ($expected | str trim | str join (char nl)) + if $o != $e { + let msg = $"OUTPUT:\n($o)\n\nEXPECTED:\n($e)" + error make {msg: $"Output does not match the expected value:\n($msg)"} + } +}