Skip to content
Open
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
6 changes: 1 addition & 5 deletions plain_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,7 @@ def plain_file_parser( # noqa: C901
f"Plain syntax error: Invalid plain file extension: {plain_source_file_path.suffix}. Expected: {PLAIN_SOURCE_FILE_EXTENSION}."
)

module_name = (
plain_source_file_path.stem
if plain_source_file_path.is_absolute()
else plain_source_file_path.with_suffix("").as_posix()
)
module_name = plain_source_file_path.stem

code_variables = {}

Expand Down
13 changes: 13 additions & 0 deletions tests/test_plainfileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ def test_regular_plain_source(get_test_data_path):
}


def test_relative_subdirectory_path_resolves(get_test_data_path):
# Regression: the CLI passes the full path as the filename and its directory as template_dirs[0].
# For a relative path with subdirectories, module_name must be the bare stem; otherwise the
# subdirectory prefix double-joins with template_dirs[0] and the module is reported as missing.
data_dir = get_test_data_path("data/plainfileparser")
rel_file = os.path.relpath(os.path.join(data_dir, "regular_plain_source.plain"))
assert os.sep in rel_file # ensure the relative path actually has a subdirectory prefix

module_name, _, _ = plain_file.plain_file_parser(rel_file, [os.path.dirname(rel_file)])

assert module_name == "regular_plain_source"


def test_unknown_section():
plain_source = """
***definitions***
Expand Down
Loading