Skip to content

Commit

Permalink
fixed bug in which only single element was still being made into a mm…
Browse files Browse the repository at this point in the history
…ul modified tag...
  • Loading branch information
leerobert committed Sep 28, 2016
1 parent 55a7d26 commit bdd2650
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mml2sympy/mml.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
MML_SYM = 'mi'

ADD_OPS = ['+', '-']
MUL_OPS = ['/', '*']
EQ_OPS = ['=']
SIMILAR_OPS = {
'+': ADD_OPS,
'-': ADD_OPS,
'=': EQ_OPS,
'*': MUL_OPS,
'/': MUL_OPS,
}

ADD_OPS_TAG = 'madd'
Expand Down Expand Up @@ -197,10 +200,12 @@ def modify(mmltree):
else: # just one element so append as leaf -- extend since list
op.extend(grouped_elems)
modified_tree.append(op)
else: # no op elements so must be multiple mn/mi
elif len(all_elements) > 1: # no op elements so must be multiple mn/mi
mmul = objectify.Element(MUL_OPS_TAG)
mmul.extend(all_elements)
modified_tree.append(mmul)
else: # only one element so just leave it alone
modified_tree.extend(all_elements)

# remove namespaces from objectify and return modified tree
objectify.deannotate(modified_tree, cleanup_namespaces=True)
Expand All @@ -213,6 +218,8 @@ def _modified_tag_for(element):
tag = ADD_OPS_TAG
elif element.text.strip() in EQ_OPS:
tag = EQ_OPS_TAG
elif element.text.strip() in MUL_OPS:
tag = MUL_OPS_TAG
else:
raise Exception("modified tag not found for: {0}".format(element))

Expand Down
10 changes: 10 additions & 0 deletions mml2sympy/tests/test_mml.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def test_modify():
assert hasattr(modified_tree.meq, 'madd')
assert hasattr(modified_tree.meq.madd, 'mmul')

modify_mml = '''
<mtd>
<mn> 27 </mn>
</mtd>
'''
tree = mml2tree(modify_mml)
modified_tree = modify(tree)
assert hasattr(modified_tree, 'mn')
assert modified_tree.countchildren() == 1


def test_table2trees():
mtable_mml = '''
Expand Down

0 comments on commit bdd2650

Please sign in to comment.