nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: audreyr/cookiecutter
Pull request #444 (2015-04-21 12:07:22)

Added fix and tests to issue 267
I added a check if the name of the file which should be generated is empty. If so, we do not generate the file and log this behaviour.


Patch:
diff --git a/cookiecutter/generate.py b/cookiecutter/generate.py
index f21c544..5a6aebf 100755
--- a/cookiecutter/generate.py
+++ b/cookiecutter/generate.py
@@ -115,7 +115,13 @@ def generate_file(project_dir, infile, context, env):
 
     # Render the path to the output file (not including the root project dir)
     outfile_tmpl = Template(infile)
+
     outfile = os.path.join(project_dir, outfile_tmpl.render(**context))
+    file_name_is_empty = os.path.isdir(outfile)
+    if file_name_is_empty:
+        logging.debug('The resulting file name is empty: {0}'.format(outfile))
+        return
+
     logging.debug('outfile is {0}'.format(outfile))
 
     # Just copy over binary files. Don't render.


Test patch:
diff --git a/tests/files/{% if generate_file == 'y' %}cheese.txt{% endif %} b/tests/files/{% if generate_file == 'y' %}cheese.txt{% endif %}
new file mode 100644
index 0000000..5f47c92
--- /dev/null
+++ b/tests/files/{% if generate_file == 'y' %}cheese.txt{% endif %}
@@ -0,0 +1,1 @@
+Testing that generate_file was {{ generate_file }}
\ No newline at end of file
diff --git a/tests/test_generate_file.py b/tests/test_generate_file.py
index 33ab611..4632d0b 100644
--- a/tests/test_generate_file.py
+++ b/tests/test_generate_file.py
@@ -54,6 +54,32 @@ def test_generate_file(env):
         assert generated_text == 'Testing cheese'
 
 
+@pytest.mark.usefixtures('remove_cheese_file')
+def test_generate_file_with_false_condition(env):
+    infile = 'tests/files/{% if generate_file == \'y\' %}cheese.txt{% endif %}'
+    generate.generate_file(
+        project_dir=".",
+        infile=infile,
+        context={'generate_file': 'n'},
+        env=env
+    )
+    assert not os.path.exists('tests/files/cheese.txt')
+
+
+@pytest.mark.usefixtures('remove_cheese_file')
+def test_generate_file_with_true_conditional(env):
+    infile = 'tests/files/{% if generate_file == \'y\' %}cheese.txt{% endif %}'
+    generate.generate_file(
+        project_dir=".",
+        infile=infile,
+        context={'generate_file': 'y'},
+        env=env
+    )
+    assert os.path.isfile('tests/files/cheese.txt')
+    with open('tests/files/cheese.txt', 'rt') as f:
+        generated_text = f.read()
+        assert generated_text == 'Testing that generate_file was y'
+
 @pytest.fixture
 def expected_msg():
     msg = (
Repository: audreyr/cookiecutter
Pull request #490 (2015-08-07 11:41:04)

Handle all types of repo, including internal


Patch:
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index a5cde54..b0fa7d5 100755
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -14,6 +14,7 @@ library rather than a script.
 from __future__ import unicode_literals
 import logging
 import os
+import re
 
 from .config import get_user_config
 from .prompt import prompt_for_config
@@ -27,6 +28,20 @@ builtin_abbreviations = {
     'bb': 'https://bitbucket.org/{0}',
 }
 
+REPO_REGEX = """
+(
+(\w+:(//)?)          # something like git:// ssh:// etc.
+ |                   # or
+ (\w+@[\w\.]+)       # something like user@...
+)
+.*
+"""
+
+
+def is_repo_url(value):
+    """Return True if value is a repository URL."""
+    return bool(re.match(REPO_REGEX, value, re.VERBOSE))
+
 
 def expand_abbreviations(template, config_dict):
     """
@@ -70,8 +85,7 @@ def cookiecutter(template, checkout=None, no_input=False, extra_context=None):
 
     template = expand_abbreviations(template, config_dict)
 
-    # TODO: find a better way to tell if it's a repo URL
-    if 'git@' in template or 'https://' in template:
+    if is_repo_url(template):
         repo_dir = clone(
             repo_url=template,
             checkout=checkout,


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
new file mode 100644
index 0000000..34c2b69
--- /dev/null
+++ b/tests/test_main.py
@@ -0,0 +1,13 @@
+from cookiecutter.main import is_repo_url
+
+
+def test_is_repo_url():
+    """Verify is_repo_url works."""
+    assert is_repo_url('gitolite@server:team/repo') is True
+    assert is_repo_url('git@github.com:audreyr/cookiecutter.git') is True
+    assert is_repo_url('https://github.com/audreyr/cookiecutter.git') is True
+    assert is_repo_url('gh:audreyr/cookiecutter-pypackage') is True
+    assert is_repo_url('https://bitbucket.org/pokoli/cookiecutter.hg') is True
+
+    assert is_repo_url('/audreyr/cookiecutter.git') is False
+    assert is_repo_url('/home/audreyr/cookiecutter') is False
Repository: dask/dask
Pull request #6343 (2020-06-23 22:30:23)

Register sizeof for numpy zero-strided arrays
Use code written by jrbourbeau in a private thread. Add tests.
Related to dask/distributed#3180

- [x] Tests added / passed
- [x] Passes `black dask` / `flake8 dask`


cc @jrbourbeau 


Patch:
diff --git a/dask/sizeof.py b/dask/sizeof.py
index a4ac0bddb..c321990bc 100644
--- a/dask/sizeof.py
+++ b/dask/sizeof.py
@@ -83,6 +83,9 @@ def register_numpy():
 
     @sizeof.register(np.ndarray)
     def sizeof_numpy_ndarray(x):
+        if 0 in x.strides:
+            xs = x[tuple(slice(None) if s != 0 else slice(1) for s in x.strides)]
+            return xs.nbytes
         return int(x.nbytes)
 
 


Test patch:
diff --git a/dask/tests/test_sizeof.py b/dask/tests/test_sizeof.py
index 44277db9f..912da2f95 100644
--- a/dask/tests/test_sizeof.py
+++ b/dask/tests/test_sizeof.py
@@ -25,6 +25,12 @@ def test_numpy():
     assert sizeof(dt) == sys.getsizeof(dt)
 
 
+def test_numpy_0_strided():
+    np = pytest.importorskip("numpy")
+    x = np.broadcast_to(1, (100, 100, 100))
+    assert sizeof(x) <= 8
+
+
 def test_pandas():
     pd = pytest.importorskip("pandas")
     df = pd.DataFrame(