Skip to content

Commit b9a4c8d

Browse files
committed
test(cuda.core): move TestHost to tests/test_host.py
The `Host`-construction tests are device-agnostic and unrelated to the managed-memory ops surface, so they belong as a sibling of `tests/test_device.py` rather than buried inside `tests/memory/`. Pure move — no test logic changes. 8 tests collected and pass in the new location; combined count across both files is unchanged. Addresses PR #1775 review comment from leofang.
1 parent f46cd86 commit b9a4c8d

2 files changed

Lines changed: 55 additions & 49 deletions

File tree

cuda_core/tests/memory/test_managed_ops.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -286,55 +286,6 @@ def test_managed_memory_advise_location_validation(location_ops_device):
286286
plain.close()
287287

288288

289-
class TestHost:
290-
def test_default(self):
291-
h = Host()
292-
assert h.numa_id is None
293-
assert h.is_numa_current is False
294-
295-
def test_numa(self):
296-
h = Host(numa_id=3)
297-
assert h.numa_id == 3
298-
assert h.is_numa_current is False
299-
300-
def test_numa_current(self):
301-
h = Host.numa_current()
302-
assert h.is_numa_current is True
303-
assert h.numa_id is None
304-
305-
def test_invalid_numa_id(self):
306-
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
307-
Host(numa_id=-1)
308-
309-
def test_numa_id_rejects_bool(self):
310-
# bool is an int subclass; reject explicitly so Host(True) doesn't
311-
# alias Host(1) (and vice versa) in the singleton cache.
312-
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
313-
Host(numa_id=True)
314-
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
315-
Host(numa_id=False)
316-
317-
def test_numa_current_constructor_and_classmethod_agree(self):
318-
# Host(is_numa_current=True) and Host.numa_current() return the same singleton.
319-
assert Host(is_numa_current=True) is Host.numa_current()
320-
# numa_id and is_numa_current are mutually exclusive.
321-
with pytest.raises(ValueError, match="mutually exclusive"):
322-
Host(numa_id=0, is_numa_current=True)
323-
324-
def test_immutable(self):
325-
h = Host(numa_id=2)
326-
with pytest.raises(AttributeError):
327-
h.numa_id = 3 # type: ignore[misc]
328-
329-
def test_eq_hash(self):
330-
# Frozen dataclass equality is structural.
331-
assert Host() == Host()
332-
assert Host(numa_id=1) == Host(numa_id=1)
333-
assert Host() != Host(numa_id=0)
334-
assert Host.numa_current() != Host()
335-
assert hash(Host(numa_id=1)) == hash(Host(numa_id=1))
336-
337-
338289
class TestLocationCoerce:
339290
"""The coerce helper is internal; verify Device/Host/int/None inputs."""
340291

cuda_core/tests/test_host.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import pytest
5+
6+
from cuda.core import Host
7+
8+
9+
class TestHost:
10+
def test_default(self):
11+
h = Host()
12+
assert h.numa_id is None
13+
assert h.is_numa_current is False
14+
15+
def test_numa(self):
16+
h = Host(numa_id=3)
17+
assert h.numa_id == 3
18+
assert h.is_numa_current is False
19+
20+
def test_numa_current(self):
21+
h = Host.numa_current()
22+
assert h.is_numa_current is True
23+
assert h.numa_id is None
24+
25+
def test_invalid_numa_id(self):
26+
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
27+
Host(numa_id=-1)
28+
29+
def test_numa_id_rejects_bool(self):
30+
# bool is an int subclass; reject explicitly so Host(True) doesn't
31+
# alias Host(1) (and vice versa) in the singleton cache.
32+
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
33+
Host(numa_id=True)
34+
with pytest.raises(ValueError, match="numa_id must be a non-negative int"):
35+
Host(numa_id=False)
36+
37+
def test_numa_current_constructor_and_classmethod_agree(self):
38+
# Host(is_numa_current=True) and Host.numa_current() return the same singleton.
39+
assert Host(is_numa_current=True) is Host.numa_current()
40+
# numa_id and is_numa_current are mutually exclusive.
41+
with pytest.raises(ValueError, match="mutually exclusive"):
42+
Host(numa_id=0, is_numa_current=True)
43+
44+
def test_immutable(self):
45+
h = Host(numa_id=2)
46+
with pytest.raises(AttributeError):
47+
h.numa_id = 3 # type: ignore[misc]
48+
49+
def test_eq_hash(self):
50+
# Frozen dataclass equality is structural.
51+
assert Host() == Host()
52+
assert Host(numa_id=1) == Host(numa_id=1)
53+
assert Host() != Host(numa_id=0)
54+
assert Host.numa_current() != Host()
55+
assert hash(Host(numa_id=1)) == hash(Host(numa_id=1))

0 commit comments

Comments
 (0)