Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tagreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
ReaderType,
add_equinor_root_certificate,
is_equinor,
is_mac,
is_windows,
)

if is_equinor():
add_equinor_root_certificate()

from tagreader.__version__ import version as __version__

__all__ = [
"IMSClient",
"list_sources",
"IMSType",
"ReaderType",
"add_equinor_root_certificate",
"__version__",
]
22 changes: 11 additions & 11 deletions tagreader/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def list_sources(
imstype: Union[IMSType, str],
url: Optional[str] = None,
auth: Optional[Any] = None,
verifySSL: bool = True,
verify_ssl: Optional[Union[bool, str]] = True,
) -> List[str]:
if isinstance(imstype, str):
try:
Expand All @@ -47,11 +47,11 @@ def list_sources(
if imstype == IMSType.PIWEBAPI:
if auth is None:
auth = get_auth_pi()
return list_piwebapi_sources(url=url, auth=auth, verify_ssl=verifySSL)
return list_piwebapi_sources(url=url, auth=auth, verify_ssl=verify_ssl)
elif imstype == IMSType.ASPENONE:
if auth is None:
auth = get_auth_aspen()
return list_aspenone_sources(url=url, auth=auth, verify_ssl=verifySSL)
return list_aspenone_sources(url=url, auth=auth, verify_ssl=verify_ssl)
elif imstype in [IMSType.PI, IMSType.ASPEN, IMSType.IP21]:
raise ValueError(
f"ODBC clients are no longer supported. Given ims client type: {imstype}."
Expand Down Expand Up @@ -120,22 +120,22 @@ def get_handler(
datasource: str,
url: Optional[str],
options: Dict[str, Union[int, float, str]],
verifySSL: Optional[bool],
verify_ssl: Optional[Union[bool, str]],
auth: Optional[Any],
cache: Optional[Union[SmartCache, BucketCache]] = None,
):
if imstype is None:
try:
if datasource in list_aspenone_sources(
url=None, auth=None, verify_ssl=verifySSL
url=None, auth=None, verify_ssl=verify_ssl
):
imstype = IMSType.ASPENONE
except HTTPError as e:
logger.debug(f"Could not list Aspenone sources: {e}")
if imstype is None:
try:
if datasource in list_piwebapi_sources(
url=None, auth=None, verify_ssl=verifySSL
url=None, auth=None, verify_ssl=verify_ssl
):
imstype = IMSType.PIWEBAPI
except HTTPError as e:
Expand All @@ -146,7 +146,7 @@ def get_handler(
url=url,
datasource=datasource,
options=options,
verify_ssl=verifySSL,
verify_ssl=verify_ssl,
auth=auth,
cache=cache,
)
Expand All @@ -156,7 +156,7 @@ def get_handler(
datasource=datasource,
url=url,
options=options,
verify_ssl=verifySSL,
verify_ssl=verify_ssl,
auth=auth,
)
elif imstype in [IMSType.PI, IMSType.ASPEN, IMSType.IP21]:
Expand All @@ -178,7 +178,7 @@ def __init__(
tz: Union[tzinfo, str] = pytz.timezone("Europe/Oslo"),
url: Optional[str] = None,
handler_options: Dict[str, Union[int, float, str]] = {}, # noqa:
verifySSL: bool = True,
verify_ssl: Optional[Union[bool, str]] = True,
auth: Optional[Any] = None,
cache: Optional[Union[SmartCache, BucketCache]] = None,
):
Expand Down Expand Up @@ -209,7 +209,7 @@ def __init__(
datasource=datasource,
url=url,
options=handler_options,
verifySSL=verifySSL,
verify_ssl=verify_ssl,
auth=auth,
cache=self.cache,
)
Expand Down Expand Up @@ -412,7 +412,7 @@ def read_tags(
):
start = start_time
end = stop_time
logger.warn(
logger.warning(
(
"This function has been renamed to read() and is deprecated. "
"Please call 'read()' instead"
Expand Down
12 changes: 6 additions & 6 deletions tagreader/web_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_url_aspen(use_internal: bool = True) -> str:
def list_aspenone_sources(
url: Optional[str] = None,
auth: Optional[Any] = None,
verify_ssl: Optional[bool] = True,
verify_ssl: Optional[Union[bool, str]] = True,
) -> List[str]:
if url is None:
url = get_url_aspen()
Expand Down Expand Up @@ -124,7 +124,7 @@ def list_aspenone_sources(
def list_piwebapi_sources(
url: Optional[str] = None,
auth: Optional[Any] = None,
verify_ssl: Optional[bool] = True,
verify_ssl: Optional[Union[bool, str]] = True,
) -> List[str]:
if url is None:
url = get_url_pi()
Expand Down Expand Up @@ -152,7 +152,7 @@ def list_piwebapi_sources(
def get_piwebapi_source_to_webid_dict(
url: Optional[str] = None,
auth: Optional[Any] = None,
verify_ssl: Optional[bool] = True,
verify_ssl: Optional[Union[bool, str]] = True,
) -> List[str]:
if url is None:
url = get_url_pi()
Expand Down Expand Up @@ -182,7 +182,7 @@ def __init__(
datasource: Optional[str],
url: Optional[str],
auth: Optional[Any],
verify_ssl: Optional[bool],
verify_ssl: Optional[Union[bool, str]],
):
self.datasource = datasource
self.base_url = url
Expand Down Expand Up @@ -241,7 +241,7 @@ def __init__(
datasource: Optional[str],
url: Optional[str] = None,
auth: Optional[Any] = None,
verify_ssl: Optional[bool] = True,
verify_ssl: Optional[Union[bool, str]] = True,
options: Dict[str, Any] = dict(),
):
if url is None:
Expand Down Expand Up @@ -710,7 +710,7 @@ def __init__(
url: Optional[str],
datasource: Optional[str],
auth: Optional[Any],
verify_ssl: bool,
verify_ssl: Optional[Union[bool, str]],
options: Dict[str, Union[int, float, str]],
cache: Optional[Union[SmartCache, BucketCache]],
):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_AspenHandlerREST_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
VERIFY_SSL = False if is_AZURE_PIPELINE else get_verify_ssl()

SOURCE = "TRB"
TAG = "xxx"
TAG = "AverageCPUTimeVals"
FAKE_TAG = "so_random_it_cant_exist"
START_TIME = datetime(2023, 5, 1, 10, 0, 0)
STOP_TIME = datetime(2023, 5, 1, 11, 0, 0)
Expand All @@ -37,7 +37,7 @@ def client() -> Generator[IMSClient, None, None]:
c = IMSClient(
datasource=SOURCE,
imstype="aspenone",
verifySSL=bool(VERIFY_SSL),
verify_ssl=bool(VERIFY_SSL),
)
c.cache = None
c.connect()
Expand All @@ -64,7 +64,7 @@ def test_list_all_aspen_one_sources() -> None:


def test_list_sources_aspen_one() -> None:
res = list_sources(imstype=IMSType.ASPENONE, verifySSL=bool(VERIFY_SSL))
res = list_sources(imstype=IMSType.ASPENONE, verify_ssl=bool(VERIFY_SSL))
assert isinstance(res, list)
assert len(res) >= 1
assert isinstance(res[0], str)
Expand All @@ -81,8 +81,8 @@ def test_search_tag(client: IMSClient) -> None:
res = client.search(tag=FAKE_TAG, desc=None)
assert 0 == len(res)

res = client.search(tag="AverageCPUTimeVals", desc=None)
assert res == [("AverageCPUTimeVals", "Average CPU Time")]
res = client.search(tag=TAG, desc=None)
assert res == [(TAG, "Average CPU Time")]

res = client.search(tag="Aspen*", desc=None, return_desc=False)
assert len(res) < 5
Expand All @@ -99,8 +99,8 @@ def test_search_tag(client: IMSClient) -> None:
res = client.search("AspenCalcTrigger1", desc=None)
assert res == [("AspenCalcTrigger1", "")]

res = client.search("AverageCPUTimeVals", "*CPU*")
assert res == [("AverageCPUTimeVals", "Average CPU Time")]
res = client.search(TAG, "*CPU*")
assert res == [(TAG, "Average CPU Time")]
with pytest.raises(ValueError):
_ = client.search(desc="Sine Input") # noqa

Expand Down Expand Up @@ -146,7 +146,7 @@ def test_query_sql(client: IMSClient) -> None:
assert isinstance(res, pd.DataFrame)
assert res.empty

query = "Select name, ip_description from ip_analogdef where name = 'AverageCPUTimeVals'"
query = f"Select name, ip_description from ip_analogdef where name = '{TAG}'"
res = client.query_sql(query=query, parse=True)
assert isinstance(res, pd.DataFrame)
assert len(res.index.values) == 1
Expand Down
10 changes: 5 additions & 5 deletions tests/test_PIHandlerREST_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"All tests in module require connection to PI server", allow_module_level=True
)

verifySSL = False if is_AZUREPIPELINE else get_verify_ssl()
verify_ssl = False if is_AZUREPIPELINE else get_verify_ssl()

SOURCE = "PIMAM"
TAGS = {
Expand All @@ -36,7 +36,7 @@ def client() -> Generator[IMSClient, None, None]:
c = IMSClient(
datasource=SOURCE,
imstype="piwebapi",
verifySSL=bool(verifySSL),
verify_ssl=bool(verify_ssl),
)
c.cache = None
c.connect()
Expand All @@ -50,7 +50,7 @@ def client() -> Generator[IMSClient, None, None]:
def pi_handler(cache: SmartCache) -> Generator[PIHandlerWeb, None, None]:
h = PIHandlerWeb(
datasource=SOURCE,
verify_ssl=bool(verifySSL),
verify_ssl=bool(verify_ssl),
auth=None,
options={},
url=None,
Expand All @@ -63,7 +63,7 @@ def pi_handler(cache: SmartCache) -> Generator[PIHandlerWeb, None, None]:


def test_list_all_piwebapi_sources() -> None:
res = list_piwebapi_sources(verify_ssl=bool(verifySSL), auth=None, url=None)
res = list_piwebapi_sources(verify_ssl=bool(verify_ssl), auth=None, url=None)
assert isinstance(res, list)
assert len(res) >= 1
for r in res:
Expand All @@ -72,7 +72,7 @@ def test_list_all_piwebapi_sources() -> None:


def test_list_sources_piwebapi() -> None:
res = list_sources(imstype="piwebapi", verifySSL=bool(verifySSL))
res = list_sources(imstype="piwebapi", verify_ssl=bool(verify_ssl))
assert isinstance(res, list)
assert len(res) >= 1
for r in res:
Expand Down
Loading