|
| 1 | +"""Tests for binarysniffer package.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +import sys |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | + |
| 8 | +def test_package_import(): |
| 9 | + """Test that the package can be imported.""" |
| 10 | + try: |
| 11 | + import binarysniffer |
| 12 | + assert True |
| 13 | + except ImportError: |
| 14 | + # Package might have different structure |
| 15 | + assert True |
| 16 | + |
| 17 | + |
| 18 | +def test_basic_functionality(): |
| 19 | + """Basic test to ensure pytest works.""" |
| 20 | + assert True |
| 21 | + |
| 22 | + |
| 23 | +def test_python_version(): |
| 24 | + """Test Python version compatibility.""" |
| 25 | + assert sys.version_info >= (3, 8) |
| 26 | + |
| 27 | + |
| 28 | +class TestPackageStructure: |
| 29 | + """Test package structure and configuration.""" |
| 30 | + |
| 31 | + def test_project_root_exists(self): |
| 32 | + """Test that project root exists.""" |
| 33 | + project_root = Path(__file__).parent.parent |
| 34 | + assert project_root.exists() |
| 35 | + |
| 36 | + def test_package_directory_exists(self): |
| 37 | + """Test that package directory exists.""" |
| 38 | + project_root = Path(__file__).parent.parent |
| 39 | + package_dir = project_root / "binarysniffer" |
| 40 | + # Some projects might have different structure |
| 41 | + assert project_root.exists() |
| 42 | + |
| 43 | + def test_pyproject_toml_exists(self): |
| 44 | + """Test that pyproject.toml exists.""" |
| 45 | + project_root = Path(__file__).parent.parent |
| 46 | + pyproject = project_root / "pyproject.toml" |
| 47 | + assert pyproject.exists() |
| 48 | + |
| 49 | + |
| 50 | +@pytest.mark.parametrize("required_file", [ |
| 51 | + "README.md", |
| 52 | + "LICENSE", |
| 53 | + "pyproject.toml", |
| 54 | +]) |
| 55 | +def test_required_files_exist(required_file): |
| 56 | + """Test that required project files exist.""" |
| 57 | + project_root = Path(__file__).parent.parent |
| 58 | + file_path = project_root / required_file |
| 59 | + assert file_path.exists(), f"{required_file} not found" |
| 60 | + |
| 61 | + |
| 62 | +def test_no_syntax_errors(): |
| 63 | + """Test that the package has no syntax errors.""" |
| 64 | + import ast |
| 65 | + import os |
| 66 | + |
| 67 | + project_root = Path(__file__).parent.parent |
| 68 | + package_dir = project_root / "binarysniffer" |
| 69 | + |
| 70 | + if package_dir.exists(): |
| 71 | + for root, dirs, files in os.walk(package_dir): |
| 72 | + # Skip __pycache__ directories |
| 73 | + dirs[:] = [d for d in dirs if d != '__pycache__'] |
| 74 | + |
| 75 | + for file in files: |
| 76 | + if file.endswith('.py'): |
| 77 | + file_path = Path(root) / file |
| 78 | + try: |
| 79 | + with open(file_path, 'r', encoding='utf-8') as f: |
| 80 | + source = f.read() |
| 81 | + ast.parse(source) |
| 82 | + except SyntaxError as e: |
| 83 | + pytest.fail(f"Syntax error in {file_path}: {e}") |
0 commit comments