testserver.TestServerScope

testserver.TestServerScope(session, ns)

A namespaced view of a TestServerSession.

Construct one with TestServerSession.make_scope rather than directly. It is the test-side counterpart of the shiny.Session proxy a module's server function receives: ids go in and come out bare, and the session underneath sees them namespaced.

with test_server("app.py") as ts:
    counter = ts.make_scope("counter")
    counter.set_inputs(n=7)
    assert counter.get_output("label") == "n=7"

    # The session still sees the namespaced ids.
    assert ts.get_output("counter-label") == "n=7"

See Also

Attributes

Name Description
error A summary of the first error in this namespace, or None.
is_ok True when nothing in this namespace errored.
ns The namespace these ids are read in, such as "counter".

Methods

Name Description
flush Re-read the session’s values, and return this scope for chaining.
get_export Return one exported test value, named as the module exported it.
get_input Return one input value, named as the module’s own code names it.
get_output Return one output value, named as the module’s own code names it.
keys Return the keys dict(scope) produces. See TestServerValues.
make_scope Return a view of a module nested inside this one.
root_scope Return the session this scope is a view of.
set_inputs Set input values in this namespace and wait for the reactive flush.
to_values Capture this namespace’s current state.

flush

testserver.TestServerScope.flush()

Re-read the session's values, and return this scope for chaining.

get_export

testserver.TestServerScope.get_export(name)

Return one exported test value, named as the module exported it.

Raises

Name Type Description
KeyError If this namespace exported no such name.

get_input

testserver.TestServerScope.get_input(name)

Return one input value, named as the module's own code names it.

Raises

Name Type Description
KeyError If the session has not received that input in this namespace.

get_output

testserver.TestServerScope.get_output(name)

Return one output value, named as the module's own code names it.

Raises

Name Type Description
KeyError If this namespace has no such output.

keys

testserver.TestServerScope.keys()

Return the keys dict(scope) produces. See TestServerValues.

make_scope

testserver.TestServerScope.make_scope(id)

Return a view of a module nested inside this one.

root_scope

testserver.TestServerScope.root_scope()

Return the session this scope is a view of.

set_inputs

testserver.TestServerScope.set_inputs(**kwargs)

Set input values in this namespace and wait for the reactive flush.

Parameters

Name Type Description Default
**kwargs Any Input values keyed by the bare id the module’s own code uses. {}

Returns

Name Type Description
TestServerScope This scope, so calls can be chained.

Raises

Name Type Description
ValueError If an id is session-wide (.clientdata_*), which no namespace owns.

to_values

testserver.TestServerScope.to_values()

Capture this namespace's current state.

Returns

Name Type Description
TestServerValues A TestServerValues holding only this namespace’s items, keyed by bare id – the same shape a test of the module server on its own would produce.