Converting tests to the new-style

This commit is contained in:
Joe Rickerby
2020-05-02 16:54:19 +01:00
parent c38bc9064a
commit 616e9dd6eb
62 changed files with 750 additions and 103 deletions
+8 -9
View File
@@ -1,29 +1,28 @@
import os
import io
import jinja2
from typing import Union, Dict, Any
from typing import Union, Dict, Any, Optional
FilesDict = Dict[str, Union[str, jinja2.Template]]
TemplateContext = Dict[str, Any]
class TemplateProject:
default_files: FilesDict = {}
files: FilesDict
context: Dict[str, Any]
template_context: TemplateContext
def __init__(self, *, extra_files: FilesDict):
self.files = self.default_files.copy()
self.files.update(extra_files)
self.context = {}
def __init__(self):
self.files = {}
self.template_context = {}
def generate(self, path):
def generate(self, path: str):
for filename, content in self.files.items():
file_path = os.path.join(path, filename)
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with io.open(file_path, 'w', encoding='utf8') as f:
if isinstance(content, jinja2.Template):
content = content.render(self.context)
content = content.render(self.template_context)
f.write(content)