Skip to content

Commit 1465451

Browse files
Merge pull request #1574 from IntelPython/change-test-main-to-work-around-a-problem
2 parents 49ca398 + 7a6a1bf commit 1465451

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

dpctl/tests/test_service.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -236,60 +236,60 @@ def test_main_library_dir():
236236
assert os.path.exists(dir_path)
237237

238238

239-
def test_cmakedir():
240-
res = subprocess.run(
241-
[sys.executable, "-m", "dpctl", "--cmakedir"], capture_output=True
239+
def _run_main_lsplatform(flags: list) -> subprocess.CompletedProcess:
240+
status = subprocess.run(
241+
[sys.executable, "-m", "dpctl"] + flags, capture_output=True
242242
)
243-
assert res.returncode == 0
244-
assert res.stdout
245-
cmake_dir = res.stdout.decode("utf-8").strip()
246-
assert os.path.exists(os.path.join(cmake_dir, "dpctl-config.cmake"))
243+
return status
244+
245+
246+
def _check_completed_process(cp: subprocess.CompletedProcess):
247+
assert cp.returncode == 0
248+
if cp.stdout:
249+
assert cp.stdout.decode("utf-8").strip()
250+
else:
251+
# Listing may be empty due to no devices known to DPC++ RT
252+
# or due to a bug in CPU RT
253+
assert dpctl.get_num_devices() == 0 or (
254+
dpctl.get_num_devices() == 1 and dpctl.has_cpu_devices()
255+
)
256+
257+
258+
def _check_main_lsplatform(mode):
259+
# List platform using subprocess
260+
status = _run_main_lsplatform([mode])
261+
_check_completed_process(status)
247262

248263

249264
def test_main_full_list():
250-
res = subprocess.run(
251-
[sys.executable, "-m", "dpctl", "-f"], capture_output=True
252-
)
253-
assert res.returncode == 0
254-
if dpctl.get_num_devices() > 0:
255-
assert res.stdout
256-
assert res.stdout.decode("utf-8")
265+
_check_main_lsplatform("-f")
257266

258267

259268
def test_main_long_list():
260-
res = subprocess.run(
261-
[sys.executable, "-m", "dpctl", "-l"], capture_output=True
262-
)
263-
assert res.returncode == 0
264-
if dpctl.get_num_devices() > 0:
265-
assert res.stdout
266-
assert res.stdout.decode("utf-8")
269+
_check_main_lsplatform("-l")
267270

268271

269272
def test_main_summary():
270-
res = subprocess.run(
271-
[sys.executable, "-m", "dpctl", "-s"], capture_output=True
272-
)
273-
assert res.returncode == 0
274-
if dpctl.get_num_devices() > 0:
275-
assert res.stdout
276-
assert res.stdout.decode("utf-8")
273+
_check_main_lsplatform("-s")
277274

278275

279276
def test_main_warnings():
280-
res = subprocess.run(
281-
[sys.executable, "-m", "dpctl", "-s", "--includes"], capture_output=True
282-
)
283-
assert res.returncode == 0
284-
assert res.stdout or dpctl.get_num_devices() == 0
277+
res = _run_main_lsplatform(["-s", "--includes"])
278+
_check_completed_process(res)
285279
assert "UserWarning" in res.stderr.decode("utf-8")
286280
assert "is being ignored." in res.stderr.decode("utf-8")
287281

282+
res = _run_main_lsplatform(["-s", "--includes", "--cmakedir"])
283+
_check_completed_process(res)
284+
assert "UserWarning" in res.stderr.decode("utf-8")
285+
assert "are being ignored." in res.stderr.decode("utf-8")
286+
287+
288+
def test_cmakedir():
288289
res = subprocess.run(
289-
[sys.executable, "-m", "dpctl", "-s", "--includes", "--cmakedir"],
290-
capture_output=True,
290+
[sys.executable, "-m", "dpctl", "--cmakedir"], capture_output=True
291291
)
292292
assert res.returncode == 0
293-
assert res.stdout or dpctl.get_num_devices() == 0
294-
assert "UserWarning" in res.stderr.decode("utf-8")
295-
assert "are being ignored." in res.stderr.decode("utf-8")
293+
assert res.stdout
294+
cmake_dir = res.stdout.decode("utf-8").strip()
295+
assert os.path.exists(os.path.join(cmake_dir, "dpctl-config.cmake"))

0 commit comments

Comments
 (0)