Skip to content

Commit

Permalink
Sequence diagram: module attribute #4
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Jun 24, 2021
1 parent dbf48f0 commit f5434f4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dial/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _call_callback(self, interpreter, token, *args, **kw):
try:
self.callback(interpreter, *args, **kw)
except AttributeError as e:
raise BadAttribute(interpreter, token, e.args[0])
raise BadAttribute(interpreter, token, '.'.join(e.args))

def __call__(self, interpreter, token):
args = tuple(
Expand Down
5 changes: 3 additions & 2 deletions dial/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ def _attr(self, attr, value):

def _module_attr(self, module, attr, value):
self._ensuremodule(module)
value = value.strip()
if not hasattr(self.modules[module], attr):
raise AttributeError(module, attr)

setattr(self.modules[module], attr, value)
setattr(self.modules[module], attr, value.strip())

statemap = {
'start': {
Expand Down
35 changes: 25 additions & 10 deletions tests/test_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
from dial.interpreter import BadSyntax, BadAttribute


def test_sequence_moduleattr_error():
d = SequenceDiagram(Tokenizer())
s = '''# Sequence
foo.invalid: Foo
'''
with pytest.raises(BadAttribute) as e:
d.parse(s)
assert str(e.value) == '''\
File "String", Interpreter SequenceDiagram, line 2, col 16
Invalid attribute: foo.invalid.\
'''


def test_sequence_moduleattr():
d = SequenceDiagram(Tokenizer())
s = '''# Sequence
Expand All @@ -20,16 +33,7 @@ def test_sequence_moduleattr():
assert repr(d) == s[:-1]


def test_sequence_title():
d = SequenceDiagram(Tokenizer())
s = '''# Sequence
title: Foo Bar
foo -> bar: baz
'''
d.parse(s)
assert repr(d) == s[:-1]

def test_sequence_title_error():
d = SequenceDiagram(Tokenizer())
s = '''# Sequence
invalid: Foo Bar
Expand All @@ -44,6 +48,17 @@ def test_sequence_title():
'''


def test_sequence_title():
d = SequenceDiagram(Tokenizer())
s = '''# Sequence
title: Foo Bar
foo -> bar: baz
'''
d.parse(s)
assert repr(d) == s[:-1]


def test_sequence_calltext():
d = SequenceDiagram(Tokenizer())
s = '''# Sequence
Expand Down

0 comments on commit f5434f4

Please sign in to comment.