Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3682c26

Browse files
Add unit tests
1 parent b343a71 commit 3682c26

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This file makes `coverage run -m unittest discover` discover tests.

tests/test_color_picker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
# Copyright 2023 Inria
6+
7+
import unittest
8+
9+
from uplot.color_picker import ColorPicker
10+
11+
12+
class TestColorPicker(unittest.TestCase):
13+
def test_color_picker(self):
14+
picker = ColorPicker()
15+
first_color = picker.get_next_color()
16+
second_color = picker.get_next_color()
17+
self.assertNotEqual(first_color, second_color)
18+
19+
picker.reset()
20+
reset_color = picker.get_next_color()
21+
self.assertEqual(first_color, reset_color)

tests/test_generate_html.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
# Copyright 2023 Inria
6+
7+
import unittest
8+
9+
import numpy as np
10+
11+
from uplot.generate_html import generate_html
12+
13+
14+
class TestGenerateHtml(unittest.TestCase):
15+
def setUp(self):
16+
t = np.linspace(0.0, 1.0, 10)
17+
self.data = [t, np.exp(0.42 * t)]
18+
self.t = t
19+
20+
def test_generate_html(self):
21+
test_title = "Test plot"
22+
opts = {
23+
"width": 1921,
24+
"height": 601,
25+
"title": test_title,
26+
"scales": {"x": {"time": False}},
27+
"series": [{}, {"stroke": "red"}],
28+
}
29+
html = generate_html(
30+
opts,
31+
self.data,
32+
resize=False,
33+
)
34+
self.assertIn("1921", html)
35+
self.assertIn("601", html)
36+
self.assertIn(test_title, html)
37+
38+
def test_resize(self):
39+
opts = {"series": [{}, {"stroke": "red"}]}
40+
html = generate_html(opts, self.data, resize=True)
41+
self.assertIn('window.addEventListener("resize', html)

tests/test_plot.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
# Copyright 2023 Inria
6+
7+
import unittest
8+
9+
import numpy as np
10+
11+
import uplot
12+
13+
14+
class TestPlot(unittest.TestCase):
15+
def test_plot(self):
16+
t = np.linspace(0.0, 1.0, 10)
17+
data = [
18+
t,
19+
np.exp(0.42 * t),
20+
]
21+
opts = {
22+
"width": 1920,
23+
"height": 600,
24+
"title": "Simple plot",
25+
"scales": {
26+
"x": {
27+
"time": False,
28+
},
29+
},
30+
"series": [
31+
{},
32+
{
33+
"stroke": "red",
34+
"fill": "rgba(255,0,0,0.1)",
35+
},
36+
],
37+
}
38+
uplot.plot(opts, data)

tox.ini

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[tox]
2+
isolated_build = True
3+
envlist =
4+
coverage
5+
lint
6+
py{38,39,310,311,312}-{linux,macos,windows}
7+
8+
[gh-actions]
9+
python =
10+
3.8: py38
11+
3.9: py39
12+
3.10: py310
13+
3.11: py311
14+
3.12: py312
15+
16+
[testenv]
17+
deps =
18+
pytest >=7.1.2
19+
commands =
20+
pytest tests
21+
22+
[testenv:coverage]
23+
deps =
24+
coverage >=5.5
25+
commands =
26+
coverage erase
27+
coverage run -m unittest discover
28+
coverage report --include="uplot/**"
29+
30+
[testenv:lint]
31+
deps =
32+
black >=22.10.0
33+
mypy >=1.10.0
34+
pylint >=2.8.2
35+
pytype >=2023.5.24
36+
ruff >=0.4.3
37+
types-setuptools >=65.6.0.2
38+
commands =
39+
black --check --diff uplot
40+
mypy uplot --ignore-missing-imports
41+
pylint uplot --exit-zero --rcfile={toxinidir}/tox.ini
42+
pytype uplot
43+
ruff check uplot

0 commit comments

Comments
 (0)