Example #1
0
def test_prep_columns():
    """Test whether _prep_columns correctly prepares data."""
    # Generate simple input data
    time_input = TIME[0:2]
    channels_input = [CHANNELS[0][0:2], CHANNELS[1][0:2]]
    filecolumns_input = ["time", "channel0", "channel1"]

    # Test case when channels and filecolumns are supplied by user.
    string_time_test, filecolumns_test = lyra._prep_columns(
        time_input, channels_input, filecolumns_input)
    # Generate expected output and verify _prep_columns() works
    string_time_expected = np.array(
        [t.strftime("%Y-%m-%dT%H:%M:%S.%f") for t in time_input])
    filecolumns_expected = ["time", "channel0", "channel1"]
    np.testing.assert_array_equal(string_time_test, string_time_expected)
    assert filecolumns_test == filecolumns_expected

    # Test case when channels supplied by user by not filecolumns
    string_time_test, filecolumns_test = lyra._prep_columns(
        time_input, channels_input)
    np.testing.assert_array_equal(string_time_test, string_time_expected)
    assert filecolumns_test == filecolumns_expected

    # Test case when neither channels nor filecolumns supplied by user
    string_time_test, filecolumns_test = lyra._prep_columns(time_input)
    np.testing.assert_array_equal(string_time_test, string_time_expected)
    assert filecolumns_test == ["time"]

    # Test correct exceptions are raised
    with pytest.raises(TypeError):
        string_time_test, filecolumns_test = lyra._prep_columns(
            time_input, channels_input, ["channel0", 1])
    with pytest.raises(ValueError):
        string_time_test = lyra._prep_columns(time_input,
                                              filecolumns=filecolumns_input)
Example #2
0
def test_prep_columns():
    """Test whether _prep_columns correctly prepares data."""
    # Generate simple input data
    time_input = TIME[0:2]
    channels_input = [CHANNELS[0][0:2], CHANNELS[1][0:2]]
    filecolumns_input = ["time", "channel0", "channel1"]

    # Test case when channels and filecolumns are supplied by user.
    string_time_test, filecolumns_test = lyra._prep_columns(
        time_input, channels_input, filecolumns_input)
    # Generate expected output and verify _prep_columns() works
    string_time_expected = np.array([t.strftime("%Y-%m-%dT%H:%M:%S.%f")
                                     for t in time_input])
    filecolumns_expected = ["time", "channel0", "channel1"]
    np.testing.assert_array_equal(string_time_test, string_time_expected)
    assert filecolumns_test == filecolumns_expected

    # Test case when channels supplied by user by not filecolumns
    string_time_test, filecolumns_test = lyra._prep_columns(time_input,
                                                                channels_input)
    np.testing.assert_array_equal(string_time_test, string_time_expected)
    assert filecolumns_test == filecolumns_expected

    # Test case when neither channels nor filecolumns supplied by user
    string_time_test, filecolumns_test = lyra._prep_columns(time_input)
    np.testing.assert_array_equal(string_time_test, string_time_expected)
    assert filecolumns_test == ["time"]

    # Test correct exceptions are raised
    with pytest.raises(TypeError):
        string_time_test, filecolumns_test = lyra._prep_columns(
        time_input, channels_input, ["channel0", 1])
    with pytest.raises(ValueError):
        string_time_test = lyra._prep_columns(time_input,
                                          filecolumns=filecolumns_input)