Files
TheRock/rocm-systems/projects/hipfile/python/tests/test_driver.py
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

75 lines
2.2 KiB
Python

# Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
#
# SPDX-License-Identifier: MIT
"""Tests for hipfile.driver.Driver."""
# pylint: disable=missing-function-docstring,redefined-outer-name
# pylint: disable=import-error # hipfile not installed in lint env; extension faked
from unittest import mock
import pytest
import hipfile.driver
from hipfile.driver import Driver
from hipfile.enums import OpError
from hipfile.error import HipFileException
_SUCCESS = (OpError.SUCCESS, 0)
_FAILURE = (OpError.DRIVER_NOT_INITIALIZED, 0)
def test_open_success():
with mock.patch.object(
hipfile.driver, "hipFileDriverOpen", autospec=True, return_value=_SUCCESS
) as drv_open:
Driver().open()
drv_open.assert_called_once_with()
def test_open_raises_on_error():
with mock.patch.object(
hipfile.driver, "hipFileDriverOpen", autospec=True, return_value=_FAILURE
):
with pytest.raises(HipFileException) as excinfo:
Driver().open()
assert excinfo.value.hipfile_err == OpError.DRIVER_NOT_INITIALIZED
def test_close_success():
with mock.patch.object(
hipfile.driver, "hipFileDriverClose", autospec=True, return_value=_SUCCESS
) as drv_close:
Driver().close()
drv_close.assert_called_once_with()
def test_close_raises_on_error():
with mock.patch.object(
hipfile.driver, "hipFileDriverClose", autospec=True, return_value=_FAILURE
):
with pytest.raises(HipFileException):
Driver().close()
def test_use_count_delegates():
with mock.patch.object(
hipfile.driver, "hipFileUseCount", autospec=True, return_value=5
) as use_count:
assert Driver.use_count() == 5
use_count.assert_called_once_with()
def test_context_manager_opens_then_closes():
with mock.patch.object(
hipfile.driver, "hipFileDriverOpen", autospec=True, return_value=_SUCCESS
) as drv_open, mock.patch.object(
hipfile.driver, "hipFileDriverClose", autospec=True, return_value=_SUCCESS
) as drv_close:
with Driver() as drv:
assert isinstance(drv, Driver)
drv_open.assert_called_once_with()
drv_close.assert_not_called()
drv_close.assert_called_once_with()