nebius/SWE-bench-extra huggingface dataset:
Repository: radiasoft/pykern

Issue:
refactor pkio.walk_tree
This is an example refactoring about local variables.

Comments:

Patch:
diff --git a/pykern/pkio.py b/pykern/pkio.py
index 4eea5f8..4d878dc 100644
--- a/pykern/pkio.py
+++ b/pykern/pkio.py
@@ -285,19 +285,22 @@ def walk_tree(dirname, file_re=None):
     Yields:
         py.path.local: paths in sorted order
     """
-    fr = file_re
-    if fr and not hasattr(fr, 'search'):
-        fr = re.compile(fr)
-    dirname = py_path(dirname).realpath()
-    dn = str(dirname)
+    def _walk(dir_path):
+        for r, _, files in os.walk(str(dir_path), topdown=True, onerror=None, followlinks=False):
+            r = py_path(r)
+            for f in files:
+                yield r.join(f)
+
     res = []
-    for r, d, files in os.walk(dn, topdown=True, onerror=None, followlinks=False):
-        for f in files:
-            p = py_path(r).join(f)
-            if fr and not fr.search(dirname.bestrelpath(p)):
-                continue
-            res.append(p)
-    # Not an iterator, but works as one. Don't assume always will return list
+    d = py_path(dirname)
+    if not file_re:
+        res = list(_walk(d))
+    else:
+        if not hasattr(file_re, 'search'):
+            file_re = re.compile(file_re)
+        for p in _walk(d):
+            if file_re.search(d.bestrelpath(p)):
+                res.append(p)
     return sorted(res)
 
 


Test patch:
diff --git a/tests/pkio_test.py b/tests/pkio_test.py
index d17b4fb..2b7e78f 100644
--- a/tests/pkio_test.py
+++ b/tests/pkio_test.py
@@ -102,6 +102,7 @@ def test_walk_tree_and_sorted_glob():
     """Looks in work_dir"""
     from pykern import pkunit
     from pykern import pkio
+    import re
 
     with pkunit.save_chdir_work() as pwd:
         for f in ('d1/d7', 'd2/d3', 'd4/d5/d6'):
@@ -116,6 +117,8 @@ def test_walk_tree_and_sorted_glob():
             'When walking tree with file_re, should only return matching files'
         assert [expect[0]] == list(pkio.walk_tree('.', '^d1')), \
             'When walking tree with file_re, file to match does not include dir being searched'
+        assert [expect[0]] == list(pkio.walk_tree('.', re.compile('^d1'))), \
+            'When walking tree with file_re, file to match does not include dir being searched'
         assert pkio.sorted_glob('*/*/f*', key='basename') == expect
Repository: radiasoft/pykern

Issue:
pkunit.file_eq always should compare files
Almost always compares objects instead

Comments:

Patch:
diff --git a/pykern/pkunit.py b/pykern/pkunit.py
index c76ac2a..fc72b1b 100644
--- a/pykern/pkunit.py
+++ b/pykern/pkunit.py
@@ -239,12 +239,17 @@ def file_eq(expect_path, *args, **kwargs):
         actual_path = b
     if not isinstance(actual_path, pykern.pkconst.PY_PATH_LOCAL_TYPE):
         actual_path = work_dir().join(actual_path)
-    actual = kwargs['actual'] if a else pkio.read_text(actual_path)
+    if a:
+        actual = kwargs['actual']
+        if actual_path.exists():
+            pkfail('actual={} and actual_path={} both exist', actual, actual_path)
+    else:
+        actual = pkio.read_text(actual_path)
     if expect_path.ext == '.json' and not actual_path.exists():
-        e = pykern.pkjson.load_any(expect_path)
+        e = pkio.read_text(expect_path)
         if a:
             pkio.mkdir_parent_only(actual_path)
-            pykern.pkjson.dump_pretty(actual, filename=actual_path)
+            actual = pykern.pkjson.dump_pretty(actual, filename=actual_path)
     else:
         if j:
             import pykern.pkjinja


Test patch:
diff --git a/tests/pkunit_data/file_eq1.json b/tests/pkunit_data/file_eq1.json
new file mode 100644
index 0000000..7326da5
--- /dev/null
+++ b/tests/pkunit_data/file_eq1.json
@@ -0,0 +1,1 @@
+"array('d', [1.0])"
diff --git a/tests/pkunit_data/file_eq2.txt b/tests/pkunit_data/file_eq2.txt
new file mode 100644
index 0000000..e69de29
diff --git a/tests/pkunit_data/file_eq3.txt b/tests/pkunit_data/file_eq3.txt
new file mode 100644
index 0000000..339f0be
--- /dev/null
+++ b/tests/pkunit_data/file_eq3.txt
@@ -0,0 +1,1 @@
+something else
\ No newline at end of file
diff --git a/tests/pkunit_test.py b/tests/pkunit_test.py
index 31acebb..40b0b6e 100644
--- a/tests/pkunit_test.py
+++ b/tests/pkunit_test.py
@@ -5,6 +5,9 @@ u"""PyTest for :mod:`pykern.pkunit`
 :license: http://www.apache.org/licenses/LICENSE-2.0.html
 """
 from __future__ import absolute_import, division, print_function
+import pkgutil
+
+import py
 import pytest
 
 def test_assert_object_with_json():
@@ -55,6 +58,22 @@ def test_empty_work_dir():
         'Ensure directory was created'
 
 
+def test_file_eq():
+    import array
+    import pykern.pkunit
+    import pykern.pkio
+
+    a = array.ArrayType('d', [1])
+    pykern.pkunit.file_eq('file_eq1.json', actual=a)
+
+    with pykern.pkunit.pkexcept(TypeError):
+        pykern.pkunit.file_eq('file_eq2.txt', actual=dict())
+    d = pykern.pkunit.empty_work_dir()
+    pykern.pkio.write_text(d.join('file_eq3.txt'), 'something')
+    with pykern.pkunit.pkexcept('both exist'):
+        pykern.pkunit.file_eq('file_eq3.txt', actual='something else')
+
+
 def test_import_module_from_data_dir(monkeypatch):
     from pykern import pkunit
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.

Comments:

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
Repository: randsleadershipslack/destalinator

Issue:
List Configs Don't Work When Using Environment Variables
Using a config like `ignore_channel_patterns` through the environment variable `DESTALINATOR_IGNORE_CHANNEL_PATTERNS=^auto-` causes everything to be ignored. The string pattern is not casted into a list properly and causes unexpected behavior. If there's a better env var syntax for this to work out of the box we should update docs, otherwise we'll need to code in a solution or not support env vars for list properties.

Comments:

Patch:
diff --git a/README.md b/README.md
index f5f8da1..90af60d 100644
--- a/README.md
+++ b/README.md
@@ -72,7 +72,7 @@ These channels need to be manually created by you in your Slack.
 
 ### Environment variables
 
-All configs in `configuration.yaml` are overrideable through environment variables with the same name prefixed by `DESTALINATOR_` (e.g. `activated` -> `DESTALINATOR_ACTIVATED`). Set array environment variables (e.g. `DESTALINATOR_IGNORE_CHANNELS`) by comma delimiting items
+All configs in `configuration.yaml` are overrideable through environment variables with the same name prefixed by `DESTALINATOR_` (e.g. `activated` -> `DESTALINATOR_ACTIVATED`). Set array environment variables (e.g. `DESTALINATOR_IGNORE_CHANNELS`) by comma delimiting items. If you only have one value for an array type environment variable add a training comma to denote the variable as a list.
 
 #### `DESTALINATOR_SB_TOKEN` (Required)
 
diff --git a/config.py b/config.py
index 364b3f6..d65d811 100644
--- a/config.py
+++ b/config.py
@@ -25,7 +25,7 @@ class Config(WithLogger):
         else:
             envvar = os.getenv('DESTALINATOR_' + upper_attrname)
         if envvar is not None:
-            return envvar.split(',') if ',' in envvar else envvar
+            return [x for x in envvar.split(',') if x] if ',' in envvar else envvar
 
         return self.config.get(attrname, '')
 


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
new file mode 100644
index 0000000..e9c88c0
--- /dev/null
+++ b/tests/test_config.py
@@ -0,0 +1,14 @@
+import os
+import unittest
+
+from config import get_config
+
+
+class ConfigTest(unittest.TestCase):
+    def setUp(self):
+        os.environ['DESTALINATOR_STRING_VARIABLE'] = 'test'
+        os.environ['DESTALINATOR_LIST_VARIABLE'] = 'test,'
+
+    def test_environment_variable_configs(self):
+        self.assertEqual(get_config().string_variable, 'test')
+        self.assertListEqual(get_config().list_variable, ['test'])