nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cogent3/cogent3
Pull request #2253 (2025-03-19 06:21:30)

BUG: fix regression from change to numpy element representation
[FIXED] repr() of numpy elements now prefixed by `np.<type>_`.
    This screws up display of some table columns. Fixed by
    assigning column templates.

## Summary by Sourcery

Bug Fixes:
- Fixes a regression where the repr() of numpy elements was prefixed by `np.<type>_`, causing incorrect display of some table columns.


Patch:
diff --git a/src/cogent3/core/moltype.py b/src/cogent3/core/moltype.py
index 7b7ca5ba8..0d3c8f66a 100644
--- a/src/cogent3/core/moltype.py
+++ b/src/cogent3/core/moltype.py
@@ -1565,7 +1565,7 @@ def available_moltypes():
 
     result = Table(header=header, data=rows, title=title, index_name="Abbreviation")
     result = result.sorted(columns=["Number of states", "Abbreviation"])
-    result.format_column("Abbreviation", repr)
+    result.format_column("Abbreviation", lambda x: repr(str(x)))
     return result
 
 
diff --git a/src/cogent3/core/new_moltype.py b/src/cogent3/core/new_moltype.py
index cf2b46f76..a59a6faac 100644
--- a/src/cogent3/core/new_moltype.py
+++ b/src/cogent3/core/new_moltype.py
@@ -1440,9 +1440,8 @@ def available_moltypes():
     title = "Specify a moltype by the Abbreviation (case insensitive)."
 
     result = Table(header=header, data=rows, title=title, index_name="Abbreviation")
-    result = result.sorted(columns=["Number of states", "Abbreviation"])
-    result.format_column("Abbreviation", repr)
-    return result
+    result.format_column("Abbreviation", lambda x: repr(str(x)))
+    return result.sorted(columns=["Number of states", "Abbreviation"])
 
 
 # constant instances of the core molecular types
diff --git a/src/cogent3/util/table.py b/src/cogent3/util/table.py
index bb65a5161..95de80a00 100644
--- a/src/cogent3/util/table.py
+++ b/src/cogent3/util/table.py
@@ -780,7 +780,9 @@ class Table:
         return "\n".join(html)
 
     def _get_persistent_attrs(self):
-        return UnionDict(self._persistent_attrs.copy())
+        attrs = self._persistent_attrs.copy()
+        attrs["column_templates"] = self._column_templates
+        return UnionDict(**attrs)
 
     @property
     def title(self):


Test patch:
diff --git a/tests/test_core/test_new_moltype.py b/tests/test_core/test_new_moltype.py
index 1c3a78601..ced2381a2 100644
--- a/tests/test_core/test_new_moltype.py
+++ b/tests/test_core/test_new_moltype.py
@@ -69,6 +69,9 @@ def test_get_moltype(name):
 def test_available_moltypes():
     t = new_moltype.available_moltypes()
     assert t.shape[0] == 6
+    got = str(t)
+    assert "np." not in got
+    assert "'dna'" in got
 
 
 def test_str_moltype():
Repository: audreyr/cookiecutter
Pull request #532 (2015-09-26 17:30:13)

Fix is repo url for win path
This PR changes the regex for ``is_repo_url`` as local windows paths seemed to be mistaken for remote urls, see #531. :cry: 

https://ci.appveyor.com/project/audreyr/cookiecutter/build/1.0.656/job/9vjf6xlxxx4sfvj4


