|
13 | 13 | from montepy.input_parser.shortcuts import Shortcuts |
14 | 14 | from montepy.input_parser import syntax_node |
15 | 15 | from montepy.particle import Particle |
| 16 | +from montepy.exceptions import UndefinedBlock |
16 | 17 | import warnings |
17 | 18 |
|
18 | 19 |
|
@@ -1472,6 +1473,33 @@ def test_jump_and_a_hop(self): |
1472 | 1473 | str(jump) |
1473 | 1474 | repr(jump) |
1474 | 1475 |
|
| 1476 | + def test_extra_block_warning(self): |
| 1477 | + # Define constants for better readability and maintainability |
| 1478 | + INPUT_FILE = "tests/inputs/test_pin_cell_extra_block_warning.imcnp" |
| 1479 | + EXPECTED_LINE = 34 |
| 1480 | + EXPECTED_CONTENT = "M101 92235.80c 0.04\n 92238.80c 0.96\n" |
| 1481 | + EXPECTED_WARNING_TYPE = UndefinedBlock |
| 1482 | + |
| 1483 | + # Setup: Use the common pattern for defining the generator |
| 1484 | + generator = input_syntax_reader.read_input_syntax(MCNP_InputFile(INPUT_FILE)) |
| 1485 | + |
| 1486 | + # Check that the expected warning is raised |
| 1487 | + with pytest.warns(EXPECTED_WARNING_TYPE) as recs: |
| 1488 | + # Exhaust generator so parser runs and warnings are emitted |
| 1489 | + for _ in generator: |
| 1490 | + pass |
| 1491 | + |
| 1492 | + # Assertions |
| 1493 | + assert len(recs) == 1, f"Expected exactly one warning, but got {len(recs)}" |
| 1494 | + warning = recs[0] |
| 1495 | + assert issubclass( |
| 1496 | + warning.category, EXPECTED_WARNING_TYPE |
| 1497 | + ), f"Expected warning type {EXPECTED_WARNING_TYPE}, but got {warning.category}" |
| 1498 | + assert ( |
| 1499 | + str(warning.message) |
| 1500 | + == f"Unexpected input after line {EXPECTED_LINE}\n line content: {EXPECTED_CONTENT}" |
| 1501 | + ), f"Expected warning message 'Unexpected input after line {EXPECTED_LINE}\n line content: {EXPECTED_CONTENT}', but got '{str(warning.message)}'" |
| 1502 | + |
1475 | 1503 |
|
1476 | 1504 | class TestClassifierNode: |
1477 | 1505 | def test_classifier_init(self): |
|
0 commit comments