vfbquery 0.2.12__py3-none-any.whl → 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- test/readme_parser.py +103 -0
- test/term_info_queries_test.py +111 -177
- test/test_examples_diff.py +317 -0
- vfbquery/__init__.py +3 -0
- vfbquery/solr_fetcher.py +100 -0
- vfbquery/term_info_queries.py +63 -3
- vfbquery/test_utils.py +39 -0
- vfbquery/vfb_queries.py +350 -76
- vfbquery-0.3.3.dist-info/METADATA +1316 -0
- vfbquery-0.3.3.dist-info/RECORD +14 -0
- {vfbquery-0.2.12.dist-info → vfbquery-0.3.3.dist-info}/WHEEL +1 -1
- vfbquery-0.2.12.dist-info/METADATA +0 -1169
- vfbquery-0.2.12.dist-info/RECORD +0 -10
- {vfbquery-0.2.12.dist-info → vfbquery-0.3.3.dist-info}/LICENSE +0 -0
- {vfbquery-0.2.12.dist-info → vfbquery-0.3.3.dist-info}/top_level.txt +0 -0
test/readme_parser.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import json
|
|
3
|
+
import os.path
|
|
4
|
+
|
|
5
|
+
def extract_code_blocks(readme_path):
|
|
6
|
+
"""
|
|
7
|
+
Extracts Python code blocks and JSON blocks from a README.md file
|
|
8
|
+
and returns them as separate lists.
|
|
9
|
+
"""
|
|
10
|
+
if not os.path.isfile(readme_path):
|
|
11
|
+
raise FileNotFoundError(f"README file not found at {readme_path}")
|
|
12
|
+
|
|
13
|
+
with open(readme_path, 'r') as f:
|
|
14
|
+
content = f.read()
|
|
15
|
+
|
|
16
|
+
# Extract Python code blocks with proper anchoring to avoid nested confusion
|
|
17
|
+
python_pattern = r'```python\s*(.*?)\s*```'
|
|
18
|
+
python_blocks = re.findall(python_pattern, content, re.DOTALL)
|
|
19
|
+
|
|
20
|
+
# Extract JSON code blocks with proper anchoring
|
|
21
|
+
json_pattern = r'```json\s*(.*?)\s*```'
|
|
22
|
+
json_blocks = re.findall(json_pattern, content, re.DOTALL)
|
|
23
|
+
|
|
24
|
+
# Process Python blocks to extract vfb calls
|
|
25
|
+
processed_python_blocks = []
|
|
26
|
+
for block in python_blocks:
|
|
27
|
+
# Look for vfb.* calls and extract them
|
|
28
|
+
vfb_calls = re.findall(r'(vfb\.[^)]*\))', block)
|
|
29
|
+
if vfb_calls:
|
|
30
|
+
processed_python_blocks.extend(vfb_calls)
|
|
31
|
+
|
|
32
|
+
# Process JSON blocks
|
|
33
|
+
processed_json_blocks = []
|
|
34
|
+
for block in json_blocks:
|
|
35
|
+
try:
|
|
36
|
+
# Clean up the JSON text
|
|
37
|
+
json_text = block.strip()
|
|
38
|
+
# Convert Python boolean literals to JSON booleans using regex
|
|
39
|
+
json_text = re.sub(r'\bTrue\b', 'true', json_text)
|
|
40
|
+
json_text = re.sub(r'\bFalse\b', 'false', json_text)
|
|
41
|
+
# Parse the JSON and add to results
|
|
42
|
+
json_obj = json.loads(json_text)
|
|
43
|
+
processed_json_blocks.append(json_obj)
|
|
44
|
+
except json.JSONDecodeError as e:
|
|
45
|
+
# Determine a context range around the error position
|
|
46
|
+
start = max(e.pos - 20, 0)
|
|
47
|
+
end = e.pos + 20
|
|
48
|
+
context = json_text[start:end]
|
|
49
|
+
print(f"Error parsing JSON block: {e.msg} at line {e.lineno} column {e.colno} (char {e.pos})")
|
|
50
|
+
print(f"Context: ...{context}...")
|
|
51
|
+
|
|
52
|
+
return processed_python_blocks, processed_json_blocks
|
|
53
|
+
|
|
54
|
+
def generate_python_file(python_blocks, output_path):
|
|
55
|
+
"""
|
|
56
|
+
Generates a Python file containing the extracted code blocks wrapped in a results list.
|
|
57
|
+
"""
|
|
58
|
+
with open(output_path, 'w') as f:
|
|
59
|
+
f.write('import vfbquery as vfb\n\n') # Add import statement
|
|
60
|
+
f.write('results = []\n')
|
|
61
|
+
for block in python_blocks:
|
|
62
|
+
f.write(f'results.append({block})\n')
|
|
63
|
+
|
|
64
|
+
def generate_json_file(json_blocks, output_path):
|
|
65
|
+
"""
|
|
66
|
+
Generates a Python file containing the extracted JSON blocks as a Python list.
|
|
67
|
+
"""
|
|
68
|
+
with open(output_path, 'w') as f:
|
|
69
|
+
f.write('from src.vfbquery.term_info_queries import *\n')
|
|
70
|
+
f.write('results = ')
|
|
71
|
+
|
|
72
|
+
# Convert JSON list to Python compatible string
|
|
73
|
+
# This handles 'null' conversion to 'None' and other JSON->Python differences
|
|
74
|
+
python_list = str(json_blocks)
|
|
75
|
+
# Replace true/false with True/False
|
|
76
|
+
python_list = python_list.replace('true', 'True').replace('false', 'False')
|
|
77
|
+
# Replace null with None
|
|
78
|
+
python_list = python_list.replace('null', 'None')
|
|
79
|
+
|
|
80
|
+
f.write(python_list)
|
|
81
|
+
|
|
82
|
+
def process_readme(readme_path, python_output_path, json_output_path):
|
|
83
|
+
"""
|
|
84
|
+
Process the README file and generate the test files.
|
|
85
|
+
"""
|
|
86
|
+
python_blocks, json_blocks = extract_code_blocks(readme_path)
|
|
87
|
+
generate_python_file(python_blocks, python_output_path)
|
|
88
|
+
generate_json_file(json_blocks, json_output_path)
|
|
89
|
+
|
|
90
|
+
return len(python_blocks), len(json_blocks)
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
# Example usage
|
|
94
|
+
readme_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'README.md')
|
|
95
|
+
python_blocks, json_blocks = extract_code_blocks(readme_path)
|
|
96
|
+
|
|
97
|
+
python_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'test_examples.py')
|
|
98
|
+
json_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'test_results.py')
|
|
99
|
+
|
|
100
|
+
generate_python_file(python_blocks, python_path)
|
|
101
|
+
generate_json_file(json_blocks, json_path)
|
|
102
|
+
|
|
103
|
+
print(f"Extracted {len(python_blocks)} Python blocks and {len(json_blocks)} JSON blocks")
|