nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: FactoryBoy/factory_boy
Pull request #708 (2020-03-03 01:23:51)

Restore original logging state on exception in factory.debug()


Patch:
diff --git a/Makefile b/Makefile
index 5dc4a9a..ef54a98 100644
--- a/Makefile
+++ b/Makefile
@@ -57,14 +57,12 @@ test:
 	python \
 		-b \
 		-Werror \
-		-Wdefault:"'U' mode is deprecated":DeprecationWarning:site: \
 		-Wdefault:"the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses":DeprecationWarning:distutils: \
 		-Wdefault:"the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses":PendingDeprecationWarning:distutils: \
 		-Wdefault:"Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working":DeprecationWarning:: \
 		-Wdefault:"Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working":DeprecationWarning:: \
 		-Wdefault:"set_output_charset() is deprecated":DeprecationWarning:: \
 		-Wdefault:"parameter codeset is deprecated":DeprecationWarning:: \
-		-Wdefault:"PY_SSIZE_T_CLEAN will be required for '#' formats":DeprecationWarning:: \
 		-m unittest discover
 
 # DOC: Test the examples
diff --git a/factory/helpers.py b/factory/helpers.py
index 01866ec..5433b31 100644
--- a/factory/helpers.py
+++ b/factory/helpers.py
@@ -20,10 +20,11 @@ def debug(logger='factory', stream=None):
     logger_obj.addHandler(handler)
     logger_obj.setLevel(logging.DEBUG)
 
-    yield
-
-    logger_obj.setLevel(old_level)
-    logger_obj.removeHandler(handler)
+    try:
+        yield
+    finally:
+        logger_obj.setLevel(old_level)
+        logger_obj.removeHandler(handler)
 
 
 def make_factory(klass, **kwargs):


Test patch:
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index c2a4f5f..57b45ed 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -55,3 +55,16 @@ class DebugTest(unittest.TestCase):
 
         self.assertEqual("", stream1.getvalue())
         self.assertEqual("Test2\n", stream2.getvalue())
+
+    def test_restores_logging_on_error(self):
+        class MyException(Exception):
+            pass
+
+        stream = io.StringIO()
+        try:
+            with helpers.debug(stream=stream):
+                raise MyException
+        except MyException:
+            logger = logging.getLogger('factory')
+            self.assertEqual(logger.level, logging.NOTSET)
+            self.assertEqual(logger.handlers, [])
Repository: FactoryBoy/factory_boy
Pull request #1032 (2023-07-24 20:35:54)

Don't require setting sqlalchemy_session to None when using a factory.
fixes FactoryBoy/factory_boy#1031

This fix makes it so that `sqlalchemy_session_factory` can be used without explicitly setting `sqlalchemy_session=None` in a metaclass.

francoisfreitag: Sounds reasonable, thanks for submitting a patch!

Patch:
diff --git a/factory/alchemy.py b/factory/alchemy.py
index 4e7ad6a..f934ce5 100644
--- a/factory/alchemy.py
+++ b/factory/alchemy.py
@@ -24,8 +24,11 @@ class SQLAlchemyOptions(base.FactoryOptions):
 
     @staticmethod
     def _check_has_sqlalchemy_session_set(meta, value):
