@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
py 55 lines 1.93 KB
Raw
1 """Checks for decoding the shared JSON Schema fixtures."""
2
3 import json
4 from pathlib import Path
5 from unittest.mock import patch
6
7 import pytest
8
9 from tests.fixtures import json_schema_conversion_corpus as corpus
10
11
12 @pytest.mark.parametrize("default_encoding", ["cp936", "cp1252"])
13 @pytest.mark.parametrize("strict", [False, True], ids=["object", "strict"])
14 def test_corpus_uses_utf8_independently_of_locale(
15 tmp_path: Path, monkeypatch: pytest.MonkeyPatch, default_encoding: str, strict: bool
16 ) -> None:
17 glyph = "\U0001d11e"
18 case: dict[str, object] = {
19 "id": "unicode-fixture",
20 "description": glyph,
21 "schema": {"type": "object"},
22 }
23 if strict:
24 case["strict"] = {"schema": {"type": "object"}}
25 path_attribute = "STRICT_CORPUS_PATH"
26 cache_attribute = "_cached_strict"
27 else:
28 case["instances"] = [{"input": {"glyph": glyph}, "accepted": True}]
29 path_attribute = "CORPUS_PATH"
30 cache_attribute = "_cached"
31
32 load = corpus.load_strict_cases if strict else corpus.load_object_cases
33
34 fixture_path = tmp_path / "corpus.json"
35 fixture_path.write_text(
36 json.dumps({"cases": [case]}, ensure_ascii=False), encoding="utf-8"
37 )
38 monkeypatch.setattr(corpus, path_attribute, fixture_path)
39 monkeypatch.setattr(corpus, cache_attribute, None)
40
41 original_read_text = Path.read_text
42
43 def read_text_with_locale_default(path, encoding=None, errors=None):
44 # Emulate a Windows locale without changing the host's global locale.
45 if path == fixture_path and encoding is None:
46 encoding = default_encoding
47 return original_read_text(path, encoding=encoding, errors=errors)
48
49 with patch.object(Path, "read_text", read_text_with_locale_default):
50 cases = load()
51
52 assert cases[0].description == glyph
53 if not strict:
54 assert corpus.load_object_cases()[0].instances[0].input == {"glyph": glyph}
55 assert load() is cases