Skip to content

Commit

Permalink
Fix warnings (#168)
Browse files Browse the repository at this point in the history
* Replace directive.warn with logger.warning

* Fix property validation parsing
  • Loading branch information
joeced authored Mar 24, 2023
1 parent 9102348 commit 9c666d1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions sphinxcontrib/mat_documenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def parse_name(self):
self.name
).groups()
except AttributeError:
self.directive.warn(
logger.warning(
"invalid signature for auto%s (%r)" % (self.objtype, self.name)
)
return False
Expand Down Expand Up @@ -232,7 +232,7 @@ def get_object_members(self, want_all):
members.append((mname, self.get_attr(self.object, mname)))
except AttributeError:
if mname not in analyzed_member_names:
self.directive.warn(
logger.warning(
"missing attribute %s in object %s" % (mname, self.fullname)
)
elif self.options.inherited_members:
Expand Down Expand Up @@ -547,7 +547,7 @@ def generate(
"""
if not self.parse_name():
# need a module to import
self.directive.warn(
logger.warning(
"don't know which module to import for autodocumenting "
'%r (try placing a "module" or "currentmodule" directive '
"in the document, or giving an explicit module name)" % self.name
Expand Down Expand Up @@ -614,7 +614,7 @@ class MatModuleDocumenter(MatlabDocumenter, PyModuleDocumenter):
def parse_name(self):
ret = MatlabDocumenter.parse_name(self)
if self.args or self.retann:
self.directive.warn(
logger.warning(
"signature arguments or return annotation "
"given for automodule %s" % self.fullname
)
Expand Down Expand Up @@ -650,7 +650,7 @@ def get_object_members(self, want_all):
else:
raise AttributeError
except AttributeError:
self.directive.warn(
logger.warning(
"missing attribute mentioned in :members: or __all__: "
"module %s, attribute %s"
% (
Expand Down
2 changes: 2 additions & 0 deletions sphinxcontrib/mat_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ def _propspec(self, idx):
or self.tokens[idx][0] == Token.Literal.Number.Integer
or self._tk_eq(idx, (Token.Punctuation, "{"))
or self._tk_eq(idx, (Token.Punctuation, "}"))
or self._tk_eq(idx, (Token.Punctuation, "["))
or self._tk_eq(idx, (Token.Punctuation, "]"))
or self._tk_eq(idx, (Token.Punctuation, "."))
or self.tokens[idx][0] == Token.Literal.String
or self.tokens[idx][0] == Token.Name
Expand Down
15 changes: 15 additions & 0 deletions tests/test_data/ClassWithPropertyValidators.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
classdef ClassWithPropertyValidators < handle
properties
% The location
Location(1,3) double {mustBeReal, mustBeFinite}

% The label
Label(1,:) char {mustBeMember(Label,{'High','Medium','Low'})} = 'Low'

% The state
State(1,1) matlab.lang.OnOffSwitchState

% The report level
ReportLevel (1,1) string {mustBeMember(ReportLevel,["short","failed","full"])} = "full"
end
end
1 change: 1 addition & 0 deletions tests/test_matlabify.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def test_module(mod):
"ClassWithGetMethod",
"ClassWithLongPropertyDocstrings",
"ClassWithLongPropertyTrailingEmptyDocstrings",
"ClassWithPropertyValidators",
}
assert all_items == expected_items
assert mod.getter("__name__") in modules
Expand Down
12 changes: 12 additions & 0 deletions tests/test_parse_mfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,17 @@ def test_ClassWithLongPropertyDocstrings():
assert obj.properties["b"]["docstring"] == " Document this property\n"


def test_ClassWithPropertyValidators():
mfile = os.path.join(TESTDATA_ROOT, "ClassWithPropertyValidators.m")
obj = mat_types.MatObject.parse_mfile(
mfile, "ClassWithPropertyValidators", "test_data"
)
assert obj.name == "ClassWithPropertyValidators"
assert obj.properties["Location"]["docstring"] == " The location\n"
assert obj.properties["Label"]["docstring"] == " The label\n"
assert obj.properties["State"]["docstring"] == " The state\n"
assert obj.properties["ReportLevel"]["docstring"] == " The report level\n"


if __name__ == "__main__":
pytest.main([os.path.abspath(__file__)])

0 comments on commit 9c666d1

Please sign in to comment.