mirror of
https://github.com/ai-robots-txt/ai.robots.txt.git
synced 2026-06-07 09:26:54 +02:00
Add tests for converter helpers
This commit is contained in:
parent
243ec6b67d
commit
e73aacfd22
1 changed files with 28 additions and 0 deletions
28
tests/test_converters.py
Normal file
28
tests/test_converters.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
MODULE_PATH = Path(__file__).resolve().parents[1] / "code" / "robots.py"
|
||||
|
||||
spec = importlib.util.spec_from_file_location("robots", MODULE_PATH)
|
||||
robots = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(robots)
|
||||
|
||||
|
||||
def test_json_to_txt_preserves_order():
|
||||
robots_txt = robots.json_to_txt({"BotA": {}, "BotB": {}})
|
||||
assert robots_txt == "User-agent: BotA\nUser-agent: BotB\nDisallow: /\n"
|
||||
|
||||
|
||||
def test_list_to_pcre_escapes_special_characters():
|
||||
items = ["Bot+One", "Bot(Two)"]
|
||||
expected = f"({"|".join(map(re.escape, items))})"
|
||||
assert robots.list_to_pcre(items) == expected
|
||||
|
||||
|
||||
def test_json_to_nginx_includes_robots_txt_exception():
|
||||
config = robots.json_to_nginx({"BotA": {}})
|
||||
assert "if ($request_uri = \"/robots.txt\")" in config
|
||||
Loading…
Add table
Add a link
Reference in a new issue