From b647cca0d466eaa0431505133adbe944a2a8eefc Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Thu, 2 Sep 2021 18:02:34 -0500 Subject: [PATCH] Simplified arg parsing in SyclDevice constructor Since Cython is compiled with language_level=3 working with unicode type is obsolete (we should work with str type instead). Removed the dead branch of code. Added test to exercise repr method --- dpctl/_sycl_device.pyx | 13 ++----------- dpctl/tests/test_sycl_device.py | 6 ++++++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/dpctl/_sycl_device.pyx b/dpctl/_sycl_device.pyx index 4bb02a5812..ea3397875a 100644 --- a/dpctl/_sycl_device.pyx +++ b/dpctl/_sycl_device.pyx @@ -253,17 +253,8 @@ cdef class SyclDevice(_SyclDevice): cdef const char *filter_c_str = NULL cdef int ret = 0 - if type(arg) is unicode: - string = bytes(arg, "utf-8") - filter_c_str = string - DSRef = DPCTLFilterSelector_Create(filter_c_str) - ret = self._init_from_selector(DSRef) - if ret == -1: - raise ValueError( - "Could not create a SyclDevice with the selector string" - ) - elif isinstance(arg, unicode): - string = bytes(unicode(arg), "utf-8") + if type(arg) is str: + string = bytes(arg, "utf-8") filter_c_str = string DSRef = DPCTLFilterSelector_Create(filter_c_str) ret = self._init_from_selector(DSRef) diff --git a/dpctl/tests/test_sycl_device.py b/dpctl/tests/test_sycl_device.py index a944613d3e..4dd52c782f 100644 --- a/dpctl/tests/test_sycl_device.py +++ b/dpctl/tests/test_sycl_device.py @@ -51,6 +51,7 @@ "opencl:gpu:-1", "cuda:cpu:0", "abc", + 1, ] @@ -470,6 +471,10 @@ def check_print_device_info(device): pytest.fail("Encountered an exception inside print_device_info().") +def check_repr(device): + assert type(repr(device)) is str + + list_of_checks = [ check_get_max_compute_units, check_get_max_work_item_dims, @@ -523,6 +528,7 @@ def check_print_device_info(device): check_create_sub_devices_by_affinity_L1_cache, check_create_sub_devices_by_affinity_next_partitionable, check_print_device_info, + check_repr, ]