예제 #1
0
import pandas as pd
import pytest
from tagreader import utils
from tagreader.utils import ReaderType, is_windows

if not is_windows():
    pytest.skip("All tests in module require Windows", allow_module_level=True)

START_TIME = "2018-01-17 16:00:00"
STOP_TIME = "2018-01-17 17:00:00"
SAMPLE_TIME = 60


@pytest.fixture(scope="module")
def PIHandler():
    from tagreader.odbc_handlers import PIHandlerODBC

    yield PIHandlerODBC("thehostname.statoil.net",
                        1234,
                        options={"das_server": "the_das_server"})


def test_generate_connection_string(PIHandler):
    res = PIHandler.generate_connection_string()
    expected = (
        "DRIVER={PI ODBC Driver};Server=the_das_server;Trusted_Connection=Yes;"
        "Command Timeout=1800;Provider Type=PIOLEDB;"
        "Provider String={Data source=thehostname;Integrated_Security=SSPI;"
        "Time Zone=UTC};")
    assert expected == res
예제 #2
0
import os

import pandas as pd
import pytest
from tagreader.clients import IMSClient, get_missing_intervals, get_next_timeslice
from tagreader.utils import ReaderType, is_windows

if is_windows():
    from tagreader.odbc_handlers import AspenHandlerODBC, PIHandlerODBC

is_GITHUBACTION = "GITHUB_ACTION" in os.environ
is_AZUREPIPELINE = "TF_BUILD" in os.environ
is_CI = is_GITHUBACTION or is_AZUREPIPELINE


def test_get_next_timeslice():
    start_time = pd.to_datetime("2018-01-02 14:00:00")
    stop_time = pd.to_datetime("2018-01-02 14:15:00")
    # taglist = ['tag1', 'tag2', 'tag3']
    ts = pd.Timedelta(60, unit="s")
    res = get_next_timeslice(start_time, stop_time, ts, max_steps=20)
    assert start_time, start_time + pd.Timedelta(6, unit="m") == res
    res = get_next_timeslice(start_time, stop_time, ts, max_steps=100000)
    assert start_time, stop_time == res


def test_get_missing_intervals():
    length = 10
    ts = 60
    data = {"tag1": range(0, length)}
    idx = pd.date_range(start="2018-01-18 05:00:00",