Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /analysis /tests /smart /test_visualization.py
| """ | |
| SMART Tests for visualization | |
| Generated by Coverage Agent | |
| Target: 90% Coverage | |
| """ | |
| import ast | |
| from pathlib import Path | |
| import pytest | |
| REPO_ROOT = Path(__file__).parent.parent.parent.parent.parent | |
| MODULE_PATH = REPO_ROOT / "analysis/visualization.py" | |
| def parse_module(): | |
| """Parse the module and return AST""" | |
| with open(MODULE_PATH, "r") as f: | |
| return ast.parse(f.read()) | |
| class TestVisualization: | |
| """Test suite for visualization - targeting 90% coverage""" | |
| def test_module_has_valid_syntax(self): | |
| """Test 1: Module has valid Python syntax""" | |
| try: | |
| tree = parse_module() | |
| assert tree is not None | |
| except SyntaxError: | |
| pytest.fail("Module has syntax errors") | |
| def test_module_has_classes(self): | |
| """Test 2: Module has 1 classes""" | |
| tree = parse_module() | |
| classes = [node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)] | |
| assert len(classes) >= 1, f"Expected at least 1 classes, found {len(classes)}" | |
| def test_module_has_functions(self): | |
| """Test 3: Module has 1 functions""" | |
| tree = parse_module() | |
| functions = [node for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)] | |
| assert len(functions) >= 1, f"Expected at least 1 functions, found {len(functions)}" | |
| def test_module_has_error_handling(self): | |
| """Test 4: Module has error handling (try/except)""" | |
| tree = parse_module() | |
| try_blocks = [node for node in ast.walk(tree) if isinstance(node, ast.Try)] | |
| assert len(try_blocks) >= 0, f"Expected at least 0 try blocks, found {len(try_blocks)}" | |
| def test_module_has_docstrings(self): | |
| """Test 5: Module has docstrings""" | |
| tree = parse_module() | |
| has_docstrings = False | |
| for node in ast.walk(tree): | |
| if isinstance(node, (ast.FunctionDef, ast.ClassDef)): | |
| if ast.get_docstring(node): | |
| has_docstrings = True | |
| break | |
| assert has_docstrings, "Module should have docstrings" | |
| def test_module_has_imports(self): | |
| """Test 6: Module has imports""" | |
| tree = parse_module() | |
| imports = [node for node in ast.walk(tree) if isinstance(node, (ast.Import, ast.ImportFrom))] | |
| assert len(imports) > 0, "Module should have imports" | |
| def test_module_classes_have_methods(self): | |
| """Test 7: Classes have methods""" | |
| tree = parse_module() | |
| classes = [node for node in ast.walk(tree) if isinstance(node, ast.ClassDef)] | |
| for cls in classes: | |
| methods = [n for n in cls.body if isinstance(n, ast.FunctionDef)] | |
| assert len(methods) > 0, f"Class {cls.name} should have methods" | |
| def test_module_has_main_guard(self): | |
| """Test 8: Module has if __name__ == '__main__' guard""" | |
| tree = parse_module() | |
| has_main_guard = False | |
| for node in ast.walk(tree): | |
| if isinstance(node, ast.If): | |
| if isinstance(node.test, ast.Compare): | |
| if isinstance(node.test.left, ast.Name): | |
| if node.test.left.id == "__name__": | |
| has_main_guard = True | |
| break | |
| # Not all modules need this, so just check it exists | |
| pass # Optional check | |
Xet Storage Details
- Size:
- 3.34 kB
- Xet hash:
- 91549d193b4b647d33c819cd88e36317ff24e160722da65acda716f0c6037db9
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.