Patch:
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index 14b1e65..604418a 100755
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -32,9 +32,9 @@ builtin_abbreviations = {
 
 REPO_REGEX = """
 (
-(\w+:(//)?)          # something like git:// ssh:// etc.
- |                   # or
- (\w+@[\w\.]+)       # something like user@...
+((git|ssh|https|http):(//)?)    # something like git:// ssh:// etc.
+ |                              # or
+ (\w+@[\w\.]+)                  # something like user@...
 )
 .*
 """


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index 34c2b69..613e0e9 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,4 +1,4 @@
-from cookiecutter.main import is_repo_url
+from cookiecutter.main import is_repo_url, expand_abbreviations
 
 
 def test_is_repo_url():
@@ -6,8 +6,24 @@ def test_is_repo_url():
     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
+
+    appveyor_temp_dir = (
+        'c:\\users\\appveyor\\appdata\\local\\temp\\1\\pytest-0\\'
+        'test_default_output_dir0\\template'
+    )
+    assert is_repo_url(appveyor_temp_dir) is False
+
+
+def test_expand_abbreviations():
+    template = 'gh:audreyr/cookiecutter-pypackage'
+
+    # This is not a valid repo url just yet!
+    # First `main.expand_abbreviations` needs to translate it
+    assert is_repo_url(template) is False
+
+    expanded_template = expand_abbreviations(template, {})
+    assert is_repo_url(expanded_template) is True
Repository: audreyr/cookiecutter
Pull request #553 (2015-10-11 21:18:29)

Return rendered project dir
This PR changes ``generate_files`` to return the rendered project directory instead of None.

By doing this we *(I am working on best-practices for template testing atm :squirrel:)* enable a caller to write tests in a convenient and yet simple way with minimal changes to **Cookiecutter** itself.

Please let me know your thoughts! :bow: 


Patch:
diff --git a/cookiecutter/generate.py b/cookiecutter/generate.py
index 30e9b8d..94e6e94 100755
--- a/cookiecutter/generate.py
+++ b/cookiecutter/generate.py
@@ -316,3 +316,5 @@ def generate_files(repo_dir, context=None, output_dir='.',
     # run post-gen hook from repo_dir
     with work_in(repo_dir):
         run_hook('post_gen_project', project_dir, context)
+
+    return project_dir
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index 2e21103..eae455b 100755
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -131,7 +131,7 @@ def cookiecutter(
         dump(template_name, context)
 
     # Create project from local context and project template.
-    generate_files(
+    return generate_files(
         repo_dir=repo_dir,
         context=context,
         overwrite_if_exists=overwrite_if_exists,


Test patch:
diff --git a/tests/test_cookiecutter_local_no_input.py b/tests/test_cookiecutter_local_no_input.py
index cc4a020..6f02b87 100644
--- a/tests/test_cookiecutter_local_no_input.py
+++ b/tests/test_cookiecutter_local_no_input.py
@@ -74,3 +74,10 @@ def test_cookiecutter_templated_context():
         no_input=True
     )
     assert os.path.isdir('fake-project-templated')
+
+
+@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
+def test_cookiecutter_no_input_return_project_dir():
+    """Call `cookiecutter()` with `no_input=True`."""
+    project_dir = main.cookiecutter('tests/fake-repo-pre', no_input=True)
+    assert project_dir == os.path.abspath('fake-project')
diff --git a/tests/test_generate_files.py b/tests/test_generate_files.py
index 85142ce..f75b0db 100644
--- a/tests/test_generate_files.py
+++ b/tests/test_generate_files.py
@@ -149,6 +149,21 @@ def test_generate_files_output_dir():
     assert os.path.isfile('tests/custom_output_dir/inputpizzä/simple.txt')
 
 
+@pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
+def test_return_rendered_project_dir():
+    os.mkdir('tests/custom_output_dir')
+    project_dir = generate.generate_files(
+        context={
+            'cookiecutter': {'food': 'pizzä'}
+        },
+        repo_dir=os.path.abspath('tests/test-generate-files'),
+        output_dir='tests/custom_output_dir'
+    )
+    assert project_dir == os.path.abspath(
+        'tests/custom_output_dir/inputpizzä/'
+    )
+
+
 @pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
 def test_generate_files_permissions():
     """
Repository: audreyr/cookiecutter
Pull request #655 (2016-03-18 23:03:46)

Fix repo urls
Resolve #595 and add tests :smile_cat: 

Let's get this in #610 


Patch:
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index 56dbc5e..d8ff7b6 100755
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -30,19 +30,18 @@ builtin_abbreviations = {
     'bb': 'https://bitbucket.org/{0}',
 }
 
-REPO_REGEX = """
-(
-((git|ssh|https|http):(//)?)    # something like git:// ssh:// etc.
- |                              # or
- (\w+@[\w\.]+)                  # something like user@...
+REPO_REGEX = re.compile(r"""
+(?x)
+((((git|hg)\+)?(git|ssh|https?):(//)?)  # 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))
+    return bool(REPO_REGEX.match(value))
 
 
 def expand_abbreviations(template, config_dict):


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
index 613e0e9..c7d08ea 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,21 +1,42 @@
+# -*- coding: utf-8 -*-
+
+import pytest
+
 from cookiecutter.main import is_repo_url, expand_abbreviations
 
 
-def test_is_repo_url():
+@pytest.fixture(params=[
+    'gitolite@server:team/repo',
+    'git@github.com:audreyr/cookiecutter.git',
+    'https://github.com/audreyr/cookiecutter.git',
+    'git+https://private.com/gitrepo',
+    'hg+https://private.com/mercurialrepo',
+    'https://bitbucket.org/pokoli/cookiecutter.hg',
+])
+def remote_repo_url(request):
+    return request.param
+
+
+def test_is_repo_url_for_remote_urls(remote_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('https://bitbucket.org/pokoli/cookiecutter.hg') is True
+    assert is_repo_url(remote_repo_url) is True
 
-    assert is_repo_url('/audreyr/cookiecutter.git') is False
-    assert is_repo_url('/home/audreyr/cookiecutter') is False
 
-    appveyor_temp_dir = (
+@pytest.fixture(params=[
+    '/audreyr/cookiecutter.git',
+    '/home/audreyr/cookiecutter',
+    (
         'c:\\users\\appveyor\\appdata\\local\\temp\\1\\pytest-0\\'
         'test_default_output_dir0\\template'
-    )
-    assert is_repo_url(appveyor_temp_dir) is False
+    ),
+])
+def local_repo_url(request):
+    return request.param
+
+
+def test_is_repo_url_for_local_urls(local_repo_url):
+    """Verify is_repo_url works."""
+    assert is_repo_url(local_repo_url) is False
 
 
 def test_expand_abbreviations():
Repository: audreyr/cookiecutter
Pull request #774 (2016-07-05 12:57:43)

Include template directory or url in the context dictionary
This is one use case: Have a make target in the rendered project that
pulls changes from the template source, renders the up-to-date template
with the same context used to create the project, and then merges the
changes back into the rendered project.


aroig: By the way, I'm not sure why travis tests fail. If you accept merging something like this, I can fix any test that needs fixing and add documentation or an entry in history.

Patch:
diff --git a/cookiecutter/main.py b/cookiecutter/main.py
index 5a15ba4..88edeb9 100644
--- a/cookiecutter/main.py
+++ b/cookiecutter/main.py
@@ -79,6 +79,9 @@ def cookiecutter(
         # except when 'no-input' flag is set
         context['cookiecutter'] = prompt_for_config(context, no_input)
 
+        # include template dir or url in the context dict
+        context['cookiecutter']['_template'] = template
+
         dump(config_dict['replay_dir'], template_name, context)
 
     # Create project from local context and project template.


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 9d0cdef..aee9f0d 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -325,7 +325,8 @@ def test_echo_undefined_variable_error(tmpdir, cli_runner):
     context = {
         'cookiecutter': {
             'github_username': 'hackebrot',
-            'project_slug': 'testproject'
+            'project_slug': 'testproject',
+            '_template': template_path
         }
     }
     context_str = json.dumps(context, indent=4, sort_keys=True)