Use patlib.Path in tests and tools

This commit is contained in:
Yannick Jadoul
2020-06-18 15:29:48 +02:00
parent f012fa1af0
commit acf5c24881
8 changed files with 35 additions and 53 deletions
+7 -5
View File
@@ -1,5 +1,7 @@
import os
from pathlib import Path
import jinja2
from typing import Union, Dict, Any
@@ -21,12 +23,12 @@ class TestProject:
self.files = {}
self.template_context = {}
def generate(self, path: str):
def generate(self, path: Path):
for filename, content in self.files.items():
file_path = os.path.join(path, filename)
os.makedirs(os.path.dirname(file_path), exist_ok=True)
file_path = path / filename
file_path.parent.mkdir(parents=True, exist_ok=True)
with open(file_path, 'w', encoding='utf8') as f:
with file_path.open('w', encoding='utf8') as f:
if isinstance(content, jinja2.Template):
content = content.render(self.template_context)