-        if value and meta.sqlalchemy_session:
-            raise RuntimeError("Provide either a sqlalchemy_session or a sqlalchemy_session_factory, not both")
+        try:
+            if value and meta.sqlalchemy_session:
+                raise RuntimeError("Provide either a sqlalchemy_session or a sqlalchemy_session_factory, not both")
+        except AttributeError:
+            pass
 
     def _build_default_options(self):
         return super()._build_default_options() + [


Test patch:
diff --git a/tests/test_alchemy.py b/tests/test_alchemy.py
index 9cac036..19e4f5e 100644
--- a/tests/test_alchemy.py
+++ b/tests/test_alchemy.py
@@ -286,7 +286,6 @@ class SQLAlchemySessionFactoryTestCase(TransactionTestCase):
         class SessionGetterFactory(SQLAlchemyModelFactory):
             class Meta:
                 model = models.StandardModel
-                sqlalchemy_session = None
                 sqlalchemy_session_factory = lambda: models.session
 
             id = factory.Sequence(lambda n: n)
Repository: FactoryBoy/factory_boy
Pull request #1043 (2023-09-19 14:58:28)

Fixed mute_signals restoring signals receiver order.
We have multiple signal receivers on our Django project and the order that they are called is important. 
We found that this update https://github.com/FactoryBoy/factory_boy/commit/3a827f098cc3ac8003e81b18e42e0d14a9b2e2e3 changed the order of signal receivers which broke a few of our tests
For example we use the package `django-dirtyfields` and the order of the post_save signal for this package is very important

This might be related to https://github.com/FactoryBoy/factory_boy/issues/895


Patch:
diff --git a/factory/django.py b/factory/django.py
index 87b6fd5..9526b77 100644
--- a/factory/django.py
+++ b/factory/django.py
@@ -311,7 +311,7 @@ class mute_signals:
             logger.debug('mute_signals: Restoring signal handlers %r',
                          receivers)
 
-            signal.receivers += receivers
+            signal.receivers = receivers + signal.receivers
             with signal.lock:
                 # Django uses some caching for its signals.
                 # Since we're bypassing signal.connect and signal.disconnect,


Test patch:
diff --git a/tests/test_django.py b/tests/test_django.py
index 19729e0..066d792 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -941,6 +941,22 @@ class PreventSignalsTestCase(django_test.TestCase):
 
         self.assertTrue(self.handlers.created_during_instantiation.called)
 
+    def test_signal_receiver_order_restored_after_mute_signals(self):
+        def must_be_first(*args, **kwargs):
+            self.handlers.do_stuff(1)
+
+        def must_be_second(*args, **kwargs):
+            self.handlers.do_stuff(2)
+
+        signals.post_save.connect(must_be_first)
+        with factory.django.mute_signals(signals.post_save):
+            WithSignalsFactory(post_save_signal_receiver=must_be_second)
+            self.assertEqual(self.handlers.do_stuff.call_args_list, [mock.call(2)])
+
+        self.handlers.reset_mock()
+        WithSignalsFactory(post_save_signal_receiver=must_be_second)
+        self.assertEqual(self.handlers.do_stuff.call_args_list, [mock.call(1), mock.call(2)])
+
     def test_signal_cache(self):
         with factory.django.mute_signals(signals.pre_save, signals.post_save):
             signals.post_save.connect(self.handlers.mute_block_receiver)
Repository: dermotduffy/frigate-hass-card
Pull request #1441 (2024-04-15 02:48:46)

Fix control hiding and video seeking bugs
* Closes (maybe) #1310


Patch:
diff --git a/src/components/surround.ts b/src/components/surround.ts
index 4ff26aa8..45ee50f1 100644
--- a/src/components/surround.ts
+++ b/src/components/surround.ts
@@ -138,6 +138,7 @@ export class FrigateCardSurround extends LitElement {
                     ...(media.getCameraID() && { camera: media.getCameraID() }),
                   })
                   .removeContext('timeline')
+                  .removeContext('mediaViewer')
                   // Send the view change from the source of the tap event, so
                   // the view change will be caught by the handler above (to
                   // close the drawer).
