Init Project Flexly CMS
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import datetime as dt
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
EXAMPLE = ROOT / "examples" / "studio-site"
|
||||
NOW = dt.datetime(2026, 11, 7, 12, 0, 0, tzinfo=dt.timezone.utc)
|
||||
|
||||
|
||||
class SiteTestCase(unittest.TestCase):
|
||||
"""Каждый тест получает свежую копию примера во временном каталоге."""
|
||||
|
||||
def setUp(self):
|
||||
self._tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self._tmp.cleanup)
|
||||
self.tmp = Path(self._tmp.name)
|
||||
self.site = self.tmp / "site"
|
||||
shutil.copytree(EXAMPLE, self.site)
|
||||
self.out = self.tmp / "dist"
|
||||
|
||||
def edit(self, rel: str, old: str, new: str) -> None:
|
||||
path = self.site / rel
|
||||
text = path.read_text(encoding="utf-8")
|
||||
assert old in text, f"{old!r} не найден в {rel}"
|
||||
path.write_text(text.replace(old, new), encoding="utf-8")
|
||||
|
||||
def write(self, rel: str, text: str) -> None:
|
||||
path = self.site / rel
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(text, encoding="utf-8")
|
||||
Reference in New Issue
Block a user