Files
beeos/tests/test_package_manifest.py

51 lines
1.5 KiB
Python

import json
import tempfile
import unittest
from pathlib import Path
from beeos.core.package_manifest import ManifestError, load_manifest
BASE_MANIFEST = {
"id": "local.test.app",
"name": "Test App",
"type": "app",
"version": "1.0.0",
"author": "BeeOS",
"description": "Manifest validation test package",
"entry": "app.py",
}
class PackageManifestTests(unittest.TestCase):
def load_with_entry(self, entry: str):
data = {**BASE_MANIFEST, "entry": entry}
with tempfile.TemporaryDirectory() as temp_dir:
path = Path(temp_dir) / "manifest.json"
path.write_text(json.dumps(data), encoding="utf-8")
return load_manifest(path)
def test_accepts_relative_entry(self):
manifest = self.load_with_entry("src/app.py")
self.assertEqual(manifest.entry, "src/app.py")
def test_rejects_parent_directory_entry(self):
with self.assertRaisesRegex(ManifestError, "relative path"):
self.load_with_entry("../outside.py")
def test_rejects_windows_absolute_entry(self):
with self.assertRaisesRegex(ManifestError, "relative path"):
self.load_with_entry(r"C:\\outside.py")
def test_rejects_windows_parent_directory_entry(self):
with self.assertRaisesRegex(ManifestError, "relative path"):
self.load_with_entry(r"..\outside.py")
def test_rejects_empty_entry(self):
with self.assertRaisesRegex(ManifestError, "non-empty"):
self.load_with_entry(" ")
if __name__ == "__main__":
unittest.main()