@@ -151,34 +151,26 @@ def test_get_sql_files_empty() -> None:
151151 assert sql_spec .get_sql_files () == []
152152
153153
154- def test_load_sql_files () -> None :
155- """Test loading SQL files from a directory."""
156- sql_spec = SQLSpec ()
157-
158- with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".sql" , delete = False ) as tf :
159- tf .write ("""
160- -- name: test_query
161- SELECT id, name FROM users WHERE active = true;
162-
163- -- name: count_users
164- SELECT COUNT(*) as total FROM users;
154+ def test_load_sql_files_accepts_file_and_directory_paths (tmp_path : Path ) -> None :
155+ """Regression test for bug #374: load_sql_files accepts file and directory inputs."""
156+ sql_file = tmp_path / "hello.sql"
157+ sql_file .write_text ("""
158+ -- name: hello_world
159+ SELECT 'Hello, World!' as greeting;
165160""" )
166- tf .flush ()
167- temp_path = Path (tf .name )
168161
169- try :
170- sql_spec .load_sql_files (temp_path )
162+ for path in (sql_file , str (sql_file ), tmp_path , str (tmp_path )):
163+ sql_spec = SQLSpec ()
164+
165+ sql_spec .load_sql_files (path )
171166
172167 queries = sql_spec .list_sql_queries ()
173- assert "test_query " in queries
174- assert "count_users" in queries
168+ assert "hello_world " in queries
169+ assert sql_spec . get_sql_files () == [ str ( sql_file )]
175170
176- test_sql = sql_spec .get_sql ("test_query " )
171+ test_sql = sql_spec .get_sql ("hello_world " )
177172 assert isinstance (test_sql , SQL )
178- assert "SELECT id, name FROM users" in test_sql .sql
179-
180- finally :
181- temp_path .unlink ()
173+ assert "SELECT 'Hello, World!'" in test_sql .sql
182174
183175
184176def test_provided_loader_is_used () -> None :
0 commit comments