Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions tests/example_structure/project_summary.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Name,Relative path,Description
fine_mesh,data_cards\fine_mesh.tally,
My transform,data_cards\my_transform.transform,
Ring source,data_cards\ring_source.source,
Main source,data_cards\volumetric_source.source,
Wrong data card,data_cards\wrong_data_card.mat,
Materials BAD,data_cards\materials_bad_library.mat,
Standard materials,data_cards\materials.mat,
Wrong suffix,data_cards\wrong_suffix.wrong,
Model 1,models\filler_model_1.mcnp,
Model 2,models\filler_model_2.mcnp,
Envelope structure,models\main_input.mcnp,
Model 3,models\path_to_be_excluded\filler_model_3.mcnp,
Bad model 1,models\path_to_be_excluded\only_cells_block.mcnp,
Bad model 2,models\path_to_be_excluded\wrong_surfaces_block.mcnp,
Standard configuration,configurations\configuration_1.yml,
fine_mesh,data_cards/fine_mesh.tally,
My transform,data_cards/my_transform.transform,
Ring source,data_cards/ring_source.source,
Main source,data_cards/volumetric_source.source,
Wrong data card,data_cards/wrong_data_card.mat,
Materials BAD,data_cards/materials_bad_library.mat,
Standard materials,data_cards/materials.mat,
Wrong suffix,data_cards/wrong_suffix.wrong,
Model 1,models/filler_model_1.mcnp,
Model 2,models/filler_model_2.mcnp,
Envelope structure,models/main_input.mcnp,
Model 3,models/path_to_be_excluded/filler_model_3.mcnp,
Bad model 1,models/path_to_be_excluded/only_cells_block.mcnp,
Bad model 2,models/path_to_be_excluded/wrong_surfaces_block.mcnp,
Standard configuration,configurations/configuration_1.yml,
2 changes: 1 addition & 1 deletion tests/example_structure/project_summary_path_not_found.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Name,Relative path,Description
My file,data_cards\WRONG.tally,
My file,data_cards/WRONG.tally,
4 changes: 2 additions & 2 deletions tests/example_structure/project_summary_repeated_name.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Name,Relative path,Description
My file,data_cards\fine_mesh.tally,
My file,data_cards\my_transform.transform,
My file,data_cards/fine_mesh.tally,
My file,data_cards/my_transform.transform,
42 changes: 41 additions & 1 deletion tests/test_generate_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path
import tempfile

import pytest

from gitronics.generate_model import generate_model
from gitronics.generate_model import generate_model, _get_envelope_structure_first_cell_id
from gitronics.model_manager import ModelManager

ROOT_FOLDER_PATH = Path(__file__).resolve().parents[1] / "tests" / "example_structure"
PROJECT_SUMMARY_PATH = (
Expand Down Expand Up @@ -79,3 +81,41 @@ def test_envelope_name_not_found_in_envelope_structure(tmpdir):
project_summary_path=PROJECT_SUMMARY_PATH,
write_path=Path(tmpdir),
)


def test_get_envelope_structure_first_cell_id_no_digits():
"""Test _get_envelope_structure_first_cell_id when no line starts with digits."""
# Create a temporary file with content that has no lines starting with digits
content = """C Comment line 1
C Comment line 2
C Another comment
C No cell definitions
C End of file"""

with tempfile.NamedTemporaryFile(mode='w', suffix='.mcnp', delete=False) as tmp_file:
tmp_file.write(content)
tmp_file.flush()

# Create a mock model manager with a project summary that points to our temp file
project_summary = {"test_envelope": Path(tmp_file.name)}

# Create a minimal configuration
class MockConfig:
envelope_structure = "test_envelope"

class MockModelManager:
def __init__(self):
self.project_summary = project_summary
self.configuration = MockConfig()

model_manager = MockModelManager()

# Test that the function raises ValueError when no cell ID is found
with pytest.raises(ValueError, match="Could not find the first cell ID"):
_get_envelope_structure_first_cell_id(model_manager)

# Clean up
Path(tmp_file.name).unlink()