From 5e33cf39c3f3664fe0fff748751807154cd8cf3a 2024-09-23 04:06:08 From: jsbautista <42411448+jsbautista@users.noreply.github.com> Date: 2024-09-23 04:06:08 Subject: [PATCH] Merge branch 'main' into UltraTBPR --- diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f18fb39..5513b16 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,9 +10,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.x - name: Install Graphviz @@ -34,6 +34,6 @@ jobs: run: | coverage combine `find . -name .coverage\*` && coverage xml - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v4 with: name: Docs diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index 00f19d3..3340c01 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -25,9 +25,9 @@ jobs: python-version: "3.10" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Update Python installer @@ -53,19 +53,21 @@ jobs: pytest - name: Install sagemath-repl run: | - cd .. - git clone --depth 1 https://github.com/sagemath/sage - cd sage - # We cloned it for the tests, but for simplicity we install the - # wheels from PyPI. - # (Avoid 10.3b6 because of https://github.com/sagemath/sage/pull/37178) - pip install --pre sagemath-repl sagemath-environment - # Install optionals that make more tests pass - pip install pillow - pip install --pre sagemath-categories - cd .. + # Sept 2024, sage has been failing for a while, + # Skipping. + # cd .. + # git clone --depth 1 https://github.com/sagemath/sage + # cd sage + # # We cloned it for the tests, but for simplicity we install the + # # wheels from PyPI. + # # (Avoid 10.3b6 because of https://github.com/sagemath/sage/pull/37178) + # pip install --pre sagemath-repl sagemath-environment + # # Install optionals that make more tests pass + # pip install pillow + # pip install --pre sagemath-categories + # cd .. - name: Test sagemath-repl run: | - cd ../sage/ - # From https://github.com/sagemath/sage/blob/develop/pkgs/sagemath-repl/tox.ini - sage-runtests -p --environment=sage.all__sagemath_repl --baseline-stats-path=pkgs/sagemath-repl/known-test-failures.json --initial --optional=sage src/sage/repl src/sage/doctest src/sage/misc/sage_input.py src/sage/misc/sage_eval.py + # cd ../sage/ + # # From https://github.com/sagemath/sage/blob/develop/pkgs/sagemath-repl/tox.ini + # sage-runtests -p --environment=sage.all__sagemath_repl --baseline-stats-path=pkgs/sagemath-repl/known-test-failures.json --initial --optional=sage src/sage/repl src/sage/doctest src/sage/misc/sage_input.py src/sage/misc/sage_eval.py diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index c65682e..d2bffdb 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -18,9 +18,9 @@ jobs: python-version: ["3.x"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/.github/workflows/nightly-wheel-build.yml b/.github/workflows/nightly-wheel-build.yml index 64a41e3..6f0eadd 100644 --- a/.github/workflows/nightly-wheel-build.yml +++ b/.github/workflows/nightly-wheel-build.yml @@ -13,9 +13,9 @@ jobs: if: github.event_name != 'pull_request' && (github.event_name != 'schedule' || github.repository_owner == 'ipython') steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" cache: pip diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e65f2e5..786d00b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -18,11 +18,11 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: 3.x - name: Install dependencies diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1935286..eb8b2b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,9 +56,9 @@ jobs: want-latest-entry-point-code: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: pip @@ -109,7 +109,7 @@ jobs: ./report-*.json - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: name: Test files: /home/runner/work/ipython/ipython/coverage.xml diff --git a/IPython/utils/tests/test_path.py b/IPython/utils/tests/test_path.py index 5ea27e0..92794b6 100644 --- a/IPython/utils/tests/test_path.py +++ b/IPython/utils/tests/test_path.py @@ -75,20 +75,29 @@ def teardown_module(): shutil.rmtree(TMP_TEST_DIR) -def setup_environment(): - """Setup testenvironment for some functions that are tested - in this module. In particular this functions stores attributes - and other things that we need to stub in some test functions. - This needs to be done on a function level and not module level because - each testfunction needs a pristine environment. - """ +# Build decorator that uses the setup_environment/setup_environment +@pytest.fixture +def environment(): global oldstuff, platformstuff - oldstuff = (env.copy(), os.name, sys.platform, path.get_home_dir, IPython.__file__, os.getcwd()) + oldstuff = ( + env.copy(), + os.name, + sys.platform, + path.get_home_dir, + IPython.__file__, + os.getcwd(), + ) -def teardown_environment(): - """Restore things that were remembered by the setup_environment function - """ - (oldenv, os.name, sys.platform, path.get_home_dir, IPython.__file__, old_wd) = oldstuff + yield + + ( + oldenv, + os.name, + sys.platform, + path.get_home_dir, + IPython.__file__, + old_wd, + ) = oldstuff os.chdir(old_wd) reload(path) @@ -96,16 +105,7 @@ def teardown_environment(): if key not in oldenv: del env[key] env.update(oldenv) - if hasattr(sys, 'frozen'): - del sys.frozen - - -# Build decorator that uses the setup_environment/setup_environment -@pytest.fixture -def environment(): - setup_environment() - yield - teardown_environment() + assert not hasattr(sys, "frozen") with_environment = pytest.mark.usefixtures("environment") @@ -113,11 +113,11 @@ with_environment = pytest.mark.usefixtures("environment") @skip_if_not_win32 @with_environment -def test_get_home_dir_1(): +def test_get_home_dir_1(monkeypatch): """Testcase for py2exe logic, un-compressed lib """ unfrozen = path.get_home_dir() - sys.frozen = True + monkeypatch.setattr(sys, "frozen", True, raising=False) #fake filename for IPython.__init__ IPython.__file__ = abspath(join(HOME_TEST_DIR, "Lib/IPython/__init__.py")) @@ -128,13 +128,15 @@ def test_get_home_dir_1(): @skip_if_not_win32 @with_environment -def test_get_home_dir_2(): +def test_get_home_dir_2(monkeypatch): """Testcase for py2exe logic, compressed lib """ unfrozen = path.get_home_dir() - sys.frozen = True - #fake filename for IPython.__init__ - IPython.__file__ = abspath(join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py")).lower() + monkeypatch.setattr(sys, "frozen", True, raising=False) + # fake filename for IPython.__init__ + IPython.__file__ = abspath( + join(HOME_TEST_DIR, "Library.zip/IPython/__init__.py") + ).lower() home_dir = path.get_home_dir(True) assert home_dir == unfrozen @@ -160,22 +162,22 @@ def test_get_home_dir_4(): @skip_win32 @with_environment -def test_get_home_dir_5(): +def test_get_home_dir_5(monkeypatch): """raise HomeDirError if $HOME is specified, but not a writable dir""" env['HOME'] = abspath(HOME_TEST_DIR+'garbage') # set os.name = posix, to prevent My Documents fallback on Windows - os.name = 'posix' + monkeypatch.setattr(os, "name", "posix") pytest.raises(path.HomeDirError, path.get_home_dir, True) # Should we stub wreg fully so we can run the test on all platforms? @skip_if_not_win32 @with_environment -def test_get_home_dir_8(): +def test_get_home_dir_8(monkeypatch): """Using registry hack for 'My Documents', os=='nt' HOMESHARE, HOMEDRIVE, HOMEPATH, USERPROFILE and others are missing. """ - os.name = 'nt' + monkeypatch.setattr(os, "name", "nt") # Remove from stub environment all keys that may be set for key in ['HOME', 'HOMESHARE', 'HOMEDRIVE', 'HOMEPATH', 'USERPROFILE']: env.pop(key, None) @@ -194,13 +196,12 @@ def test_get_home_dir_8(): assert home_dir == abspath(HOME_TEST_DIR) @with_environment -def test_get_xdg_dir_0(): +def test_get_xdg_dir_0(monkeypatch): """test_get_xdg_dir_0, check xdg_dir""" - reload(path) - path._writable_dir = lambda path: True - path.get_home_dir = lambda : 'somewhere' - os.name = "posix" - sys.platform = "linux2" + monkeypatch.setattr(path, "_writable_dir", lambda path: True) + monkeypatch.setattr(path, "get_home_dir", lambda: "somewhere") + monkeypatch.setattr(os, "name", "posix") + monkeypatch.setattr(sys, "platform", "linux2") env.pop('IPYTHON_DIR', None) env.pop('IPYTHONDIR', None) env.pop('XDG_CONFIG_HOME', None) @@ -209,44 +210,41 @@ def test_get_xdg_dir_0(): @with_environment -def test_get_xdg_dir_1(): +def test_get_xdg_dir_1(monkeypatch): """test_get_xdg_dir_1, check nonexistent xdg_dir""" - reload(path) - path.get_home_dir = lambda : HOME_TEST_DIR - os.name = "posix" - sys.platform = "linux2" - env.pop('IPYTHON_DIR', None) - env.pop('IPYTHONDIR', None) - env.pop('XDG_CONFIG_HOME', None) + monkeypatch.setattr(path, "get_home_dir", lambda: HOME_TEST_DIR) + monkeypatch.setattr(os, "name", "posix") + monkeypatch.setattr(sys, "platform", "linux2") + env.pop("IPYTHON_DIR", None) + env.pop("IPYTHONDIR", None) + env.pop("XDG_CONFIG_HOME", None) assert path.get_xdg_dir() is None @with_environment -def test_get_xdg_dir_2(): +def test_get_xdg_dir_2(monkeypatch): """test_get_xdg_dir_2, check xdg_dir default to ~/.config""" - reload(path) - path.get_home_dir = lambda : HOME_TEST_DIR - os.name = "posix" - sys.platform = "linux2" - env.pop('IPYTHON_DIR', None) - env.pop('IPYTHONDIR', None) - env.pop('XDG_CONFIG_HOME', None) - cfgdir=os.path.join(path.get_home_dir(), '.config') + monkeypatch.setattr(path, "get_home_dir", lambda: HOME_TEST_DIR) + monkeypatch.setattr(os, "name", "posix") + monkeypatch.setattr(sys, "platform", "linux2") + env.pop("IPYTHON_DIR", None) + env.pop("IPYTHONDIR", None) + env.pop("XDG_CONFIG_HOME", None) + cfgdir = os.path.join(path.get_home_dir(), ".config") if not os.path.exists(cfgdir): os.makedirs(cfgdir) assert path.get_xdg_dir() == cfgdir @with_environment -def test_get_xdg_dir_3(): +def test_get_xdg_dir_3(monkeypatch): """test_get_xdg_dir_3, check xdg_dir not used on non-posix systems""" - reload(path) - path.get_home_dir = lambda : HOME_TEST_DIR - os.name = "nt" - sys.platform = "win32" - env.pop('IPYTHON_DIR', None) - env.pop('IPYTHONDIR', None) - env.pop('XDG_CONFIG_HOME', None) - cfgdir=os.path.join(path.get_home_dir(), '.config') + monkeypatch.setattr(path, "get_home_dir", lambda: HOME_TEST_DIR) + monkeypatch.setattr(os, "name", "nt") + monkeypatch.setattr(sys, "platform", "win32") + env.pop("IPYTHON_DIR", None) + env.pop("IPYTHONDIR", None) + env.pop("XDG_CONFIG_HOME", None) + cfgdir = os.path.join(path.get_home_dir(), ".config") os.makedirs(cfgdir, exist_ok=True) assert path.get_xdg_dir() is None @@ -281,31 +279,30 @@ def test_get_long_path_name(): assert p == "/usr/local" -class TestRaiseDeprecation(unittest.TestCase): +@dec.skip_win32 # can't create not-user-writable dir on win +@with_environment +def test_not_writable_ipdir(): + tmpdir = tempfile.mkdtemp() + os.name = "posix" + env.pop("IPYTHON_DIR", None) + env.pop("IPYTHONDIR", None) + env.pop("XDG_CONFIG_HOME", None) + env["HOME"] = tmpdir + ipdir = os.path.join(tmpdir, ".ipython") + os.mkdir(ipdir, 0o555) + try: + open(os.path.join(ipdir, "_foo_"), "w", encoding="utf-8").close() + except IOError: + pass + else: + # I can still write to an unwritable dir, + # assume I'm root and skip the test + pytest.skip("I can't create directories that I can't write to") + + with pytest.warns(UserWarning, match="is not a writable location"): + ipdir = paths.get_ipython_dir() + env.pop("IPYTHON_DIR", None) - @dec.skip_win32 # can't create not-user-writable dir on win - @with_environment - def test_not_writable_ipdir(self): - tmpdir = tempfile.mkdtemp() - os.name = "posix" - env.pop('IPYTHON_DIR', None) - env.pop('IPYTHONDIR', None) - env.pop('XDG_CONFIG_HOME', None) - env['HOME'] = tmpdir - ipdir = os.path.join(tmpdir, '.ipython') - os.mkdir(ipdir, 0o555) - try: - open(os.path.join(ipdir, "_foo_"), "w", encoding="utf-8").close() - except IOError: - pass - else: - # I can still write to an unwritable dir, - # assume I'm root and skip the test - pytest.skip("I can't create directories that I can't write to") - - with self.assertWarnsRegex(UserWarning, 'is not a writable location'): - ipdir = paths.get_ipython_dir() - env.pop('IPYTHON_DIR', None) @with_environment def test_get_py_filename():