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
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ fixable = ["ALL"]
quote-style = "double"
indent-style = "space"
docstring-code-format = true

[dependency-groups]
dev = [
"numpy>=2.0.2",
"pytest>=8.4.2",
]
20 changes: 15 additions & 5 deletions tests/unit/test_urdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
from urchin import URDF, Joint, Link, Material, Transmission


def test_urchin(tmpdir):
outfn = tmpdir.mkdir("urdf").join("ur5.urdf").strpath

# Load
u = URDF.load("tests/data/ur5/ur5.urdf")
def _test_urdf(u,outfn):

assert isinstance(u, URDF)
for j in u.joints:
Expand Down Expand Up @@ -109,3 +105,17 @@ def test_urchin(tmpdir):
assert isinstance(x, URDF)
x = x.copy(scale=[1, 1, 3])
assert isinstance(x, URDF)

def test_urchin(tmpdir):
outfn = tmpdir.mkdir("urdf").join("ur5.urdf").strpath
# Load
u = URDF.load("tests/data/ur5/ur5.urdf")

_test_urdf(u, outfn)

def test_urchin_pathlib(tmpdir):
from pathlib import Path
outfn = Path(tmpdir.mkdir("urdf").join("ur5.urdf"))
p = "tests/data/ur5/ur5.urdf"
u = URDF.load(Path(p))
_test_urdf(u, outfn)
7 changes: 7 additions & 0 deletions urchin/urdf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
from pathlib import Path
import time
from collections import OrderedDict
from typing import IO, Mapping, Optional, Sequence, Union, cast
Expand Down Expand Up @@ -1092,6 +1093,9 @@ def save(self, file_obj: Union[str, IO[bytes], IO[str]]) -> None:
None
Nothing. Writes the URDF XML to ``file_obj``.
"""
if isinstance(file_obj, Path):
file_obj = str(file_obj.expanduser().resolve()) # https://github.com/fishbotics/urchin/issues/35

if isinstance(file_obj, str):
path, _ = os.path.split(file_obj)
else:
Expand Down Expand Up @@ -1207,6 +1211,9 @@ def load(
urdf : :class:`.URDF`
The parsed URDF.
"""
if isinstance(file_obj, Path):
file_obj = str(file_obj.expanduser().resolve()) # https://github.com/fishbotics/urchin/issues/35

if isinstance(file_obj, str):
if os.path.isfile(file_obj):
parser = ET.XMLParser(remove_comments=True, remove_blank_text=True)
Expand Down
Loading