This commit is contained in:
77
scripts/README.md
Normal file
77
scripts/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
# Scripts
|
||||
|
||||
This directory contains helper scripts for working with PICT models and test cases.
|
||||
|
||||
## Available Scripts
|
||||
|
||||
### pict_helper.py
|
||||
|
||||
A Python utility for:
|
||||
- Generating PICT models from JSON configuration
|
||||
- Formatting PICT output as markdown tables
|
||||
- Parsing PICT output into JSON
|
||||
|
||||
**Installation:**
|
||||
```bash
|
||||
pip install pypict --break-system-packages
|
||||
```
|
||||
|
||||
**Usage:**
|
||||
|
||||
1. **Generate PICT model from config:**
|
||||
```bash
|
||||
python pict_helper.py generate config.json > model.txt
|
||||
```
|
||||
|
||||
2. **Format PICT output as markdown:**
|
||||
```bash
|
||||
python pict_helper.py format output.txt
|
||||
```
|
||||
|
||||
3. **Parse PICT output to JSON:**
|
||||
```bash
|
||||
python pict_helper.py parse output.txt
|
||||
```
|
||||
|
||||
**Example config.json:**
|
||||
```json
|
||||
{
|
||||
"parameters": {
|
||||
"Browser": ["Chrome", "Firefox", "Safari"],
|
||||
"OS": ["Windows", "MacOS", "Linux"],
|
||||
"Memory": ["4GB", "8GB", "16GB"]
|
||||
},
|
||||
"constraints": [
|
||||
"IF [OS] = \"MacOS\" THEN [Browser] <> \"IE\"",
|
||||
"IF [Memory] = \"4GB\" THEN [OS] <> \"MacOS\""
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Future Scripts
|
||||
|
||||
We welcome contributions for:
|
||||
- Test automation generators
|
||||
- Export to test management tools (JIRA, TestRail)
|
||||
- Integration with CI/CD pipelines
|
||||
- Coverage analysis tools
|
||||
- Constraint validation utilities
|
||||
|
||||
## Contributing
|
||||
|
||||
Have a useful script to share?
|
||||
|
||||
1. Add your script to this directory
|
||||
2. Update this README with usage instructions
|
||||
3. Add comments and examples in your script
|
||||
4. Submit a pull request
|
||||
|
||||
See [CONTRIBUTING.md](../CONTRIBUTING.md) for guidelines.
|
||||
|
||||
## Dependencies
|
||||
|
||||
Current scripts use:
|
||||
- Python 3.7+
|
||||
- pypict (optional, for direct PICT integration)
|
||||
|
||||
All dependencies should be clearly documented in each script.
|
||||
207
scripts/pict_helper.py
Normal file
207
scripts/pict_helper.py
Normal file
@@ -0,0 +1,207 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
PICT Helper Script
|
||||
|
||||
This script provides utilities for working with PICT models and test cases.
|
||||
|
||||
Note: This is a placeholder/example script. Full implementation coming soon!
|
||||
|
||||
Requirements:
|
||||
pip install pypict --break-system-packages
|
||||
|
||||
Usage:
|
||||
python pict_helper.py generate config.json
|
||||
python pict_helper.py format output.txt
|
||||
python pict_helper.py parse output.txt
|
||||
"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
from typing import Dict, List, Any
|
||||
|
||||
def generate_model(config_file: str) -> str:
|
||||
"""
|
||||
Generate a PICT model from a JSON configuration file.
|
||||
|
||||
Args:
|
||||
config_file: Path to JSON config file
|
||||
|
||||
Returns:
|
||||
PICT model as string
|
||||
|
||||
Example config.json:
|
||||
{
|
||||
"parameters": {
|
||||
"Browser": ["Chrome", "Firefox", "Safari"],
|
||||
"OS": ["Windows", "MacOS", "Linux"],
|
||||
"Memory": ["4GB", "8GB", "16GB"]
|
||||
},
|
||||
"constraints": [
|
||||
"IF [OS] = \"MacOS\" THEN [Browser] <> \"IE\"",
|
||||
"IF [Memory] = \"4GB\" THEN [OS] <> \"MacOS\""
|
||||
]
|
||||
}
|
||||
"""
|
||||
try:
|
||||
with open(config_file, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
parameters = config.get('parameters', {})
|
||||
constraints = config.get('constraints', [])
|
||||
|
||||
# Generate model
|
||||
model_lines = []
|
||||
model_lines.append("# Generated PICT Model")
|
||||
model_lines.append("")
|
||||
|
||||
# Add parameters
|
||||
for param_name, values in parameters.items():
|
||||
values_str = ", ".join(values)
|
||||
model_lines.append(f"{param_name}: {values_str}")
|
||||
|
||||
# Add constraints
|
||||
if constraints:
|
||||
model_lines.append("")
|
||||
model_lines.append("# Constraints")
|
||||
for constraint in constraints:
|
||||
if not constraint.endswith(';'):
|
||||
constraint += ';'
|
||||
model_lines.append(constraint)
|
||||
|
||||
return "\n".join(model_lines)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error generating model: {e}", file=sys.stderr)
|
||||
return ""
|
||||
|
||||
def format_output(output_file: str) -> str:
|
||||
"""
|
||||
Format PICT output as a markdown table.
|
||||
|
||||
Args:
|
||||
output_file: Path to PICT output file
|
||||
|
||||
Returns:
|
||||
Markdown formatted table
|
||||
"""
|
||||
try:
|
||||
with open(output_file, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
if not lines:
|
||||
return "No output to format"
|
||||
|
||||
# First line is header
|
||||
header = lines[0].strip().split('\t')
|
||||
|
||||
# Create markdown table
|
||||
table = []
|
||||
table.append("| " + " | ".join(header) + " |")
|
||||
table.append("|" + "|".join(["-" * (len(h) + 2) for h in header]) + "|")
|
||||
|
||||
# Add data rows
|
||||
for line in lines[1:]:
|
||||
if line.strip():
|
||||
values = line.strip().split('\t')
|
||||
table.append("| " + " | ".join(values) + " |")
|
||||
|
||||
return "\n".join(table)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error formatting output: {e}", file=sys.stderr)
|
||||
return ""
|
||||
|
||||
def parse_output(output_file: str) -> List[Dict[str, str]]:
|
||||
"""
|
||||
Parse PICT output into a list of dictionaries.
|
||||
|
||||
Args:
|
||||
output_file: Path to PICT output file
|
||||
|
||||
Returns:
|
||||
List of test case dictionaries
|
||||
"""
|
||||
try:
|
||||
with open(output_file, 'r') as f:
|
||||
lines = f.readlines()
|
||||
|
||||
if not lines:
|
||||
return []
|
||||
|
||||
# First line is header
|
||||
header = lines[0].strip().split('\t')
|
||||
|
||||
# Parse data rows
|
||||
test_cases = []
|
||||
for i, line in enumerate(lines[1:], 1):
|
||||
if line.strip():
|
||||
values = line.strip().split('\t')
|
||||
test_case = {"test_id": i}
|
||||
for h, v in zip(header, values):
|
||||
test_case[h] = v
|
||||
test_cases.append(test_case)
|
||||
|
||||
return test_cases
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error parsing output: {e}", file=sys.stderr)
|
||||
return []
|
||||
|
||||
def main():
|
||||
"""Main entry point for the script."""
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage:")
|
||||
print(" python pict_helper.py generate <config.json>")
|
||||
print(" python pict_helper.py format <output.txt>")
|
||||
print(" python pict_helper.py parse <output.txt>")
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1]
|
||||
|
||||
if command == "generate" and len(sys.argv) >= 3:
|
||||
config_file = sys.argv[2]
|
||||
model = generate_model(config_file)
|
||||
print(model)
|
||||
|
||||
elif command == "format" and len(sys.argv) >= 3:
|
||||
output_file = sys.argv[2]
|
||||
table = format_output(output_file)
|
||||
print(table)
|
||||
|
||||
elif command == "parse" and len(sys.argv) >= 3:
|
||||
output_file = sys.argv[2]
|
||||
test_cases = parse_output(output_file)
|
||||
print(json.dumps(test_cases, indent=2))
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {command}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# Example usage:
|
||||
"""
|
||||
# 1. Create a config.json file:
|
||||
{
|
||||
"parameters": {
|
||||
"Browser": ["Chrome", "Firefox", "Safari"],
|
||||
"OS": ["Windows", "MacOS", "Linux"]
|
||||
},
|
||||
"constraints": [
|
||||
"IF [OS] = \"MacOS\" THEN [Browser] <> \"IE\""
|
||||
]
|
||||
}
|
||||
|
||||
# 2. Generate PICT model:
|
||||
python pict_helper.py generate config.json > model.txt
|
||||
|
||||
# 3. Run PICT (if installed):
|
||||
pict model.txt > output.txt
|
||||
|
||||
# 4. Format as markdown:
|
||||
python pict_helper.py format output.txt
|
||||
|
||||
# 5. Parse to JSON:
|
||||
python pict_helper.py parse output.txt
|
||||
"""
|
||||
Reference in New Issue
Block a user