nebius/SWE-bench-extra huggingface dataset:
Repository: closeio/freezefrog

Issue:
FreezeFrog should also mock datetime.datetime.now
FreezeFrog should raise an exception when datetime.datetime.now() is used without a TZ instead of not mocking it at all.


Comments:

Patch:
diff --git a/freezefrog/__init__.py b/freezefrog/__init__.py
index 44a232a..60463f3 100644
--- a/freezefrog/__init__.py
+++ b/freezefrog/__init__.py
@@ -47,6 +47,12 @@ class FakeDateTime(with_metaclass(FakeDateTimeMeta, real_datetime)):
             cls._start = real_datetime.utcnow()
         return (real_datetime.utcnow() - cls._start) + cls.dt
 
+    @classmethod
+    def now(cls, *args, **kwargs):
+        raise NotImplementedError(
+            '{}.now() is not implemented yet'.format(cls.__name__)
+        )
+
 
 class FakeFixedDateTime(FakeDateTime):
     @classmethod


Test patch:
diff --git a/tests/__init__.py b/tests/__init__.py
index dd74be2..093fc1c 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -27,3 +27,9 @@ class FreezeFrogTestCase(unittest.TestCase):
             end = datetime.datetime(2014, 1, 1, 0, 0, 1)
             self.assertTrue(start < dt < end)
             self.assertTrue(1388534400 < time.time() < 1388534401)
+
+    def test_now(self):
+        regular_now = datetime.datetime.now()
+        self.assertTrue(regular_now)
+        with FreezeTime(datetime.datetime(2014, 1, 1)):
+            self.assertRaises(NotImplementedError, datetime.datetime.now)
Repository: closeio/limitlion

Issue:
Consider not setting defaults in Redis
This line can probably be removed so that the defaults used in Python would always be used unless the Redis `:knobs` key was created. Can't think of a reason that the defaults need to exist in Redis.

https://github.com/closeio/limitlion/blob/e6705996a2ee5ea87779689feb2e42d084424268/limitlion/throttle.lua#L112

Comments:

Patch:
diff --git a/limitlion/throttle.lua b/limitlion/throttle.lua
index f2aa58c..201832d 100644
--- a/limitlion/throttle.lua
+++ b/limitlion/throttle.lua
@@ -106,10 +106,12 @@ local window
 
 -- Lookup throttle knob settings
 local knobs_key = name .. ":knobs"
+-- Use
+--   HMSET <knobs_key> rps <rps> burst <burst> window <window>
+-- to manually override the setting for any throttle.
 local knobs = redis.call("HMGET", knobs_key, "rps", "burst", "window")
 if knobs[1] == false then
   -- Set defaults if knobs hash is not found
-  redis.call("HMSET", knobs_key, "rps", default_rps, "burst", default_burst, "window", default_window)
   rps = tonumber(default_rps)
   burst = tonumber(default_burst)
   window = tonumber(default_window)


Test patch:
diff --git a/tests/test_throttle.py b/tests/test_throttle.py
index fe85319..8d89ad0 100644
--- a/tests/test_throttle.py
+++ b/tests/test_throttle.py
@@ -278,7 +278,8 @@ class TestThrottle():
 
         self._freeze_redis_time(start_time, 0)
 
-        self._fake_work(throttle_name, 5, 2, 6)
+        limitlion.throttle_set(throttle_name, 5, 2, 6)
+        self._fake_work(throttle_name)
         tokens, refreshed, rps, burst, window = \
             limitlion.throttle_get(throttle_name)
         assert int(tokens) == 59
Repository: cloudinary/pycloudinary

Issue:
Using unicode literals in config causes UnicodeDecodeError on upload
If the `CLOUDINARY` settings are defined in a python file which uses unicode literals (or if the `cloud_name` is defined as a unicode literal manually) there is an error thrown deep down inside `httplib.py`. The reason for this is that `cloudinary_api_url` joins together all of the url parts which, if one of these elements is unicode, generates a URL which is a unicode string.

```
In [1]: "/".join(('non-unicode', u'unicode'))
Out[1]: u'non-unicode/unicode'
```

There was a python bug raised for this here https://bugs.python.org/issue11898 but it looks like it was treated as an invalid input. I guess you could say the same thing here and that passing a unicode string is undefined behaviour but at least this bug might help someone else with this problem.

Comments:

Patch:
diff --git a/cloudinary/utils.py b/cloudinary/utils.py
index bf4cac4..a112aa6 100644
--- a/cloudinary/utils.py
+++ b/cloudinary/utils.py
@@ -8,6 +8,7 @@ import re
 import string
 import struct
 import time
+import urllib
 import zlib
 from collections import OrderedDict
 from datetime import datetime, date
@@ -557,7 +558,8 @@ def cloudinary_api_url(action='upload', **options):
     if not cloud_name:
         raise ValueError("Must supply cloud_name")
     resource_type = options.get("resource_type", "image")
-    return "/".join([cloudinary_prefix, "v1_1", cloud_name, resource_type, action])
+
+    return encode_unicode_url("/".join([cloudinary_prefix, "v1_1", cloud_name, resource_type, action]))
 
 
 def smart_escape(source, unsafe=r"([^a-zA-Z0-9_.\-\/:]+)"):
@@ -962,6 +964,20 @@ def base64_encode_url(url):
     return b64.decode('ascii')
 
 
+def encode_unicode_url(url_str):
+    """
+    Quote and encode possible unicode url string (applicable for python2)
+
+    :param url_str: Url string to encode
+
+    :return: Encoded string
+    """
+    if six.PY2:
+        url_str = urllib.quote(url_str.encode('utf-8'), ":/?#[]@!$&'()*+,;=")
+
+    return url_str
+
+
 def __json_serializer(obj):
     """JSON serializer for objects not serializable by default json code"""
     if isinstance(obj, (datetime, date)):


Test patch:
diff --git a/test/test_utils.py b/test/test_utils.py
index 591cbab..ccb82fc 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -10,7 +10,7 @@ import six
 from mock import patch
 
 import cloudinary.utils
-from cloudinary.utils import build_list_of_dicts, json_encode
+from cloudinary.utils import build_list_of_dicts, json_encode, encode_unicode_url
 from test.helper_test import TEST_IMAGE, REMOTE_TEST_IMAGE
 
 
@@ -816,6 +816,10 @@ class TestUtils(unittest.TestCase):
             json_encode({"t": self})
         self.assertIn("is not JSON serializable", str(te.exception))
 
+    def test_encode_unicode_url(self):
+        self.assertEqual("string", encode_unicode_url("string"))
+        self.assertEqual("encoded", encode_unicode_url(u"encoded"))
+
     def test_is_remote_url(self):
         self.assertFalse(cloudinary.utils.is_remote_url(TEST_IMAGE))
         self.assertTrue(cloudinary.utils.is_remote_url(REMOTE_TEST_IMAGE))