From 7cb5ba1347cba526e71f878a1b262c35e5883df5 Mon Sep 17 00:00:00 2001 From: Filippo Luca Ferretti Date: Mon, 11 Nov 2024 17:47:04 +0100 Subject: [PATCH] Improve forcing of `is_urdf` argument --- src/rod/sdf/sdf.py | 33 +++++++++++++++------------------ tests/test_urdf_parsing.py | 5 +++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/rod/sdf/sdf.py b/src/rod/sdf/sdf.py index 74e133d..1eed007 100644 --- a/src/rod/sdf/sdf.py +++ b/src/rod/sdf/sdf.py @@ -69,24 +69,21 @@ def load(sdf: pathlib.Path | str, is_urdf: bool | None = None) -> Sdf: # Check if the input is a string path. is_str_path = getattr(sdf, "__len__", lambda: MAX_PATH + 1)() <= MAX_PATH - if is_urdf is not None: - sdf_string = sdf - else: - match sdf: - # Case 1: Handle SDF/URDF string. - case str() if not is_str_path: - sdf_string = sdf - is_urdf = " None: with pytest.raises(RuntimeError): _ = rod.Sdf.load(sdf=urdf_path.read_text(), is_urdf=False) + # Check that it fails is is_urdf=True and the resource is a non-existing path + with pytest.raises(FileNotFoundError): + _ = rod.Sdf.load(sdf="/non/existing/path", is_urdf=None) + _ = rod.Sdf.load(sdf="/non/existing/path", is_urdf=False) + # The following instead should succeed _ = rod.Sdf.load(sdf=urdf_path, is_urdf=None) _ = rod.Sdf.load(sdf=urdf_path, is_urdf=True)