diff --git a/testmon/testmon_core.py b/testmon/testmon_core.py index 7d8b7e6..6603d87 100644 --- a/testmon/testmon_core.py +++ b/testmon/testmon_core.py @@ -90,7 +90,7 @@ def get_file(self, filename): self.cache[filename] = Module( source_code=code, mtime=fs_mtime, - ext=filename.rsplit(".", 1)[1], + ext=filename.rsplit(".", 1)[1] if "." in filename else "", fs_fsha=fsha, filename=filename, rootdir=self.rootdir, diff --git a/tests/test_process_code.py b/tests/test_process_code.py index 6238fcb..43bd887 100644 --- a/tests/test_process_code.py +++ b/tests/test_process_code.py @@ -497,3 +497,16 @@ def test_noncached_get_files_shas(testdir): testdir.run("git", "commit", "-m", "Initial commit") assert isinstance(noncached_get_files_shas(testdir.tmpdir.strpath), dict) + + +def test_get_file_extensionless(tmp_path): + """Test that SourceTree.get_file handles files without extensions.""" + extensionless = tmp_path / "Dockerfile" + extensionless.write_text("FROM python:3.10\n") + + source_tree = SourceTree(str(tmp_path)) + module = source_tree.get_file("Dockerfile") + + assert module is not None + assert module.ext == "" + assert len(module.blocks) == 1