You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .agents/context/testing.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,20 @@
1
1
# Testing Instructions
2
2
3
-
Cypress 9 for E2E and visual regression. No Python unit tests — validation is via demo scripts and Cypress.
3
+
Two layers: **pytest** for Python unit tests (pure functions, server utils, window/env lifecycle) and **Cypress 9** for E2E and visual regression. Demo scripts remain useful for manual/visual validation.
4
4
5
-
## Run Tests
5
+
## Run Python Tests (pytest)
6
+
7
+
```bash
8
+
pip install -r test-requirements.txt # includes pytest, pytest-cov
9
+
pytest # runs the tracked suite under py/tests/
10
+
pytest -m "not server"# skip tests that need a live server (CI default)
11
+
```
12
+
13
+
Config lives in `pyproject.toml` (`[tool.pytest.ini_options]`): discovery is scoped to
14
+
`py/tests/` and `pythonpath = ["py"]` makes `import visdom` work without an editable install.
15
+
Experimental `test_*.py` scripts in the repo root (and `test/`) are intentionally out of scope.
16
+
17
+
## Run E2E / Visual Tests (Cypress)
6
18
7
19
```bash
8
20
visdom -port 8098 -env_path /tmp # Always start fresh server first
@@ -24,9 +36,19 @@ Always use port `8098` and `-env_path /tmp` for isolation.
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,13 +193,19 @@ To run the predefined tests
193
193
5. run `npm run test:gui` (a new window should appear)
194
194
6. click through the test spec-files and observe the tests done automatically in a newly opened browser instance
195
195
196
-
**as CLI tests**:
196
+
**as CLI tests (Cypress)**:
197
197
1. start a fresh visdom server instance on port `8098` , i.e. by just calling `visdom -port 8098` (Just to make sure another instance is not interfering with our test.)
198
198
2. run `npm run test:init`. This generates screenshots of all plots for the visual regression testing.
199
199
3. Adapt the code now to your needs.
200
200
4. run `npm run build`*or*`npm run dev` (enables automatic building)
201
201
5. run `npm run test`
202
202
203
+
**using Playwright (E2E tests)**:
204
+
1. start a fresh visdom server instance on port `8098` using your environment's Python, i.e. `python -m visdom.server -port 8098 -env_path playwright/tmp` (make sure no other instances interfere).
205
+
2. run `npx playwright install chromium` on first setup to install the browser.
206
+
3. run `npm run build`*or*`npm run dev` to compile the frontend code.
207
+
4. run the Playwright test suite: `npm run test:pw`
208
+
203
209
## Issues
204
210
We use GitHub issues to track public bugs. Please ensure your description is
205
211
clear and has sufficient instructions to be able to reproduce the issue.
-[`vis.dual_axis_lines`](#visdual_axis_lines) : double y axis line plots
301
307
-[`vis.graph`](#visgraph) : network graphs
302
308
@@ -353,6 +359,34 @@ The following `opts` are supported:
353
359
> **Note** You can use alt on an image pane to view the x/y coordinates of the cursor. You can also ctrl-scroll to zoom, alt scroll to pan vertically, and alt-shift scroll to pan horizontally. Double click inside the pane to restore the image to default.
354
360
355
361
362
+
#### vis.image_heatmap
363
+
364
+
This function overlays a saliency or attention heatmap on top of an image. It takes a `CxHxW` or `HxW` array `img` (uint8 or float) and an `HxW` float array `heatmap` with values in `[0, 1]`. The blending is per-pixel — pixels where the heatmap is near zero stay close to the original image, so a zero-gradient background does not get tinted by the colormap.
365
+
366
+
```python
367
+
import numpy as np
368
+
from visdom import Visdom
369
+
370
+
viz = Visdom()
371
+
372
+
# img: CxHxW uint8 or float in [0, 1]
373
+
# heatmap: HxW float in [0, 1] — e.g. from a saliency method or attention map
Any attribution method that produces an `HxW` numpy array works — gradient saliency, GradCAM, SHAP, or a hand-computed attention map.
378
+
379
+
The following `opts` are supported:
380
+
381
+
-`alpha`: blend strength (`float` in `[0, 1]`; default = `0.5`). Higher values make the heatmap more visible.
382
+
-`colormap`: matplotlib colormap name (`string`; default = `'jet'`). Falls back to a blue-red gradient if matplotlib is not installed.
383
+
-`caption`: caption for the image pane
384
+
-`jpgquality`: JPG quality (`number` 0-100). If set, the result is encoded as JPEG. Otherwise PNG.
385
+
-`normalize`: normalize the image to `[0, 1]` before blending (`boolean`; default = `False`)
386
+
387
+
> **Note**`heatmap` accepts any finite float range. Values outside `[0, 1]` are rescaled automatically via min-max normalization, so methods like SHAP or Integrated Gradients that return signed or unnormalized values work without any pre-processing. NaN maps to 0; infinite values are clamped to the `[0, 1]` boundary.
388
+
389
+
356
390
#### vis.images
357
391
358
392
This function draws a list of `images`. It takes an input `B x C x H x W` tensor or a `list of images` all of the same size. It makes a grid of images of size (B / nrow, nrow).
@@ -548,6 +582,57 @@ The following `opts` are supported:
548
582
-`opts.traceopts` : `dict` mapping trace names or indices to `dict`s of additional options that plot.ly accepts for a trace.
549
583
-`opts.webgl` : use WebGL for plotting (`boolean`; default = `false`). It is faster if a plot contains too many points. Use sparingly as browsers won't allow more than a couple of WebGL contexts on a single page.
550
584
585
+
#### vis.roc_curve
586
+
This function draws a ROC curve for binary classification.
587
+
588
+
It accepts either:
589
+
- raw binary labels and scores via `y_true` and `y_score`, or
590
+
- precomputed curve points via `fpr` and `tpr`.
591
+
592
+
The following `opts` are supported:
593
+
-`opts.title` : plot title (`string`; default includes ROC-AUC)
594
+
-`opts.legend` : two legend labels for curve and baseline (`list`)
This function draws named machine-learning metrics as line plots. It accepts a mapping from metric names to scalar values or equal-length 1D series and forwards to [`vis.line`](#visline).
This function draws a stem plot. It takes as input an `N` or `NxM` tensor
@@ -578,6 +663,32 @@ The following `opts` are supported:
578
663
-`opts.layoutopts` : `dict` of any additional options that the graph backend accepts for a layout. For example `layoutopts = {'plotly': {'legend': {'x':0, 'y':0}}}`.
579
664
-`opts.nancolor` : color for plotting `NaN`s. If this is `None`, `NaN`s will be plotted as transparent. (`string`; default = `None`)
580
665
666
+
#### vis.confusion_matrix
667
+
This function draws a confusion matrix for classification evaluation.
668
+
669
+
It accepts either:
670
+
- raw label vectors via `y_true` and `y_pred`, or
671
+
- a precomputed confusion matrix via `cm`.
672
+
673
+
Optional normalization can be applied with the `normalize` parameter:
674
+
-`'true'`: normalize by row (actual class)
675
+
-`'pred'`: normalize by column (predicted class)
676
+
-`'all'`: normalize by total count
677
+
678
+
An existing confusion matrix window can be modified with the `update` parameter:
679
+
-`'replace'`: redraw the whole matrix in the window given by `win`
680
+
-`'remove'`: delete the window given by `win`
681
+
682
+
The following `opts` are supported:
683
+
684
+
-`opts.title` : plot title (`string`; default = `Confusion Matrix`)
-`opts.showCounts` : show raw counts in cells (`bool`; default = `True`)
689
+
-`opts.showPercent` : show percentages in cells (`bool`; default = `True` when normalized, `False` otherwise)
690
+
-`opts.layoutopts` : `dict` of any additional options that the graph backend accepts for a layout.
691
+
581
692
#### vis.bar
582
693
This function draws a regular, stacked, or grouped bar plot. It takes as
583
694
input an `N` or `NxM` tensor `X` that specifies the height of each of the
@@ -696,6 +807,27 @@ The following `opts` are supported:
696
807
-`opts.opacity`: opacity of polygons (`number` between 0 and 1)
697
808
-`opts.layoutopts` : `dict` of any additional options that the graph backend accepts for a layout. For example `layoutopts = {'plotly': {'legend': {'x':0, 'y':0}}}`.
698
809
810
+
#### vis.sankey
811
+
This function draws a Sankey (flow) diagram. Flows are defined by three
812
+
equal-length arrays:
813
+
814
+
-`source`: source node index of each link (`N` array of ints)
815
+
-`target`: target node index of each link (`N` array of ints)
816
+
-`value` : magnitude of each link (`N` array of non-negative numbers)
817
+
818
+
`labels` is an optional list of node names. If omitted, nodes are referenced
819
+
by their index alone.
820
+
821
+
The following `opts` are supported:
822
+
823
+
-`opts.labels` : list of node labels (alternative to the `labels` arg)
824
+
-`opts.pad` : node padding in px (`number`; default = 15)
825
+
-`opts.thickness` : node thickness in px (`number`; default = 20)
826
+
-`opts.orientation`: `'h'` (default) or `'v'`
827
+
-`opts.nodecolor` : node color(s) (`string` or list of strings)
828
+
-`opts.linkcolor` : link color(s) (`string` or list of strings)
829
+
-`opts.layoutopts` : `dict` of any additional options that the graph backend accepts for a layout.
830
+
699
831
#### vis.dual_axis_lines
700
832
This function will create a line plot using plotly with different Y-Axis.
701
833
@@ -857,7 +989,7 @@ visdom is Apache 2.0 licensed, as found in the LICENSE file.
857
989
Support for Lua Torch was deprecated following `v0.1.8.4`. If you'd like to use torch support, you'll need to download that release. You can follow the usage instructions there, but it is no longer officially supported.
858
990
859
991
## Contributing
860
-
See guidelines for contributing [here.](./CONTRIBUTING.md)
992
+
See guidelines for contributing and running E2E/visual tests (Cypress and Playwright) [here.](./CONTRIBUTING.md)
861
993
862
994
## Acknowledgments
863
995
Visdom was inspired by tools like [display](https://github.com/szym/display) and relies on [Plotly](https://plot.ly/) as a plotting front-end.
0 commit comments