copier/tests/helpers.py
2013-06-30 12:03:06 -05:00

47 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
from hashlib import sha1
from os import urandom
from os.path import join, dirname
from tempfile import mkdtemp
import filecmp
import io
import shutil
from voodoo import render_skeleton
SKELETON_PATH = join(dirname(__file__), 'demo')
def read_content(path):
with io.open(path, mode='rt', encoding='utf8') as f:
return f.read()
def write_content(path, content):
with io.open(path, mode='wt', encoding='utf8') as f:
return f.write(content)
class RenderMixin(object):
def setUp(self):
self.dst_path = mkdtemp()
def tearDown(self):
shutil.rmtree(self.dst_path)
def assert_file(self, *path):
p1 = join(self.dst_path, *path)
p2 = join(SKELETON_PATH, *path)
assert filecmp.cmp(p1, p2)
def render_skeleton(self, **kwargs):
data = {
'package': 'demo',
'py3': True,
'make_secret': lambda: sha1(urandom(48)).hexdigest()
}
kwargs.setdefault('quiet', True)
render_skeleton(SKELETON_PATH, self.dst_path, data=data, **kwargs)