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
5 changes: 4 additions & 1 deletion sofar/sofa.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def __setattr__(self, name: str, value):
"only data (e.g., to repair corrupted SOFA data)."))

# convert to numpy array or scalar
if not isinstance(value, (str, dict, np.ndarray)) \
if isinstance(value, str):
if self._convention.get(name, {}).get("type") == "string":
value = np.str_(value)
elif not isinstance(value, (dict, np.ndarray)) \
and name != "protected":
value = np.atleast_2d(value)
if value.size == 1:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sofa.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ def test_inspect(capfd):
assert out == "".join(text)


def test_inspect_scalar_string_variable(capfd):
sofa = sf.Sofa("GeneralTF")
sofa.add_variable("TestString", "test", "string", "S")
sofa.inspect()
assert "TestString : test" in capfd.readouterr().out

sofa.TestString = "updated"
sofa.inspect()
assert "TestString : updated" in capfd.readouterr().out


def test_add_entry():

sofa = sf.Sofa("GeneralTF")
Expand Down
Loading