-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy pathtest_compile_llms.py
More file actions
92 lines (71 loc) · 3.35 KB
/
test_compile_llms.py
File metadata and controls
92 lines (71 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import shutil
import tempfile
import unittest
from pathlib import Path
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from docs.compile_llms_txt import compile_llms_txt
class TestCompileLLMsTxt(unittest.TestCase):
def setUp(self):
self.original_cwd = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Create a temporary directory for test files
self.test_dir = tempfile.mkdtemp()
self.docs_dir = Path(self.test_dir)
# Change to the temporary directory
os.chdir(self.docs_dir)
def tearDown(self):
os.chdir(self.original_cwd)
shutil.rmtree(self.test_dir)
def create_test_mdx_file(self, path: str, content: str):
"""Helper to create test MDX files"""
file_path = self.docs_dir / path
file_path.parent.mkdir(parents=True, exist_ok=True)
file_path.write_text(content)
def test_basic_compilation(self):
"""Test basic MDX file compilation"""
# Create test MDX files
self.create_test_mdx_file("test1.mdx", "Test content 1")
self.create_test_mdx_file("test2.mdx", "Test content 2")
# Run compilation
compile_llms_txt()
# Check output file exists and contains expected content
output_path = self.docs_dir / "llms.txt"
self.assertTrue(output_path.exists())
content = output_path.read_text()
self.assertIn("## test1.mdx", content)
self.assertIn("Test content 1", content)
self.assertIn("## test2.mdx", content)
self.assertIn("Test content 2", content)
def test_excluded_directories(self):
"""Test that files in excluded directories are skipped"""
# Create files in both regular and excluded directories
self.create_test_mdx_file("regular/file.mdx", "Regular content")
self.create_test_mdx_file("tool/file.mdx", "Tool content")
compile_llms_txt()
content = (self.docs_dir / "llms.txt").read_text()
self.assertIn("Regular content", content)
self.assertNotIn("Tool content", content)
def test_excluded_files(self):
"""Test that excluded files are skipped"""
self.create_test_mdx_file("regular.mdx", "Regular content")
self.create_test_mdx_file("tool.mdx", "Tool content")
compile_llms_txt()
content = (self.docs_dir / "llms.txt").read_text()
self.assertIn("Regular content", content)
self.assertNotIn("Tool content", content)
def test_nested_directories(self):
"""Test compilation from nested directory structure"""
self.create_test_mdx_file("dir1/test1.mdx", "Content 1")
self.create_test_mdx_file("dir1/dir2/test2.mdx", "Content 2")
compile_llms_txt()
content = (self.docs_dir / "llms.txt").read_text()
self.assertIn("## dir1/test1.mdx", content)
self.assertIn("## dir1/dir2/test2.mdx", content)
self.assertIn("Content 1", content)
self.assertIn("Content 2", content)
def test_empty_directory(self):
"""Test compilation with no MDX files"""
compile_llms_txt()
content = (self.docs_dir / "llms.txt").read_text()
self.assertEqual(content, "")