import re
import unittest
from pathlib import Path


class PackagingTests(unittest.TestCase):
    def test_installed_launcher_is_not_world_writable(self):
        spec = (Path(__file__).resolve().parents[1] / "swai-inst.spec").read_text(encoding="utf-8")
        match = re.search(r"^install\s+-m\s+(\d+)\s+__main__\.py\s+.*?/swai-inst$", spec, re.MULTILINE)
        self.assertIsNotNone(match, "swai-inst launcher install rule is missing")
        self.assertEqual(match.group(1), "0755")


if __name__ == "__main__":
    unittest.main()
