OpenMC/tests/unit_tests/test_pathlike_simple.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
Python
Raw Permalink Normal View History

"""Simple test for PathLike filename support"""
from pathlib import Path
import pytest
import openmc
from openmc.checkvalue import check_type, PathLike
def test_pathlike_type_checking():
"""Test that PathLike type checking works correctly"""
# Test with string (should work)
check_type('filename', 'test.txt', PathLike)
# Test with Path object (should work)
path_obj = Path('test.txt')
check_type('filename', path_obj, PathLike)
# Test with Path object containing subdirectories (should work)
path_with_subdir = Path('subdir') / 'test.txt'
check_type('filename', path_with_subdir, PathLike)
# Test with invalid type (should raise TypeError)
with pytest.raises(TypeError):
check_type('filename', 123, PathLike)
def test_plot_filename_pathlike():
"""Test that plot filename accepts Path objects"""
plot = openmc.Plot()
# Test with string (should still work)
plot.filename = "test_plot"
assert plot.filename == "test_plot"
# Test with Path object
path_obj = Path("test_plot_path")
plot.filename = path_obj
assert plot.filename == path_obj
# Test with Path object containing subdirectories
path_with_subdir = Path("subdir") / "test_plot"
plot.filename = path_with_subdir
assert plot.filename == path_with_subdir