Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions spatialmath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@
import importlib.metadata

__version__ = importlib.metadata.version("spatialmath-python")
except:
pass
except importlib.metadata.PackageNotFoundError:
# running from a source checkout without an installed/editable
# spatialmath-python distribution -- e.g. importing straight from
# the repo root
__version__ = "unknown"
22 changes: 22 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import re
import unittest
from pathlib import Path

import spatialmath


class TestVersion(unittest.TestCase):
def test_version_is_a_non_empty_string(self):
self.assertIsInstance(spatialmath.__version__, str)
self.assertTrue(spatialmath.__version__)

def test_version_matches_pyproject(self):
pyproject = Path(__file__).parent.parent / "pyproject.toml"
match = re.search(r'^version\s*=\s*"([^"]+)"', pyproject.read_text(), re.MULTILINE)
self.assertIsNotNone(match, f"couldn't find a version in {pyproject}")
self.assertEqual(spatialmath.__version__, match.group(1))


# ---------------------------------------------------------------------------------------#
if __name__ == "__main__":
unittest.main()
Loading