Skip to content

Commit 5b75326

Browse files
[Work Item microsoft#17159 & microsoft#17194] fix ptest for python-omegaconf (microsoft#17332)
1 parent 9a24196 commit 5b75326

2 files changed

Lines changed: 127 additions & 4 deletions

File tree

SPECS/python-omegaconf/python-omegaconf.spec

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
Summary: A hierarchical configuration system
22
Name: python-omegaconf
33
Version: 2.3.0
4-
Release: 1%{?dist}
4+
Release: 2%{?dist}
55
License: BSD-3-Clause
66
Vendor: Microsoft Corporation
77
Distribution: Azure Linux
88
Group: Development/Languages/Python
99
URL: https://pypi.org/project/omegaconf/
1010
Source0: https://github.com/omry/omegaconf/archive/refs/tags/v%{version}.tar.gz#/%{name}-%version.tar.gz
11+
Patch0: upstream-fix-for-ptests.patch
1112
%if 0%{?with_check}
1213
BuildRequires: python3-pip
1314
%endif
@@ -28,7 +29,7 @@ OmegaConf is a hierarchical configuration system, with support for merging confi
2829
providing a consistent API regardless of hwo the configuration was created
2930

3031
%prep
31-
%autosetup -n omegaconf-%{version}
32+
%autosetup -p1 -n omegaconf-%{version}
3233

3334
%build
3435
%py3_build
@@ -37,14 +38,25 @@ providing a consistent API regardless of hwo the configuration was created
3738
%py3_install
3839

3940
%check
40-
pip3 install mock wheel
41-
#%python3 setup.py test
41+
%{python3} -m pip install --disable-pip-version-check --no-cache-dir \
42+
--target .pytest-deps \
43+
-r requirements/base.txt \
44+
"pytest<8" \
45+
pytest-mock \
46+
attrs \
47+
pydevd
48+
49+
PYTHONPATH=$PWD/.pytest-deps${PYTHONPATH:+:$PYTHONPATH} \
50+
%{python3} -m pytest tests
4251

4352
%files -n python3-omegaconf
4453
%license LICENSE
4554
%{python3_sitelib}/*
4655

4756
%changelog
57+
* Wed Jun 03 2026 Akhila Guruju <v-guakhila@microsoft.com> - 2.3.0-2
58+
- Added and fixed ptest.
59+
4860
* Fri May 10 2024 Alberto David Perez Guevara <aperezguevar@microsoft.com> - 2.3.0-1
4961
- Original version for Azure Linux.
5062
- license verified.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
From ed7e24bdbf68c3b9f979fd5bdb46f6b6c5472549 Mon Sep 17 00:00:00 2001
2+
From: akhila-guruju <v-guakhila@microsoft.com>
3+
Date: Tue, 12 May 2026 11:59:39 +0000
4+
Subject: [PATCH] Upstream fix for ptests
5+
6+
Upstream Patch reference: https://github.com/omry/omegaconf/commit/a656e85e44795d471c812d9f9c326967465cf788.patch
7+
PR: https://github.com/omry/omegaconf/pull/1225
8+
9+
Modified to apply to Azure Linux.
10+
Only first 2 commit changes are relevant to the ptests.
11+
Combined commit changes: https://github.com/omry/omegaconf/pull/1225/changes/BASE..8cb50f64ea58c217f908d3f65cb09c0707633234
12+
---
13+
pydevd_plugins/__init__.py | 7 ++--
14+
pydevd_plugins/extensions/__init__.py | 7 ++--
15+
tests/test_nodes.py | 50 +++++++++++++++++++++++++--
16+
3 files changed, 52 insertions(+), 12 deletions(-)
17+
18+
diff --git a/pydevd_plugins/__init__.py b/pydevd_plugins/__init__.py
19+
index e4abcfa..f77af49 100644
20+
--- a/pydevd_plugins/__init__.py
21+
+++ b/pydevd_plugins/__init__.py
22+
@@ -1,6 +1,3 @@
23+
-try:
24+
- __import__("pkg_resources").declare_namespace(__name__)
25+
-except ImportError: # pragma: no cover
26+
- import pkgutil
27+
+import pkgutil
28+
29+
- __path__ = pkgutil.extend_path(__path__, __name__)
30+
+__path__ = pkgutil.extend_path(__path__, __name__)
31+
diff --git a/pydevd_plugins/extensions/__init__.py b/pydevd_plugins/extensions/__init__.py
32+
index e4abcfa..f77af49 100644
33+
--- a/pydevd_plugins/extensions/__init__.py
34+
+++ b/pydevd_plugins/extensions/__init__.py
35+
@@ -1,6 +1,3 @@
36+
-try:
37+
- __import__("pkg_resources").declare_namespace(__name__)
38+
-except ImportError: # pragma: no cover
39+
- import pkgutil
40+
+import pkgutil
41+
42+
- __path__ = pkgutil.extend_path(__path__, __name__)
43+
+__path__ = pkgutil.extend_path(__path__, __name__)
44+
diff --git a/tests/test_nodes.py b/tests/test_nodes.py
45+
index af73670..8ef8e94 100644
46+
--- a/tests/test_nodes.py
47+
+++ b/tests/test_nodes.py
48+
@@ -843,8 +843,11 @@ def test_eq(node: ValueNode, value: Any, expected: Any) -> None:
49+
assert (value != node) != expected
50+
51+
# Check hash except for unhashable types (dict/list).
52+
- if not isinstance(value, (dict, list)):
53+
- assert (node.__hash__() == value.__hash__()) == expected
54+
+ # Per Python's hash contract: if a == b, then hash(a) == hash(b)
55+
+ # Note: if a != b, hashes may or may not be equal (collisions are allowed)
56+
+ # E.g. Path('a') != 'a' but their hashes are equal as of Python 3.12
57+
+ if not isinstance(value, (dict, list)) and expected:
58+
+ assert node.__hash__() == value.__hash__()
59+
60+
61+
@mark.parametrize(
62+
@@ -998,3 +1001,46 @@ def test_interpolation_result_readonly(flags: Any) -> None:
63+
# If no value was provided for the "readonly" flag, it should be set.
64+
if readonly is None:
65+
assert node._get_node_flag("readonly")
66+
+
67+
+
68+
+@mark.skipif(
69+
+ sys.version_info < (3, 12),
70+
+ reason="Hash collision between Path and str only exists in Python 3.12+",
71+
+)
72+
+def test_path_str_hash_collision_handling() -> None:
73+
+ """
74+
+ Regression test for Python 3.12+ hash collision between Path and str.
75+
+
76+
+ In Python 3.12+, Path('x') and 'x' have identical hashes but are not equal.
77+
+ This test verifies that OmegaConf's containers handle this collision correctly.
78+
+ """
79+
+ from pathlib import Path
80+
+
81+
+ path_str = "hello.txt"
82+
+ path_obj = Path(path_str)
83+
+ assert hash(path_obj) == hash(path_str)
84+
+ assert path_obj != path_str # type: ignore[comparison-overlap]
85+
+
86+
+ # Test PathNode behavior with hash collision
87+
+ path_node = PathNode(path_obj)
88+
+ assert hash(path_node) == hash(path_str)
89+
+ assert path_node != path_str
90+
+
91+
+ list_cfg1 = OmegaConf.create([path_obj])
92+
+ assert path_obj in list_cfg1
93+
+ assert path_str not in list_cfg1
94+
+
95+
+ list_cfg2 = OmegaConf.create([path_str])
96+
+ assert path_obj not in list_cfg2
97+
+ assert path_str in list_cfg2
98+
+
99+
+ # Test DictConfig with both types as values
100+
+ dict_cfg = OmegaConf.create(
101+
+ {
102+
+ "by_path": {"file": path_obj},
103+
+ "by_string": {"file": path_str},
104+
+ }
105+
+ )
106+
+ assert dict_cfg.by_path.file == path_obj
107+
+ assert dict_cfg.by_string.file == path_str
108+
+ assert dict_cfg.by_path.file != dict_cfg.by_string.file
109+
--
110+
2.43.0
111+

0 commit comments

Comments
 (0)