diff --git a/src/utils/media.ts b/src/utils/media.ts
index 6bf63a93..f63f07a9 100644
--- a/src/utils/media.ts
+++ b/src/utils/media.ts
@@ -44,6 +44,17 @@ export const hideMediaControlsTemporarily = (
   setControlsOnVideo(video, false);
   video._controlsHideTimer ??= new Timer();
   video._controlsOriginalValue = oldValue;
+
+  // LitElement may change the src attribute of the video element during
+  // rendering, so we need to ensure that the controls are reset on the 'old'
+  // video. See:
+  // https://github.com/dermotduffy/frigate-hass-card/issues/1310
+  const resetIfReloaded = () => {
+    setControlsOnVideo(video, oldValue);
+    video.removeEventListener('loadstart', resetIfReloaded);
+  };
+  video.addEventListener('loadstart', resetIfReloaded);
+
   video._controlsHideTimer.start(seconds, () => {
     setControlsOnVideo(video, oldValue);
   });


Test patch:
diff --git a/tests/utils/media.test.ts b/tests/utils/media.test.ts
index 01859e85..adbdd322 100644
--- a/tests/utils/media.test.ts
+++ b/tests/utils/media.test.ts
@@ -51,6 +51,24 @@ describe('hideMediaControlsTemporarily', () => {
     expect(video.controls).toBeTruthy();
     expect(video._controlsHideTimer).toBeFalsy();
   });
+
+  it('should add event listener that resets controls', () => {
+    const video: FrigateCardHTMLVideoElement = document.createElement('video');
+    video.controls = true;
+
+    hideMediaControlsTemporarily(video);
+    expect(video.controls).toBeFalsy();
+
+    // After a new media starts to load, the controls should reset.
+    video.dispatchEvent(new Event('loadstart'));
+    expect(video.controls).toBeTruthy();
+
+    // ... but only once, future loadstart events without subsequent calls to
+    // hideMediaControlsTemporarily() should do nothing.
+    video.controls = false;
+    video.dispatchEvent(new Event('loadstart'));
+    expect(video._controlsHideTimer).toBeFalsy();
+  });
 });
 
 class NotAllowedError extends Error {
Repository: dermotduffy/frigate-hass-card
Pull request #1590 (2024-09-28 01:46:49)

fix: Don't hide menu in casting profile


Patch:
diff --git a/docs/usage/casting.md b/docs/usage/casting.md
index 3877ebca..960e3b34 100644
--- a/docs/usage/casting.md
+++ b/docs/usage/casting.md
@@ -23,6 +23,16 @@ Casting Home Assistant dashboards comes with a number of caveats:
 - The Javascript fullscreen API does not work (so the fullscreen button does not
   work, but see below for an equivalent).
 
+## The `casting` profile
+
+The optional [casting profile](../configuration/profiles.md?id=casting) provides
+some defaults to improve your casting experience. Use it like:
+
+```yaml
+profiles:
+  - casting
+```
+
 ## Recommended configuration for Nest Hub
 
 Using a `panel` dashboard with the following base configuration will result in
@@ -38,6 +48,8 @@ cameras:
 dimensions:
   aspect_ratio: 1024:600
   aspect_ratio_mode: static
+profile:
+  - casting
 ```
 
 ### Result
diff --git a/src/config/profiles/casting.ts b/src/config/profiles/casting.ts
index c53bf972..6537700a 100644
--- a/src/config/profiles/casting.ts
+++ b/src/config/profiles/casting.ts
@@ -5,11 +5,9 @@ import {
   CONF_LIVE_CONTROLS_BUILTIN,
   CONF_LIVE_SHOW_IMAGE_DURING_LOAD,
   CONF_MEDIA_VIEWER_CONTROLS_BUILTIN,
-  CONF_MENU_STYLE,
 } from '../../const.js';
 
 export const CASTING_PROFILE = {
-  [CONF_MENU_STYLE]: 'none' as const,
   [CONF_LIVE_AUTO_UNMUTE]: ['selected', 'visible'],
   [CONF_DIMENSIONS_ASPECT_RATIO]: '16:9',
   [CONF_LIVE_CONTROLS_BUILTIN]: false,


Test patch:
diff --git a/tests/config/profiles/casting.test.ts b/tests/config/profiles/casting.test.ts
index 886f86d0..cad2188d 100644
--- a/tests/config/profiles/casting.test.ts
+++ b/tests/config/profiles/casting.test.ts
@@ -12,7 +12,6 @@ it('should contain expected defaults', () => {
     'live.controls.builtin': false,
     'live.show_image_during_load': true,
     'media_viewer.controls.builtin': false,
-    'menu.style': 'none',
   });
 });