File: fix-test_merge.py.patch

package info (click to toggle)
python-omegaconf 2.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,244 kB
  • sloc: python: 26,413; makefile: 38; sh: 11
file content (172 lines) | stat: -rw-r--r-- 6,360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Description: Fix test_merge.py
 The file was using private pytest stuff, causing FTBFS with latest pytest.
Author: Thomas Goirand <zigo@debian.org>
Bug-Debian: https://bugs.debian.org/1114316
Forwarded: no
Last-Update: 2025-10-27

Index: python-omegaconf/tests/test_merge.py
===================================================================
--- python-omegaconf.orig/tests/test_merge.py
+++ python-omegaconf/tests/test_merge.py
@@ -13,7 +13,6 @@ from typing import (
     Union,
 )
 
-from _pytest.python_api import RaisesContext
 from pytest import mark, param, raises
 
 from omegaconf import (
@@ -800,7 +799,7 @@ def test_optional_element_type_merge(
     inputs: Any, expected: Any, ref_type: Any, is_optional: bool
 ) -> None:
     configs = [_ensure_container(c) for c in inputs]
-    if isinstance(expected, RaisesContext):
+    if hasattr(expected, '__enter__'):
         with expected:
             OmegaConf.merge(*configs)
     else:
@@ -1010,7 +1009,7 @@ def test_optional_element_type_merge(
 )
 def test_union_merge(inputs: Any, expected: Any, type_hint: Any) -> None:
     configs = [_ensure_container(c) for c in inputs]
-    if isinstance(expected, RaisesContext):
+    if hasattr(expected, '__enter__'):
         with expected:
             OmegaConf.merge(*configs)
     else:
Index: python-omegaconf/tests/test_basic_ops_list.py
===================================================================
--- python-omegaconf.orig/tests/test_basic_ops_list.py
+++ python-omegaconf/tests/test_basic_ops_list.py
@@ -4,7 +4,6 @@ from pathlib import Path
 from textwrap import dedent
 from typing import Any, Callable, List, MutableSequence, Optional, Union
 
-from _pytest.python_api import RaisesContext
 from pytest import mark, param, raises
 
 from omegaconf import MISSING, AnyNode, DictConfig, ListConfig, OmegaConf, flag_override
@@ -16,6 +15,7 @@ from omegaconf.errors import (
     InterpolationToMissingValueError,
     KeyValidationError,
     MissingMandatoryValue,
+    OmegaConfBaseException,
     UnsupportedValueType,
     ValidationError,
 )
@@ -968,7 +968,7 @@ def test_setitem_slice(
     lst: List[Any],
     idx: slice,
     value: Union[List[Any], Any],
-    expected: Union[List[Any], RaisesContext[Any]],
+    expected: Union[List[Any], Any],
     constructor: Callable[[List[Any]], MutableSequence[Any]],
 ) -> None:
     cfg = constructor(lst)
@@ -976,13 +976,20 @@ def test_setitem_slice(
         cfg[idx] = value
         assert cfg == expected
     else:
-        expected_exception: Any = expected.expected_exception
-        if type(constructor) == type(list) and issubclass(
-            expected_exception, UnsupportedValueType
-        ):
-            return  # standard list() can accept object() so skip
+        expected_exception: Any = getattr(expected, 'expected_exception', None)
+
+        # Special case: plain Python list cannot raise OmegaConf-specific exceptions
+        if (constructor is list and
+            expected_exception is not None and
+            isinstance(expected_exception, type)):
+
+            if issubclass(expected_exception, OmegaConfBaseException):
+                # Plain Python list should accept the value - this is correct behavior
+                cfg[idx] = value
+                return
+
         orig_cfg = cfg[:]
-        with expected:
+        with expected:  # type: ignore
             cfg[idx] = value
         assert cfg == orig_cfg
 
Index: python-omegaconf/tests/structured_conf/test_structured_config.py
===================================================================
--- python-omegaconf.orig/tests/structured_conf/test_structured_config.py
+++ python-omegaconf/tests/structured_conf/test_structured_config.py
@@ -8,7 +8,7 @@ from pathlib import Path
 from types import LambdaType
 from typing import Any, Callable, Dict, List, Optional, Tuple, Union
 
-from _pytest.python_api import RaisesContext
+import pytest
 from pytest import fixture, mark, param, raises
 
 from omegaconf import (
@@ -2268,7 +2268,7 @@ class TestUnionsOfPrimitiveTypes:
         class_ = getattr(module.UnionsOfPrimitveTypes, class_name)
         cfg = OmegaConf.structured(class_)
 
-        if isinstance(expected, RaisesContext):
+        if hasattr(expected, '__enter__'):
             with expected:
                 cfg[key] = value
 
@@ -2329,7 +2329,7 @@ class TestUnionsOfPrimitiveTypes:
 
         assert _utils._get_value(cfg._get_node(key)) == value
 
-        if isinstance(expected, RaisesContext):
+        if hasattr(expected, '__enter__'):
             with expected:
                 cfg[key]
         else:
@@ -2362,7 +2362,7 @@ class TestUnionsOfPrimitiveTypes:
         class_ = module.UnionsOfPrimitveTypes.InterpolationToUnion
         cfg = OmegaConf.structured(class_)
 
-        if isinstance(expected, RaisesContext):
+        if hasattr(expected, '__enter__'):
             with expected:
                 cfg[key]
         else:
Index: python-omegaconf/tests/test_select.py
===================================================================
--- python-omegaconf.orig/tests/test_select.py
+++ python-omegaconf/tests/test_select.py
@@ -1,6 +1,6 @@
 from typing import Any, Optional
 
-from _pytest.python_api import RaisesContext
+import pytest
 from pytest import mark, param, raises
 
 from omegaconf import DictConfig, ListConfig, MissingMandatoryValue, OmegaConf
@@ -60,7 +60,7 @@ class TestSelect:
     ) -> None:
         cfg = _ensure_container(cfg)
         OmegaConf.set_struct(cfg, struct)
-        if isinstance(expected, RaisesContext):
+        if hasattr(expected, '__enter__'):
             with expected:
                 OmegaConf.select(cfg, key)
         else:
@@ -88,7 +88,7 @@ class TestSelect:
         register_func("func", lambda x: f"_{x}_")
         cfg = _ensure_container(cfg)
         OmegaConf.set_struct(cfg, struct)
-        if isinstance(expected, RaisesContext):
+        if hasattr(expected, '__enter__'):
             with expected:
                 OmegaConf.select(cfg, key)
         else:
@@ -284,7 +284,7 @@ class TestSelect:
 )
 def test_select_resolves_interpolation(cfg: Any, key: str, expected: Any) -> None:
     cfg = _ensure_container(cfg)
-    if isinstance(expected, RaisesContext):
+    if hasattr(expected, '__enter__'):
         with expected:
             OmegaConf.select(cfg, key)
     else: