示例#1
0
def test_write_dict_to_pi_file():
    """Test to write a dict of TimeseriesStub-like objects to a PI XML file."""
    dict_series =\
        {"precipitation": SparseTimeseriesStub(datetime(2011, 10, 25), [10.0, 20.0, 30.0]),
         "seepage": SparseTimeseriesStub(datetime(2011, 10, 25), [40.0, 50.0, 60.0]),
         }

    testdata = pkg_resources.resource_filename("timeseries", "testdata/")
    filename = "open-water-incoming-flows.xml"
    filepath = os.path.join(testdata, filename)
    if filename in os.listdir(testdata):
        os.remove(filepath)

    write_to_pi_file(location_id="SAP",
                     filename=filepath,
                     timeseries=dict_series)

    obj = TimeSeries.as_dict(filepath)

    if filename in os.listdir(testdata):
        os.remove(filepath)

    for parameter_id, series in dict_series.iteritems():
        stored_events = [(e[0], e[1][0])
                         for e in obj[("SAP", parameter_id)].get_events()]
        assert stored_events == list(series.events())
示例#2
0
def test_write_to_pi_file():
    """Test the way to write a TimeseriesStub-like object to a PI XML file."""
    series = \
        SparseTimeseriesStub(datetime(2011, 10, 25), [10.0, 20.0, 30.0])

    testdata = pkg_resources.resource_filename("timeseries", "testdata/")
    filename = "sluice-error.xml"
    filepath = os.path.join(testdata, filename)
    if filename in os.listdir(testdata):
        os.remove(filepath)

    write_to_pi_file(location_id="SAP", parameter_id="sluice-error",
        filename=filepath, timeseries=series)

    obj = TimeSeries.as_dict(filepath)

    if filename in os.listdir(testdata):
        os.remove(filepath)

    stored_events = [(e[0], e[1][0]) for e in obj[("SAP", "sluice-error")].get_events()]
    assert stored_events == list(series.events())
示例#3
0
def test_write_dict_to_pi_file():
    """Test to write a dict of TimeseriesStub-like objects to a PI XML file."""
    dict_series =\
        {"precipitation": SparseTimeseriesStub(datetime(2011, 10, 25), [10.0, 20.0, 30.0]),
         "seepage": SparseTimeseriesStub(datetime(2011, 10, 25), [40.0, 50.0, 60.0]),
         }

    testdata = pkg_resources.resource_filename("timeseries", "testdata/")
    filename = "open-water-incoming-flows.xml"
    filepath = os.path.join(testdata, filename)
    if filename in os.listdir(testdata):
        os.remove(filepath)

    write_to_pi_file(location_id="SAP", filename=filepath, timeseries=dict_series)

    obj = TimeSeries.as_dict(filepath)

    if filename in os.listdir(testdata):
        os.remove(filepath)

    for parameter_id, series in dict_series.iteritems():
        stored_events = [(e[0], e[1][0]) for e in obj[("SAP", parameter_id)].get_events()]
        assert stored_events == list(series.events())
示例#4
0
def test_write_to_pi_file():
    """Test the way to write a TimeseriesStub-like object to a PI XML file."""
    series = \
        SparseTimeseriesStub(datetime(2011, 10, 25), [10.0, 20.0, 30.0])

    testdata = pkg_resources.resource_filename("timeseries", "testdata/")
    filename = "sluice-error.xml"
    filepath = os.path.join(testdata, filename)
    if filename in os.listdir(testdata):
        os.remove(filepath)

    write_to_pi_file(location_id="SAP",
                     parameter_id="sluice-error",
                     filename=filepath,
                     timeseries=series)

    obj = TimeSeries.as_dict(filepath)

    if filename in os.listdir(testdata):
        os.remove(filepath)

    stored_events = [(e[0], e[1][0])
                     for e in obj[("SAP", "sluice-error")].get_events()]
    assert stored_events == list(series.events())