From 1f9ebe926f4526284c5d3c179d60d35a24e3856a Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Sat, 10 Jan 2026 17:37:04 +0100 Subject: [PATCH] add tests --- pyproject.toml | 22 +++++++++++++++++----- src/fvr/geom.py | 6 ++++-- src/fvr/typing.py | 5 ++--- tests/test_structure.py | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 tests/test_structure.py diff --git a/pyproject.toml b/pyproject.toml index 65ac971..12b09eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,3 @@ -[build-system] -requires = ["setuptools", "setuptools-scm"] -build-backend = "setuptools.build_meta" - [project] name = "fvr" dynamic = ["version"] @@ -34,7 +30,7 @@ dependencies = [ [project.optional-dependencies] docs = ["sphinx", "furo"] -test = ["pytest"] +test = ["pytest>=9.0"] dev = [ # recursive optional dependencies "fvr[docs,test]", @@ -51,6 +47,10 @@ dev = [ # "pipdeptree", ] +[build-system] +requires = ["setuptools", "setuptools-scm"] +build-backend = "setuptools.build_meta" + [tool.setuptools.dynamic] version = {attr = "fvr.__version__"} @@ -58,3 +58,15 @@ version = {attr = "fvr.__version__"} where = ["src"] include = ["fvr*"] # namespaces = false + +[tool.pytest] +addopts = ["--doctest-modules", "--doctest-continue-on-failure"] +testpaths = [ + "tests", + "src/fvr", +] +filterwarnings = [ + # "ignore::DeprecationWarning", + # in ezdxf/queryparser.py + "ignore:'.*' deprecated - use '.*':DeprecationWarning", +] diff --git a/src/fvr/geom.py b/src/fvr/geom.py index e635181..085cfe1 100644 --- a/src/fvr/geom.py +++ b/src/fvr/geom.py @@ -25,8 +25,10 @@ class polygon: r"""Determine the area of a simple polygon. Example: - >>> fvr.geom.polygon([[0, 0], [0, 1], [1, 1], [1, 0]]).area - >>> fvr.geom.polygon('[[0, 0], [0, 1], [1, 1], [1, 0]]').area + >>> polygon([[0, 0], [0, 1], [1, 1], [1, 0]]).area + 1.0 + >>> polygon('[[0, 0], [0, 1], [1, 1], [1, 0]]').area + 1.0 Shoelace formula, Gauss's area formula, surveyor's formula diff --git a/src/fvr/typing.py b/src/fvr/typing.py index 37b4e22..1cad337 100644 --- a/src/fvr/typing.py +++ b/src/fvr/typing.py @@ -1,5 +1,4 @@ from collections.abc import Sequence -import numpy as np -from numpy.typing import NDArray +import numpy.typing -type FloatArray = Sequence[float] | NDArray[np.float64] +type FloatArray = Sequence[float] | numpy.typing.NDArray[numpy.float64] diff --git a/tests/test_structure.py b/tests/test_structure.py new file mode 100644 index 0000000..e71914e --- /dev/null +++ b/tests/test_structure.py @@ -0,0 +1,20 @@ +"""Test of structure module. + +""" +import unittest +import fvr.structure + +class TestStructureBeam(unittest.TestCase): + def setUp(self): + self.obj = fvr.structure.beam(1, 2, 3, 4, 5) + def test_volume(self): + self.assertEqual(self.obj.V, 12, 'incorrect volume after creation') + def test_volume_a(self): + self.obj.A = 6 + self.assertEqual(self.obj.V, 24, 'incorrect volume after changing A') + def test_volume_l(self): + self.obj.L = 7 + self.assertEqual(self.obj.V, 21, 'incorrect volume after changing L') + +if __name__ == '__main__': + unittest.main()