Skip to content

Commit

Permalink
Tests: Use pathlib for files read/write (test_cli.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
insspb committed Jun 8, 2022
1 parent 260b856 commit 1d18696
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/test_cli.py
Expand Up @@ -3,7 +3,7 @@
import json
import os
import re

from pathlib import Path

import pytest
from click.testing import CliRunner
Expand Down Expand Up @@ -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()


Expand All @@ -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()


Expand Down Expand Up @@ -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
Expand All @@ -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()


Expand Down Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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()


Expand Down

0 comments on commit 1d18696

Please sign in to comment.