Files
pages/data/pageswiki_cli_test.py
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

48 lines
1.6 KiB
Python

import importlib.util
from pathlib import Path
import unittest
SCRIPT = Path(__file__).with_name("pageswiki-cli")
SPEC = importlib.util.spec_from_file_location("pageswiki_cli", SCRIPT)
if SPEC is None or SPEC.loader is None:
from importlib.machinery import SourceFileLoader
SPEC = importlib.util.spec_from_loader(
"pageswiki_cli",
SourceFileLoader("pageswiki_cli", str(SCRIPT)),
)
assert SPEC is not None and SPEC.loader is not None
pageswiki_cli = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(pageswiki_cli)
class ContentTypeDetectionTest(unittest.TestCase):
def test_extensionless_shell(self) -> None:
content_type = pageswiki_cli.detect_content_type(
b"#!/usr/bin/env bash\necho hello\n",
)
self.assertEqual(content_type, "application/x-sh; charset=utf-8")
def test_extensionless_utf8_text(self) -> None:
content_type = pageswiki_cli.detect_content_type(
"拡張子なしの文書\n".encode(),
)
self.assertEqual(content_type, "text/plain; charset=utf-8")
def test_magic_number_wins_over_text_analysis(self) -> None:
content_type = pageswiki_cli.detect_content_type(
b"%PDF-1.7\nsample",
)
self.assertEqual(content_type, "application/pdf")
def test_shift_jis_text(self) -> None:
content_type = pageswiki_cli.detect_content_type(
"日本語の文書\n".encode("shift_jis"),
)
self.assertEqual(content_type, "text/plain; charset=shift_jis")
if __name__ == "__main__":
unittest.main()