diff --git a/tests/test_cli.py b/tests/test_cli.py index 1bc2fdd55..45a4a0019 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -3,7 +3,7 @@ import json import os import re - +from pathlib import Path import pytest from click.testing import CliRunner @@ -72,7 +72,7 @@ def test_cli(cli_runner): result = cli_runner('tests/fake-repo-pre/', '--no-input') assert result.exit_code == 0 assert os.path.isdir('fake-project') - with open(os.path.join('fake-project', 'README.rst')) as f: + with Path("fake-project", "README.rst").open() as f: assert 'Project name: **Fake Project**' in f.read() @@ -82,7 +82,7 @@ def test_cli_verbose(cli_runner): result = cli_runner('tests/fake-repo-pre/', '--no-input', '-v') assert result.exit_code == 0 assert os.path.isdir('fake-project') - with open(os.path.join('fake-project', 'README.rst')) as f: + with Path("fake-project", "README.rst").open() as f: assert 'Project name: **Fake Project**' in f.read() @@ -435,7 +435,7 @@ def test_local_extension(tmpdir, cli_runner): template_path, ) assert result.exit_code == 0 - with open(os.path.join(output_dir, 'Foobar', 'HISTORY.rst')) as f: + with Path(output_dir, 'Foobar', 'HISTORY.rst').open() as f: data = f.read() assert 'FoobarFoobar' in data assert 'FOOBAR' in data @@ -462,7 +462,7 @@ def test_cli_extra_context(cli_runner): ) assert result.exit_code == 0 assert os.path.isdir('fake-project') - with open(os.path.join('fake-project', 'README.rst')) as f: + with Path('fake-project', 'README.rst').open() as f: assert 'Project name: **Awesomez**' in f.read() @@ -544,13 +544,14 @@ def test_debug_list_installed_templates(cli_runner, debug_file, user_config_path """Verify --list-installed command correct invocation.""" fake_template_dir = os.path.dirname(os.path.abspath('fake-project')) os.makedirs(os.path.dirname(user_config_path)) - with open(user_config_path, 'w') as config_file: + with Path(user_config_path).open('w') as config_file: # In YAML, double quotes mean to use escape sequences. # Single quotes mean we will have unescaped backslahes. # http://blogs.perl.org/users/tinita/2018/03/ # strings-in-yaml---to-quote-or-not-to-quote.html config_file.write("cookiecutters_dir: '%s'" % fake_template_dir) - open(os.path.join('fake-project', 'cookiecutter.json'), 'w').write('{}') + with Path("fake-project", "cookiecutter.json").open("w") as f: + f.write('{}') result = cli_runner( '--list-installed', @@ -568,7 +569,7 @@ def test_debug_list_installed_templates_failure( ): """Verify --list-installed command error on invocation.""" os.makedirs(os.path.dirname(user_config_path)) - with open(user_config_path, 'w') as config_file: + with Path(user_config_path).open('w') as config_file: config_file.write('cookiecutters_dir: "/notarealplace/"') result = cli_runner( @@ -590,7 +591,7 @@ def test_directory_repo(cli_runner): ) assert result.exit_code == 0 assert os.path.isdir("fake-project") - with open(os.path.join("fake-project", "README.rst")) as f: + with Path("fake-project", "README.rst").open() as f: assert "Project name: **Fake Project**" in f.read()