1
0
mirror of https://github.com/venthur/blag.git synced 2025-11-25 12:42:41 +00:00

added cleandir to change cwd

This commit is contained in:
Bastian Venthur
2021-03-29 13:02:12 +02:00
parent 72971408b2
commit 499b0dfe11
2 changed files with 41 additions and 34 deletions

View File

@@ -1,5 +1,5 @@
from tempfile import TemporaryDirectory
from os import mkdir
import os
import pytest
@@ -45,14 +45,32 @@ def tag_template(environment):
@pytest.fixture
def tempdir():
config = """
[main]
base_url = https://example.com/
title = title
description = description
author = a. u. thor
"""
with TemporaryDirectory() as dir:
for d in 'content', 'build', 'static', 'templates':
mkdir(f'{dir}/{d}')
os.mkdir(f'{dir}/{d}')
with open(f'{dir}/config.ini', 'w') as fh:
fh.write(config)
yield dir
@pytest.fixture
def args(tempdir):
def cleandir(tempdir):
old_cwd = os.getcwd()
os.chdir(tempdir)
yield
os.chdir(old_cwd)
@pytest.fixture
def args(cleandir):
class NameSpace:
def __init__(self, **kwargs):
@@ -60,9 +78,9 @@ def args(tempdir):
setattr(self, name, kwargs[name])
args = NameSpace(
input_dir=f'{tempdir}/content',
output_dir=f'{tempdir}/build',
static_dir=f'{tempdir}/static',
template_dir=f'{tempdir}/templates',
input_dir='content',
output_dir='build',
static_dir='static',
template_dir='templates',
)
yield args