Merge pull request #4066 from dannysepler/pathlib-in-test
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add pathlib in cli tests
authored by David Lord · committed by GitHub · parents 1c30523, 1b5f21e · Browse files · 1 file·+16 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+16 added−27 removed
- tests:+16 added−27 removed
Provenance
- Commit
19b905e- Tree
2ec0312- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
1c30523- Parent 2
1b5f21e
1 file changed+16 added−27 removed
modified:tests/test_cli.py+16 added-27 removed
3 unmodified lines4 import ssl5 import sys6 import types7 from functools import partial8+from pathlib import Path9 from unittest.mock import patch10 11 import click12 import pytest16 unmodified lines29 from flask.cli import run_command30 from flask.cli import ScriptInfo31 from flask.cli import with_appcontext32 32-cwd = os.getcwd()33-test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps"))33+cwd = Path.cwd()34+test_path = (Path(__file__) / ".." / "test_apps").resolve()35 36 37 @pytest.fixture38 def runner():113 unmodified lines152 "value,path,result",153 (154 ("test", cwd, "test"),155 ("test.py", cwd, "test"),155- ("a/test", os.path.join(cwd, "a"), "test"),156+ ("a/test", cwd / "a", "test"),157 ("test/__init__.py", cwd, "test"),158 ("test/__init__", cwd, "test"),159 # nested package160 (160- os.path.join(test_path, "cliapp", "inner1", "__init__"),161+ test_path / "cliapp" / "inner1" / "__init__",162 test_path,163 "cliapp.inner1",164 ),165 (165- os.path.join(test_path, "cliapp", "inner1", "inner2"),166+ test_path / "cliapp" / "inner1" / "inner2",167 test_path,168 "cliapp.inner1.inner2",169 ),170 # dotted name171 ("test.a.b", cwd, "test.a.b"),171- (os.path.join(test_path, "cliapp.app"), test_path, "cliapp.app"),172+ (test_path / "cliapp.app", test_path, "cliapp.app"),173 # not a Python file, will be caught during import173- (174- os.path.join(test_path, "cliapp", "message.txt"),175- test_path,176- "cliapp.message.txt",177- ),174+ (test_path / "cliapp" / "message.txt", test_path, "cliapp.message.txt"),175 ),176 )177 def test_prepare_import(request, value, path, result):178 """Expect the correct path to be set and the correct import and app names10 unmodified lines189 190 request.addfinalizer(reset_path)191 192 assert prepare_import(value) == result196- assert sys.path[0] == path193+ assert sys.path[0] == str(path)194 195 196 @pytest.mark.parametrize(197 "iname,aname,result",76 unmodified lines274 assert app.name == "testapp"275 assert obj.load_app() is app276 277 # import app with module's absolute path281- cli_app_path = os.path.abspath(282- os.path.join(os.path.dirname(__file__), "test_apps", "cliapp", "app.py")283- )278+ cli_app_path = str(test_path / "cliapp" / "app.py")279+280 obj = ScriptInfo(app_import_path=cli_app_path)281 app = obj.load_app()282 assert app.name == "testapp"283 assert obj.load_app() is app13 unmodified lines297 obj = ScriptInfo()298 pytest.raises(NoAppException, obj.load_app)299 300 # import app from wsgi.py in current directory305- monkeypatch.chdir(306- os.path.abspath(307- os.path.join(os.path.dirname(__file__), "test_apps", "helloworld")308- )309- )301+ monkeypatch.chdir(test_path / "helloworld")302 obj = ScriptInfo()303 app = obj.load_app()304 assert app.name == "hello"305 306 # import app from app.py in current directory315- monkeypatch.chdir(316- os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps", "cliapp"))317- )307+ monkeypatch.chdir(test_path / "cliapp")308 obj = ScriptInfo()309 app = obj.load_app()310 assert app.name == "testapp"311 190 unmodified lines502 503 monkeypatch.setenv("EGGS", "3")504 monkeypatch.chdir(test_path)505 assert load_dotenv()516- assert os.getcwd() == test_path506+ assert Path.cwd() == test_path507 # .flaskenv doesn't overwrite .env508 assert os.environ["FOO"] == "env"509 # set only in .flaskenv510 assert os.environ["BAR"] == "bar"11 unmodified lines522 def test_dotenv_path(monkeypatch):523 for item in ("FOO", "BAR", "EGGS"):524 monkeypatch._setitem.append((os.environ, item, notset))525 536- cwd = os.getcwd()537- load_dotenv(os.path.join(test_path, ".flaskenv"))538- assert os.getcwd() == cwd526+ load_dotenv(test_path / ".flaskenv")527+ assert Path.cwd() == cwd528 assert "FOO" in os.environ529 530 531 def test_dotenv_optional(monkeypatch):130 unmodified lines