Пример #1
0
def test_enable_disable_memmap(tmpdir):
    f = os.path.join(tmpdir, 'npn_empty.npy')
    arr = [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]
    a = MemMapArray(arr, filename=f, dtype=None, memmap=False)
    check.is_false(a.memmap)
    check.is_false(os.path.exists(f))

    a.enable_memmap()
    check.is_true(a.memmap)
    check.is_true(os.path.exists(f))
    check.is_instance(a._contained, np.memmap)

    # First keep the file
    a.disable_memmap(remove=False)
    check.is_false(a.memmap)
    check.is_true(os.path.exists(f))
    check.is_not_instance(a._contained, np.memmap)

    a.enable_memmap()
    check.is_true(a.memmap)
    check.is_true(os.path.exists(f))
    check.is_instance(a._contained, np.memmap)

    # Remove the file
    a.disable_memmap(remove=True)
    check.is_false(a.memmap)
    check.is_false(os.path.exists(f))
    check.is_not_instance(a._contained, np.memmap)

    with pytest.raises(ValueError):
        # raises error if name is locked
        a.enable_memmap('not_the_same_name.npy')
Пример #2
0
def test_splunk_query_success(splunk_client, splunk_results):
    """Check loaded true."""
    splunk_client.connect = cli_connect
    sp_driver = SplunkDriver()
    splunk_results.ResultsReader = _results_reader

    # trying to get these before connecting should throw
    with pytest.raises(MsticpyNotConnectedError) as mp_ex:
        sp_driver.query("some query")
        check.is_false(sp_driver.connected)
    check.is_in("not connected to Splunk.", mp_ex.value.args)

    sp_driver.connect(host="localhost", username="******",
                      password="******")  # nosec
    check.is_true(sp_driver.connected)

    df_result = sp_driver.query("some query")
    check.is_instance(df_result, pd.DataFrame)
    check.equal(len(df_result), 10)

    response = sp_driver.query("zero query")
    check.is_not_instance(response, pd.DataFrame)
    check.equal(len(response), 0)
Пример #3
0
def test_splunk_query_success(splunk_client, splunk_results):
    """Check loaded true."""
    splunk_client.connect = cli_connect
    sp_driver = SplunkDriver()
    splunk_results.ResultsReader = _results_reader

    # trying to get these before connecting should throw
    with pytest.raises(MsticpyNotConnectedError) as mp_ex:
        sp_driver.query("some query")
        check.is_false(sp_driver.connected)
    check.is_in("not connected to Splunk.", mp_ex.value.args)

    # [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Test code")]
    sp_driver.connect(host="localhost", username="******", password=_FAKE_STRING)  # nosec
    check.is_true(sp_driver.connected)

    df_result = sp_driver.query("some query")
    check.is_instance(df_result, pd.DataFrame)
    check.equal(len(df_result), 10)

    response = sp_driver.query("zero query")
    check.is_not_instance(response, pd.DataFrame)
    check.equal(len(response), 0)
Пример #4
0
def test_create_and_delete_memmap(tmpdir):
    # Creation
    f = os.path.join(tmpdir, 'testarray.npy')
    g = os.path.join(tmpdir, 'test2array.npy')
    a = np.ones((30, 30), dtype='f8')
    b = create_array_memmap(f, a)
    c = create_array_memmap(g, a, dtype=bool)
    check.is_instance(b, np.memmap)
    check.is_instance(c, np.memmap)
    npt.assert_array_equal(a, b)
    npt.assert_allclose(a, c)
    check.is_true(os.path.exists(f))
    check.is_true(os.path.exists(g))

    # Deletion
    # Since for the uses the object is overwritten, we do it here too
    d = delete_array_memmap(b, read=True, remove=False)
    e = delete_array_memmap(c, read=True, remove=False)
    check.is_not_instance(d, np.memmap)
    check.is_not_instance(e, np.memmap)
    check.is_instance(d, np.ndarray)
    check.is_instance(e, np.ndarray)
    npt.assert_array_equal(a, d)
    npt.assert_allclose(a, e)
    check.is_true(os.path.exists(f))
    check.is_true(os.path.exists(g))

    d = delete_array_memmap(b, read=False, remove=True)
    e = delete_array_memmap(c, read=False, remove=True)
    check.is_true(d is None)
    check.is_true(e is None)
    check.is_false(os.path.exists(f))
    check.is_false(os.path.exists(g))

    # None should not raise errors
    create_array_memmap('dummy', None)
    delete_array_memmap(None)
Пример #5
0
def test_is_not_instance():
    check.is_not_instance(1, str)