diff --git a/htmd/cli.py b/htmd/cli.py index e629c16..70e96f4 100644 --- a/htmd/cli.py +++ b/htmd/cli.py @@ -1,6 +1,6 @@ import datetime import importlib -import os +from pathlib import Path import sys import click @@ -28,23 +28,23 @@ def cli(): help='Include all templates.', ) def start(all_templates): - create_directory('templates/') + dir_templates = create_directory('templates/') if all_templates: copy_missing_templates() else: - copy_site_file('templates', '_layout.html') + copy_site_file(dir_templates, '_layout.html') - create_directory('static/') - copy_site_file('static', '_reset.css') - copy_site_file('static', 'style.css') + dir_static = create_directory('static/') + copy_site_file(dir_static, '_reset.css') + copy_site_file(dir_static, 'style.css') - create_directory('pages/') - copy_site_file('pages', 'about.html') + dir_pages = create_directory('pages/') + copy_site_file(dir_pages, 'about.html') - create_directory('posts/') - copy_site_file('posts', 'example.md') + dir_posts = create_directory('posts/') + copy_site_file(dir_posts, 'example.md') - copy_site_file('', 'config.toml') + copy_site_file(Path(), 'config.toml') click.echo('Add the site name and edit settings in config.toml') @@ -92,15 +92,15 @@ def verify(): def set_post_time(app, post, field, date_time): - file_path = os.path.join( - app.config['FLATPAGES_ROOT'], - post.path + app.config['FLATPAGES_EXTENSION'], + file_path = ( + Path(app.config['FLATPAGES_ROOT']) + / (post.path + app.config['FLATPAGES_EXTENSION']) ) - with open(file_path, 'r') as file: + with file_path.open('r') as file: lines = file.readlines() found = False - with open(file_path, 'w') as file: + with file_path.open('w') as file: for line in lines: if not found and field in line: # Update datetime value @@ -159,10 +159,10 @@ def build(ctx, css_minify, js_minify): app = site.app if css_minify: - combine_and_minify_css(app.static_folder) + combine_and_minify_css(Path(app.static_folder)) if js_minify: - combine_and_minify_js(app.static_folder) + combine_and_minify_js(Path(app.static_folder)) if css_minify or js_minify: # reload to set app.config['INCLUDE_CSS'] and app.config['INCLUDE_JS'] @@ -213,10 +213,10 @@ def preview(_ctx, host, port, css_minify, js_minify): app = site.app if css_minify: - combine_and_minify_css(app.static_folder) + combine_and_minify_css(Path(app.static_folder)) if js_minify: - combine_and_minify_js(app.static_folder) + combine_and_minify_js(Path(app.static_folder)) app.run(debug=True, host=host, port=port) diff --git a/htmd/site.py b/htmd/site.py index 65c642e..605b30d 100644 --- a/htmd/site.py +++ b/htmd/site.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import sys import tomllib @@ -11,20 +12,20 @@ from jinja2 import ChoiceLoader, FileSystemLoader, TemplateNotFound -this_dir = os.path.dirname(os.path.abspath(__file__)) +this_dir = Path(__file__).parent def get_project_dir(): - current_directory = os.getcwd() + current_directory = Path.cwd() while True: - file_path = os.path.join(current_directory, 'config.toml') + file_path = current_directory / 'config.toml' - if os.path.isfile(file_path): + if file_path.is_file(): return current_directory # Move to the parent directory - parent_directory = os.path.dirname(current_directory) + parent_directory = current_directory.parent # If the current and parent directories are the same, break the loop if current_directory == parent_directory: @@ -32,20 +33,20 @@ def get_project_dir(): current_directory = parent_directory - return os.getcwd() + return Path.cwd() project_dir = get_project_dir() app = Flask( __name__, - static_folder=os.path.join(project_dir, 'static'), - template_folder=os.path.join(this_dir, 'example_site', 'templates'), + static_folder=project_dir / 'static', + template_folder=this_dir / 'example_site' / 'templates', ) try: - with open(os.path.join(project_dir, 'config.toml'), 'rb') as config_file: + with (project_dir / 'config.toml').open('rb') as config_file: htmd_config = tomllib.load(config_file) except FileNotFoundError: msg = 'Can not find config.toml' @@ -81,11 +82,11 @@ def get_project_dir(): # To avoid full paths in config.toml -app.config['FLATPAGES_ROOT'] = os.path.join( - project_dir, app.config.get('POSTS_FOLDER'), +app.config['FLATPAGES_ROOT'] = ( + project_dir / app.config.get('POSTS_FOLDER') ) -app.config['FREEZER_DESTINATION'] = os.path.join( - project_dir, app.config.get('BUILD_FOLDER'), +app.config['FREEZER_DESTINATION'] = ( + project_dir / app.config.get('BUILD_FOLDER') ) app.config['FREEZER_REMOVE_EXTRA_FILES'] = False app.config['FLATPAGES_EXTENSION'] = app.config.get('POSTS_EXTENSION') @@ -111,7 +112,7 @@ def truncate_post_html(post_html): # Include current htmd site templates app.jinja_loader = ChoiceLoader([ - FileSystemLoader(os.path.join(project_dir, 'templates/')), + FileSystemLoader(project_dir / 'templates/'), app.jinja_loader, ]) @@ -133,7 +134,7 @@ def truncate_post_html(post_html): pages = Blueprint( 'pages', __name__, - template_folder=os.path.join(project_dir, app.config.get('PAGES_FOLDER')), + template_folder=project_dir / app.config.get('PAGES_FOLDER'), ) diff --git a/htmd/utils.py b/htmd/utils.py index 2e3cb69..9615afc 100644 --- a/htmd/utils.py +++ b/htmd/utils.py @@ -1,5 +1,5 @@ from importlib.resources import as_file, files -import os +from pathlib import Path import shutil import click @@ -8,64 +8,66 @@ def create_directory(name): + directory = Path(name) try: - os.mkdir(name) + directory.mkdir() except FileExistsError: msg = f'{name} already exists and was not created.' click.echo(click.style(msg, fg='yellow')) else: click.echo(click.style(f'{name} was created.', fg='green')) + return directory def combine_and_minify_css(static_folder): # Combine and minify all .css files in the static folder css_files = sorted([ - f for f in os.listdir(static_folder) - if f.endswith('.css') and f != 'combined.min.css' + f for f in static_folder.iterdir() + if f.name.endswith('.css') and f.name != 'combined.min.css' ]) if not css_files: # There are no .css files in the static folder return - with open(os.path.join(static_folder, 'combined.min.css'), 'w') as master: + with (static_folder / 'combined.min.css').open('w') as master: for f in css_files: - with open(os.path.join(static_folder, f), 'r') as css_file: + with (static_folder / f).open('r') as css_file: # combine all .css files into one master.write(css_file.read()) - with open(os.path.join(static_folder, 'combined.min.css'), 'r') as master: + with (static_folder / 'combined.min.css').open('r') as master: combined = master.read() - with open(os.path.join(static_folder, 'combined.min.css'), 'w') as master: + with (static_folder / 'combined.min.css').open('w') as master: master.write(compress(combined)) def combine_and_minify_js(static_folder): # Combine and minify all .js files in the static folder js_files = sorted([ - f for f in os.listdir(static_folder) - if f.endswith('.js') - and f != 'combined.min.js' + f for f in static_folder.iterdir() + if f.name.endswith('.js') + and f.name != 'combined.min.js' ]) if not js_files: # There are no .js files in the static folder return - with open(os.path.join(static_folder, 'combined.min.js'), 'w') as master: + with (static_folder / 'combined.min.js').open('w') as master: for f in js_files: - with open(os.path.join(static_folder, f), 'r') as js_file: + with (static_folder / f).open('r') as js_file: # combine all .js files into one master.write(js_file.read()) # minify should be done after combined to avoid duplicate identifiers # minifying each file will use 'a' for the first identifier - with open(os.path.join(static_folder, 'combined.min.js'), 'r') as master: + with (static_folder / 'combined.min.js').open('r') as master: combined = master.read() - with open(os.path.join(static_folder, 'combined.min.js'), 'w') as master: + with (static_folder / 'combined.min.js').open('w') as master: master.write(jsmin(combined)) def copy_file(source, destination): - if os.path.exists(destination) is False: + if destination.exists() is False: shutil.copyfile(source, destination) click.echo(click.style(f'{destination} was created.', fg='green')) else: @@ -76,17 +78,17 @@ def copy_file(source, destination): def copy_missing_templates(): template_dir = files('htmd.example_site') / 'templates' for template_file in sorted(template_dir.iterdir()): - file_name = os.path.basename(template_file) - copy_file(template_file, os.path.join('templates/', file_name)) + file_name = template_file.name + copy_file(template_file, Path('templates') / file_name) def copy_site_file(directory, filename): - if directory == '': + if directory.name == '': anchor = 'htmd.example_site' else: anchor = f'htmd.example_site.{directory}' source_path = files(anchor) / filename - destination_path = os.path.join(directory, filename) + destination_path = directory / filename with as_file(source_path) as file: copy_file(file, destination_path) diff --git a/pyproject.toml b/pyproject.toml index 1dbb619..40b6483 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ ignore = [ "RET504", "S101", "UP015", - "ANN", "PTH", + "ANN", ] select = ["ALL"] diff --git a/tests/test_build.py b/tests/test_build.py index 17fa242..9bb409e 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,5 +1,6 @@ import datetime import os +from pathlib import Path import re import shutil @@ -40,7 +41,7 @@ def test_build_js_minify(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('static', 'app.js'), 'w') as js_file: + with (Path('static') / 'app.js').open('w') as js_file: js_file.write('console.log("htmd");') result = runner.invoke(build, ['--js-minify']) @@ -71,7 +72,7 @@ def test_build_css_minify(): with runner.isolated_filesystem(): result = runner.invoke(start) result = runner.invoke(build, ['--css-minify']) - with open(os.path.join('build', 'index.html'), 'r') as built_index: + with (Path('build') / 'index.html').open('r') as built_index: contents = built_index.read() assert result.exit_code == 0 assert re.search(SUCCESS_REGEX, result.output) @@ -91,8 +92,8 @@ def test_build_css_minify_no_css_files(): runner = CliRunner() with runner.isolated_filesystem(): result = runner.invoke(start) - os.remove(os.path.join('static', 'style.css')) - os.remove(os.path.join('static', '_reset.css')) + (Path('static') / 'style.css').unlink() + (Path('static') / '_reset.css').unlink() result = runner.invoke(build, ['--css-minify']) assert result.exit_code == 0 assert re.search(SUCCESS_REGEX, result.output) @@ -102,10 +103,10 @@ def test_build_html_pretty_true(): runner = CliRunner() with runner.isolated_filesystem(): result = runner.invoke(start) - with open('config.toml', 'r') as config_file: + with Path('config.toml').open('r') as config_file: lines = config_file.readlines() - with open('config.toml', 'w') as config_file: + with Path('config.toml').open('w') as config_file: for line in lines: if 'pretty =' in line: config_file.write('pretty = true\n') @@ -121,10 +122,10 @@ def test_build_html_minify_true(): runner = CliRunner() with runner.isolated_filesystem(): result = runner.invoke(start) - with open('config.toml', 'r') as config_file: + with Path('config.toml').open('r') as config_file: lines = config_file.readlines() - with open('config.toml', 'w') as config_file: + with Path('config.toml').open('w') as config_file: for line in lines: if 'minify =' in line: config_file.write('minify = true\n') @@ -148,11 +149,11 @@ def test_build_page_404(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -175,11 +176,11 @@ def test_build_post_404_invalid_date_year(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -202,10 +203,10 @@ def test_build_post_404_invalid_date_month(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: lines = post_file.readlines() - with open(os.path.join('posts', 'about.html'), 'w') as post_file: + with (Path('posts') / 'about.html').open('w') as post_file: for line in lines: if 'published' in line: post_file.write('published: 2014-01-30') @@ -214,11 +215,11 @@ def test_build_post_404_invalid_date_month(): else: post_file.write(line) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -241,10 +242,10 @@ def test_build_post_404_invalid_date_day(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: lines = post_file.readlines() - with open(os.path.join('posts', 'about.html'), 'w') as post_file: + with (Path('posts') / 'about.html').open('w') as post_file: for line in lines: if 'published' in line: post_file.write('published: 2014-10-03') @@ -253,11 +254,11 @@ def test_build_post_404_invalid_date_day(): else: post_file.write(line) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -281,11 +282,11 @@ def test_build_post_404_different_date(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -302,8 +303,8 @@ def test_build_multiple_posts(): with runner.isolated_filesystem(): result = runner.invoke(start) shutil.copyfile( - os.path.join('posts', 'example.md'), - os.path.join('posts', 'sample.md'), + Path('posts') / 'example.md', + Path('posts') / 'sample.md', ) result = runner.invoke(build) assert result.exit_code == 0 @@ -322,11 +323,11 @@ def test_build_year_404_incorrect(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -350,11 +351,11 @@ def test_build_year_404_no_posts(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -378,11 +379,11 @@ def test_build_month_404_no_posts(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -406,11 +407,11 @@ def test_build_day_404_no_posts(): with runner.isolated_filesystem(): result = runner.invoke(start) - with open(os.path.join('pages', 'about.html'), 'r') as about_file: + with (Path('pages') / 'about.html').open('r') as about_file: lines = about_file.readlines() new_line = '''

DNE link

\n''' # noqa: E501 - with open(os.path.join('pages', 'about.html'), 'w') as about_file: + with (Path('pages') / 'about.html').open('w') as about_file: for line in lines: if '

This is the about page.

' in line: about_file.write(new_line) @@ -426,8 +427,8 @@ def test_build_from_sub_directory(): runner = CliRunner() with runner.isolated_filesystem(): runner.invoke(start) - current_directory = os.getcwd() - os.chdir(os.path.join(current_directory, 'posts')) + current_directory = Path.cwd() + os.chdir(Path(current_directory) / 'posts') result = runner.invoke(build) assert result.exit_code == 0 assert re.search(SUCCESS_REGEX, result.output) @@ -438,8 +439,8 @@ def test_build_feed_dot_atom(): with runner.isolated_filesystem(): runner.invoke(start) runner.invoke(build) - current_directory = os.getcwd() - assert os.path.isfile(os.path.join(current_directory, 'build', 'feed.atom')) + current_directory = Path.cwd() + assert (Path(current_directory) / 'build' / 'feed.atom').is_file def test_build_updated_time_is_added(): @@ -450,10 +451,10 @@ def test_build_updated_time_is_added(): runner = CliRunner() with runner.isolated_filesystem(): runner.invoke(start) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: b_lines = post_file.readlines() runner.invoke(build) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: a_lines = post_file.readlines() for b_line, a_line in zip(b_lines, a_lines, strict=True): if 'updated' in b_line: @@ -500,10 +501,10 @@ def test_build_published_time_is_added(): with runner.isolated_filesystem(): runner.invoke(start) remove_fields_from_example_post(('updated',)) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: b_lines = post_file.readlines() runner.invoke(build) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: a_lines = post_file.readlines() for b_line, a_line in zip(b_lines, a_lines, strict=True): if 'published' in b_line: @@ -550,7 +551,7 @@ def test_build_updated_is_added(): runner.invoke(build) # Second build adds updated with time runner.invoke(build) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: a_lines = post_file.readlines() for a_line in a_lines: if 'updated' in a_line: @@ -576,9 +577,9 @@ def test_build_updated_is_added_once(): with runner.isolated_filesystem(): runner.invoke(start) # Remove updated from example post - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: b_lines = post_file.readlines() - with open(os.path.join('posts', 'example.md'), 'w') as post_file: + with (Path('posts') / 'example.md').open('w') as post_file: for line in b_lines: if 'updated' not in line: post_file.write(line) @@ -589,7 +590,7 @@ def test_build_updated_is_added_once(): runner.invoke(build) # Second build adds updated runner.invoke(build) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: a_lines = post_file.readlines() count = 0 for a_line in a_lines: @@ -607,7 +608,7 @@ def test_build_without_published(): # First build adds published time runner.invoke(build) - with open(os.path.join('posts', 'example.md'), 'r') as post_file: + with (Path('posts') / 'example.md').open('r') as post_file: a_lines = post_file.readlines() count = 0 for a_line in a_lines: diff --git a/tests/test_start.py b/tests/test_start.py index de434ca..6c24e3f 100644 --- a/tests/test_start.py +++ b/tests/test_start.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path from click.testing import CliRunner from htmd.cli import start @@ -60,11 +60,11 @@ def test_start_all_templates(): def test_start_with_existing_template(): runner = CliRunner() with runner.isolated_filesystem(): - os.mkdir('templates') - with open(os.path.join('templates', '_layout.html'), 'w') as layout: + Path('templates').mkdir() + with (Path('templates') / '_layout.html').open('w') as layout: pass result = runner.invoke(start) - with open(os.path.join('templates', '_layout.html'), 'r') as layout: + with (Path('templates') / '_layout.html').open('r') as layout: # _layout.html was not replaced assert layout.read() == '' assert result.exit_code == 0 diff --git a/tests/test_verify.py b/tests/test_verify.py index a516e33..c4f1349 100644 --- a/tests/test_verify.py +++ b/tests/test_verify.py @@ -1,4 +1,4 @@ -import os +from pathlib import Path from click.testing import CliRunner from htmd.cli import start, verify @@ -65,9 +65,9 @@ def test_verify_published_invalid_year(): with runner.isolated_filesystem(): runner.invoke(start) - with open(os.path.join('posts', 'example.md'), 'r') as post: + with (Path('posts') / 'example.md').open('r') as post: lines = post.readlines() - with open(os.path.join('posts', 'example.md'), 'w') as post: + with (Path('posts') / 'example.md').open('w') as post: for line in lines: if 'published' in line: post.write('published: 14-10-30\n') @@ -88,9 +88,9 @@ def test_verify_published_invalid_month(): with runner.isolated_filesystem(): runner.invoke(start) - with open(os.path.join('posts', 'example.md'), 'r') as post: + with (Path('posts') / 'example.md').open('r') as post: lines = post.readlines() - with open(os.path.join('posts', 'example.md'), 'w') as post: + with (Path('posts') / 'example.md').open('w') as post: for line in lines: if 'published' in line: post.write('published: 2014-1-30\n') @@ -111,9 +111,9 @@ def test_verify_published_invalid_day(): with runner.isolated_filesystem(): runner.invoke(start) - with open(os.path.join('posts', 'example.md'), 'r') as post: + with (Path('posts') / 'example.md').open('r') as post: lines = post.readlines() - with open(os.path.join('posts', 'example.md'), 'w') as post: + with (Path('posts') / 'example.md').open('w') as post: for line in lines: if 'published' in line: post.write('published: 2014-01-3\n') @@ -138,9 +138,9 @@ def test_verify_site_name_empty(): with runner.isolated_filesystem(): runner.invoke(start) - with open('config.toml', 'r') as post: + with Path('config.toml').open('r') as post: lines = post.readlines() - with open('config.toml', 'w') as post: + with Path('config.toml').open('w') as post: seen = False for line in lines: if 'name' in line and not seen: @@ -165,9 +165,9 @@ def test_verify_site_name_missing(): with runner.isolated_filesystem(): runner.invoke(start) - with open('config.toml', 'r') as post: + with Path('config.toml').open('r') as post: lines = post.readlines() - with open('config.toml', 'w') as post: + with Path('config.toml').open('w') as post: for line in lines: if 'name' not in line: post.write(line) @@ -184,7 +184,7 @@ def test_verify_no_config(): with runner.isolated_filesystem(): runner.invoke(start) - os.remove('config.toml') + Path('config.toml').unlink() result = runner.invoke(verify) diff --git a/tests/utils.py b/tests/utils.py index 2ea1cef..e33dcd8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,10 +1,10 @@ -import os +from pathlib import Path def remove_fields_from_example_post(field_names): - with open(os.path.join('posts', 'example.md'), 'r') as post: + with (Path('posts') / 'example.md').open('r') as post: lines = post.readlines() - with open(os.path.join('posts', 'example.md'), 'w') as post: + with (Path('posts') / 'example.md').open('w') as post: for line in lines: for field_name in field_names: if field_name in line: