Esempio n. 1
0
def test_missing_script_function(use_cluster):
    """User requests to run a function not in the script"""

    c = Client(None, use_cluster)
    c.set_function("bad-function", bad_function)
    with pytest.raises(RedisReplyError):
        c.run_script("bad-function", "not-a-function-in-script",
                     ["bad-func-tensor"], ["output"])
Esempio n. 2
0
def test_run_script(use_cluster):
    data = np.array([[1, 2, 3, 4, 5]])

    c = Client(None, use_cluster)
    c.put_tensor("script-test-data", data)
    c.set_function("one-to-one", one_to_one)
    c.run_script("one-to-one", "one_to_one", ["script-test-data"], ["script-test-out"])
    out = c.get_tensor("script-test-out")
    assert out == 5
Esempio n. 3
0
def test_bad_function_execution(use_cluster):
    """Error raised inside function"""

    c = Client(None, use_cluster)
    c.set_function("bad-function", bad_function)
    data = np.array([1, 2, 3, 4])
    c.put_tensor("bad-func-tensor", data)
    with pytest.raises(RedisReplyError):
        c.run_script("bad-function", "bad_function", ["bad-func-tensor"],
                     ["output"])
Esempio n. 4
0
def test_run_script_multi(use_cluster):
    data = np.array([[1, 2, 3, 4]])
    data_2 = np.array([[5, 6, 7, 8]])

    c = Client(None, use_cluster)
    c.put_tensor("srpt-multi-out-data-1", data)
    c.put_tensor("srpt-multi-out-data-2", data_2)
    c.set_function("two-to-one", two_to_one)
    c.run_script(
        "two-to-one",
        "two_to_one",
        ["srpt-multi-out-data-1", "srpt-multi-out-data-2"],
        ["srpt-multi-out-output"],
    )
    out = c.get_tensor("srpt-multi-out-output")
    expected = np.array([4, 8])
    np.testing.assert_array_equal(
        out, expected, "Returned array from script not equal to expected result"
    )
Esempio n. 5
0
    Two inputs to one output
    """
    # return the highest element
    merged = torch.cat((data, data_2))
    return merged.max(1)[0]

# Connect a SmartRedis client to the Redis database
db_address = "127.0.0.1:6379"
client = Client(address=db_address, cluster=False)

# Generate some test data to feed to the two_to_one function
data = np.array([[1, 2, 3, 4]])
data_2 = np.array([[5, 6, 7, 8]])

# Put the test data into the Redis database
client.put_tensor("script-data-1", data)
client.put_tensor("script-data-2", data_2)

# Put the function into the Redis database
client.set_function("two-to-one", two_to_one)

# Run the script using the test data
client.run_script(
    "two-to-one",
    "two_to_one",
    ["script-data-1", "script-data-2"],
    ["script-multi-out-output"],
)

# Retrieve the output of the test function
out = client.get_tensor("script-multi-out-output")