added new tests
Gitea Actions For Tree-Structurer / Explore-Gitea-Actions (push) Successful in 20s
Details
Gitea Actions For Tree-Structurer / Explore-Gitea-Actions (push) Successful in 20s
Details
This commit is contained in:
parent
3765449064
commit
9907388a14
|
@ -1,6 +1,8 @@
|
|||
import pytest
|
||||
from pathlib import Path
|
||||
from prodir import create_tree_structurer, get_structure
|
||||
from prodir import create_tree_structurer, get_structure, create_structure_from_file
|
||||
import re
|
||||
|
||||
|
||||
def test_basic_structure(temp_directory):
|
||||
"""Test that the basic directory structure is correctly represented."""
|
||||
|
@ -87,3 +89,71 @@ def test_nested_structure(temp_directory):
|
|||
# Verify tree-like formatting is present
|
||||
assert any("└" in line or "├" in line for line in structure), \
|
||||
"Tree-like formatting characters not found in structure"
|
||||
|
||||
def test_invalid_indentation_structure(temp_directory):
|
||||
"""Test handling of invalid indentation in the directory structure."""
|
||||
create_tree_structurer()
|
||||
# Create a file with invalid indentation
|
||||
invalid_file_path = temp_directory / "invalid_structure.txt"
|
||||
invalid_content = [
|
||||
"root/",
|
||||
"├── child1/",
|
||||
"│ └── grandchild1",
|
||||
"grandchild2" # Invalid indentation jump
|
||||
]
|
||||
invalid_file_path.write_text("\n".join(invalid_content), encoding='utf-8')
|
||||
|
||||
try:
|
||||
create_structure_from_file(str(invalid_file_path), str(temp_directory))
|
||||
pytest.fail("Expected an exception for invalid indentation")
|
||||
except Exception as e: # Changed from RuntimeError
|
||||
assert "Invalid indentation structure in the file" in str(e)
|
||||
|
||||
def test_create_structure_from_file(temp_directory):
|
||||
"""Test creating a directory structure from a file."""
|
||||
structure_file_path = temp_directory / "valid_structure.txt"
|
||||
valid_content = """
|
||||
project/
|
||||
├── src/
|
||||
│ ├── __init__.py
|
||||
│ ├── main.py
|
||||
│ ├── module1.py
|
||||
│ └── module2.py
|
||||
├── config/
|
||||
│ └── config.yaml
|
||||
├── .gitignore
|
||||
├── pyproject.toml
|
||||
├── setup.py
|
||||
├── LICENSE
|
||||
└── README.md
|
||||
"""
|
||||
structure_file_path.write_text(valid_content, encoding='utf-8')
|
||||
|
||||
# Create the structure
|
||||
target_dir = temp_directory / "project"
|
||||
create_structure_from_file(str(structure_file_path), str(target_dir))
|
||||
|
||||
# Remove the source file
|
||||
structure_file_path.unlink()
|
||||
|
||||
# Define expected structure with proper tree markers
|
||||
expected_structure = [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"config/",
|
||||
"└── config.yaml",
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"src/",
|
||||
"├── __init__.py",
|
||||
"├── main.py",
|
||||
"├── module1.py",
|
||||
"└── module2.py"
|
||||
]
|
||||
|
||||
# Get actual structure
|
||||
actual_structure = get_structure(str(target_dir))
|
||||
|
||||
# Compare the structures
|
||||
assert actual_structure == expected_structure, \
|
||||
f"Expected structure:\n{expected_structure}\n\nGot:\n{actual_structure}"
|
Loading…
Reference in New Issue