Skip to content

Commit 30b82f9

Browse files
committed
Add docs and tests
1 parent 3b9b39d commit 30b82f9

File tree

3 files changed

+78
-8
lines changed

3 files changed

+78
-8
lines changed

python/perspective/docs/perspective.core.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Additionally, ``perspective.core`` defines several enums that provide easy acces
55

66
For usage of ``PerspectiveWidget`` and ``PerspectiveTornadoHandler``, see the User Guide in the sidebar.
77

8+
.. autofunction:: perspective.set_threadpool_size
9+
810
.. automodule:: perspective.core
911
:members:
1012
:show-inheritance:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
################################################################################
2+
#
3+
# Copyright (c) 2019, the Perspective Authors.
4+
#
5+
# This file is part of the Perspective library, distributed under the terms of
6+
# the Apache License 2.0. The full license can be found in the LICENSE file.
7+
#
8+
9+
################################################################################
10+
#
11+
# Copyright (c) 2019, the Perspective Authors.
12+
#
13+
# This file is part of the Perspective library, distributed under the terms of
14+
# the Apache License 2.0. The full license can be found in the LICENSE file.
15+
#
16+
17+
import pandas as pd
18+
from perspective import Table, set_threadpool_size
19+
20+
set_threadpool_size(1)
21+
22+
23+
class TestThreadPoolOne:
24+
def test_threadpool_one_does_not_block_view(self):
25+
t = Table(
26+
{"id": int, "symbol": str, "valid": bool, "value": int, "value2": int},
27+
index="id",
28+
)
29+
t.update(
30+
[
31+
{"id": 1, "symbol": "A", "valid": False, "value": 5, "value2": 15},
32+
{"id": 2, "symbol": "A", "valid": True, "value": 10, "value2": 20},
33+
]
34+
)
35+
36+
v = t.view(
37+
columns=["symbol", "value", "value3"],
38+
expressions=["""//value3\n"value" + "value2\""""],
39+
)
40+
41+
v_agg = t.view(
42+
columns=["symbol", "value", "value3"],
43+
expressions=["""//value3\n"value" + "value2\""""],
44+
group_by=["symbol"],
45+
aggregates={"symbol": "first", "value": "sum", "value2": "sum"},
46+
)
47+
48+
assert v.to_df().to_dict("records") == [
49+
{"symbol": "A", "value": 5, "value3": 20.0},
50+
{"symbol": "A", "value": 10, "value3": 30.0},
51+
]
52+
53+
assert v_agg.to_df().to_dict("records") == [
54+
{"__ROW_PATH__": [], "symbol": "A", "value": 15, "value3": 50.0},
55+
{"__ROW_PATH__": ["A"], "symbol": "A", "value": 15, "value3": 50.0},
56+
]

scripts/test_python.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,23 @@ const pytest_client_mode = (IS_DOCKER) => {
6969
}
7070
};
7171

72+
/**
73+
* Run pytest for single-threaded tests
74+
*/
75+
const pytest_single_threaded = (IS_DOCKER) => {
76+
if (IS_DOCKER) {
77+
return bash`${docker(IMAGE)} bash -c "cd \
78+
python/perspective && TZ=UTC PYTHONMALLOC=debug ${PYTHON} -m pytest \
79+
${VERBOSE ? "-vv --full-trace" : ""} --noconftest
80+
perspective/tests/single_threaded"`;
81+
} else {
82+
return bash`cd ${python_path} && PYTHONMALLOC=debug ${PYTHON} -m pytest \
83+
${VERBOSE ? "-vv --full-trace" : ""} --noconftest
84+
--disable-pytest-warnings
85+
perspective/tests/single_threaded`;
86+
}
87+
};
88+
7289
/**
7390
* Run `pytest` for the `perspective-python` library.
7491
*/
@@ -78,12 +95,14 @@ const pytest = (IS_DOCKER) => {
7895
python/perspective && TZ=UTC PYTHONMALLOC=debug ${PYTHON} -m pytest \
7996
${VERBOSE ? "-vv --full-trace" : ""} perspective \
8097
--ignore=perspective/tests/client_mode \
98+
--ignore=perspective/tests/single_threaded \
8199
--disable-pytest-warnings
82100
--cov=perspective"`;
83101
} else {
84102
return bash`cd ${python_path} && PYTHONMALLOC=debug ${PYTHON} -m pytest \
85103
${VERBOSE ? "-vv --full-trace" : ""} perspective \
86104
--ignore=perspective/tests/client_mode \
105+
--ignore=perspective/tests/single_threaded \
87106
--disable-pytest-warnings
88107
${COVERAGE ? "--cov=perspective" : ""}`;
89108
}
@@ -97,16 +116,9 @@ try {
97116
PYTHON = "python";
98117
}
99118

100-
// Check that the `PYTHON` command is valid, else default to `python`.
101-
try {
102-
execute_throw`${PYTHON} --version`;
103-
} catch (e) {
104-
console.warn(`\`${PYTHON}\` not found - using \`python\` instead.`);
105-
PYTHON = "python";
106-
}
107-
108119
try {
109120
execute(pytest_client_mode(IS_DOCKER));
121+
execute(pytest_single_threaded(IS_DOCKER));
110122
execute(pytest(IS_DOCKER));
111123
} catch (e) {
112124
console.log(e.message);

0 commit comments

Comments
 (0)