Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing directories #1203

Merged
merged 2 commits into from
Mar 7, 2024
Merged
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
4 changes: 4 additions & 0 deletions src/parser/nmodl_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ std::shared_ptr<ast::Program> NmodlDriver::parse_stream(std::istream& in) {

std::shared_ptr<ast::Program> NmodlDriver::parse_file(const fs::path& filename,
const location* loc) {
if (fs::is_directory(filename)) {
throw std::runtime_error("NMODL Parser Error : path " + filename.string() +
" appears to be a directory, please provide a file instead");
}
std::ifstream in(filename);
if (!in.good()) {
std::ostringstream oss;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/pybind/test_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import nmodl
from pathlib import Path
import pytest


def test_parse_directory():
"""
Make sure we raise an error when parsing a directory instead of a file
"""

with pytest.raises(RuntimeError):
nmodl.NmodlDriver().parse_file(str(Path(__file__).parent))
Loading