copier/tests/conftest.py
Juan-Pablo Scaletti 4c286ea6bd Fix for Python 3.5
2019-06-12 23:54:21 -05:00

34 lines
758 B
Python

from os import SEEK_END
from pathlib import Path
from tempfile import mkdtemp
import six
import shutil
import pytest
from unittest import mock
@pytest.fixture()
def dst(request):
"""Return a real temporary folder path which is unique to each test
function invocation. This folder is deleted after the test has finished.
"""
dst = mkdtemp()
request.addfinalizer(lambda: shutil.rmtree(dst, ignore_errors=True))
return Path(dst)
class AppendableStringIO(six.StringIO):
def append(self, text):
pos = self.tell()
self.seek(0, SEEK_END)
self.write(text)
self.seek(pos)
@pytest.fixture()
def stdin():
buffer = AppendableStringIO()
with mock.patch("sys.stdin", buffer):
yield buffer