Repository: radiasoft/pykern

Issue:
pkunit.case_dirs should detect no files and fail
If case_dirs doesn't generate any files, it should pkfail with a message about the prefix not generating any files. There should be at least one output file, too.

Discussion:

Patch:
diff --git a/pykern/pkunit.py b/pykern/pkunit.py
index 4c758b8..5b26817 100644
--- a/pykern/pkunit.py
+++ b/pykern/pkunit.py
@@ -168,9 +168,11 @@ def case_dirs(group_prefix="", ignore_lines=None):
             file_eq(expect_path=e, actual_path=a, ignore_lines=ignore_lines)
 
     d = work_dir()
+    n = 0
     for i in pkio.sorted_glob(data_dir().join(group_prefix + "*.in")):
         w = d.join(i.purebasename)
         shutil.copytree(str(i), str(w))
+        n += 1
         with pkio.save_chdir(w):
             yield w
         try:
@@ -188,6 +190,8 @@ def case_dirs(group_prefix="", ignore_lines=None):
             _pkdlog("Exception in case_dir={}\n{}", w, f.read())
         # This avoids confusing "during handling of above exception"
         pkfail("See stack above")
+    if n == 0:
+        pkfail(f"No files found for group_prefix={group_prefix}")
 
 
 def data_dir():


Test patch:
diff --git a/tests/pkunit1_test.py b/tests/pkunit1_test.py
index 417a0f4..8386381 100644
--- a/tests/pkunit1_test.py
+++ b/tests/pkunit1_test.py
@@ -33,3 +33,11 @@ def test_case_dirs_curly_brackets():
     with pkunit.pkexcept("1c1\n< expected\n---\n> {unexpected}"):
         for d in pkunit.case_dirs(group_prefix="curly_brackets"):
             pass
+
+
+def test_no_files():
+    from pykern import pkunit
+
+    with pkunit.pkexcept("no files found"):
+        for d in pkunit.case_dirs(group_prefix="no_files"):
+            continue