def test_can_handle_tag_no_asset():
    iroc_reader = IrocReader(
        storage=None,
        assets_config=None,
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    assert not iroc_reader.can_handle_tag(SensorTag("UON_EF.xxx", None))
def test_can_handle_tag_ok(mock_file_system):
    iroc_reader = IrocReader(
        storage=mock_file_system,
        assets_config=load_assets_config(),
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    assert iroc_reader.can_handle_tag(SensorTag("UON_EF.xxx", "UON_EF"))
def test_load_series_dry_run_raises():
    iroc_reader = IrocReader(
        storage=None,
        assets_config=load_assets_config(),
        storage_name="dataplatformdlsprod",
    )

    with pytest.raises(NotImplementedError):
        list(
            iroc_reader.load_series(
                train_start_date=isoparse("2018-05-02T01:56:00+02:00"),
                train_end_date=isoparse("2018-05-03T01:56:00+00:00"),
                tag_list=IROC_HAPPY_TAG_LIST,
                dry_run=True,
            ))
def test_load_series_checks_date():
    """load_series will raise ValueError if train_end_date<train_start_date"""
    iroc_reader = IrocReader(
        storage=None,
        assets_config=None,
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    with pytest.raises(ValueError):
        list(
            iroc_reader.load_series(
                train_start_date=isoparse("2018-05-03T01:56:00+00:00"),
                train_end_date=isoparse("2018-05-02T01:56:00+00:00"),
                tag_list=[SensorTag("jalla", None)],  # Not a tag in the input
            ))
def test_load_series_no_tag_list():
    """load_series will return an empty generator when called with no tags"""
    iroc_reader = IrocReader(
        storage=None,
        assets_config=None,
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    res = list(
        iroc_reader.load_series(
            train_start_date=isoparse("2018-05-02T01:56:00+00:00"),
            train_end_date=isoparse("2018-05-03T01:56:00+00:00"),
            tag_list=[],
        ))
    assert [] == res
def test_load_series_happy_path(_mocked_method, mock_file_system):
    """Happy-path testing of load_dataframe"""
    iroc_reader = IrocReader(
        storage=mock_file_system,
        assets_config=load_assets_config(),
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    res = list(
        iroc_reader.load_series(
            train_start_date=isoparse("2018-05-02T01:56:00+00:00"),
            train_end_date=isoparse("2018-05-03T01:56:00+00:00"),
            tag_list=IROC_HAPPY_TAG_LIST,
        ))
    # We get one dataframe per tag, so 3
    assert 3 == len(res)
def test_load_series_no_asset_found():
    """load_series will return an empty generator when called with tags
    that cannot be related to any asset"""
    iroc_reader = IrocReader(
        storage=None,
        assets_config=None,
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    with pytest.raises(ValueError):
        list(
            iroc_reader.load_series(
                train_start_date=isoparse("2018-05-02T01:56:00+00:00"),
                train_end_date=isoparse("2018-05-03T01:56:00+00:00"),
                tag_list=IROC_NO_ASSET_TAG_LIST,  # Not a tag in the input
            ))
def test_load_series_missing_columns_data(_mocked_method):
    """load_series will raise ValueError if there is a single tag it can not
    find"""
    iroc_reader = IrocReader(
        storage=None,
        assets_config=None,
        threads=1,
        storage_name="dataplatformdlsprod",
    )
    with pytest.raises(ValueError):
        list(
            iroc_reader.load_series(
                train_start_date=isoparse("2018-05-02T01:56:00+00:00"),
                train_end_date=isoparse("2018-05-03T01:56:00+00:00"),
                tag_list=IROC_HAPPY_TAG_LIST + [SensorTag("jalla", None)],
                # "jalla" is not a tag
            ))