diff options
author | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-02-09 15:32:03 +0000 |
---|---|---|
committer | Anderson Bravalheri <andersonbravalheri@gmail.com> | 2022-03-05 09:56:48 +0000 |
commit | 81c3faaca72550e36809d4bbd9ea3922e89225cf (patch) | |
tree | 2488bd523c87d32d031c12198da6e7216798e61b /setuptools/tests/config/test_expand.py | |
parent | 25612c5557a2d693214903bae0f8ff6bf405a7eb (diff) | |
download | python-setuptools-git-81c3faaca72550e36809d4bbd9ea3922e89225cf.tar.gz |
Replace pushd with monkeypatch.chdir in test_expand
Diffstat (limited to 'setuptools/tests/config/test_expand.py')
-rw-r--r-- | setuptools/tests/config/test_expand.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/setuptools/tests/config/test_expand.py b/setuptools/tests/config/test_expand.py index 9fc256f0..4ca23bdc 100644 --- a/setuptools/tests/config/test_expand.py +++ b/setuptools/tests/config/test_expand.py @@ -5,7 +5,6 @@ import pytest from distutils.errors import DistutilsOptionError from setuptools.command.sdist import sdist from setuptools.config import expand -from setuptools.sandbox import pushd def write_files(files, root_dir): @@ -15,7 +14,7 @@ def write_files(files, root_dir): path.write_text(content) -def test_glob_relative(tmp_path): +def test_glob_relative(tmp_path, monkeypatch): files = { "dir1/dir2/dir3/file1.txt", "dir1/dir2/file2.txt", @@ -28,24 +27,26 @@ def test_glob_relative(tmp_path): write_files({k: "" for k in files}, tmp_path) patterns = ["**/*.txt", "[ab].*", "**/[ac].ini"] - with pushd(tmp_path): - assert set(expand.glob_relative(patterns)) == files + monkeypatch.chdir(tmp_path) + assert set(expand.glob_relative(patterns)) == files # Make sure the same APIs work outside cwd assert set(expand.glob_relative(patterns, tmp_path)) == files -def test_read_files(tmp_path): +def test_read_files(tmp_path, monkeypatch): files = { "a.txt": "a", "dir1/b.txt": "b", "dir1/dir2/c.txt": "c" } write_files(files, tmp_path) - with pushd(tmp_path): + + with monkeypatch.context() as m: + m.chdir(tmp_path) assert expand.read_files(list(files)) == "a\nb\nc" - with pushd(tmp_path / "dir1"), pytest.raises(DistutilsOptionError): - expand.read_files(["../a.txt"]) + with pytest.raises(DistutilsOptionError): + expand.read_files(["../a.txt"]) # Make sure the same APIs work outside cwd assert expand.read_files(list(files), tmp_path) == "a\nb\nc" @@ -53,7 +54,7 @@ def test_read_files(tmp_path): expand.read_files(["../a.txt"], tmp_path) -def test_read_attr(tmp_path): +def test_read_attr(tmp_path, monkeypatch): files = { "pkg/__init__.py": "", "pkg/sub/__init__.py": "VERSION = '0.1.1'", @@ -63,10 +64,13 @@ def test_read_attr(tmp_path): ), } write_files(files, tmp_path) - # Make sure it can read the attr statically without evaluating the module - with pushd(tmp_path): + + with monkeypatch.context() as m: + m.chdir(tmp_path) + # Make sure it can read the attr statically without evaluating the module assert expand.read_attr('pkg.sub.VERSION') == '0.1.1' values = expand.read_attr('lib.mod.VALUES', {'lib': 'pkg/sub'}) + assert values['a'] == 0 assert values['b'] == {42} @@ -80,7 +84,7 @@ def test_resolve_class(): assert expand.resolve_class("setuptools.command.sdist.sdist") == sdist -def test_find_packages(tmp_path): +def test_find_packages(tmp_path, monkeypatch): files = { "pkg/__init__.py", "other/__init__.py", @@ -88,7 +92,9 @@ def test_find_packages(tmp_path): } write_files({k: "" for k in files}, tmp_path) - with pushd(tmp_path): + + with monkeypatch.context() as m: + m.chdir(tmp_path) assert set(expand.find_packages(where=['.'])) == {"pkg", "other"} expected = {"pkg", "other", "dir2"} assert set(expand.find_packages(where=['.', "dir1"])) == expected |