def is_expression_type(self):
return False
-class Var:
+class Var:
def __init__(self, name):
self.name = name
def is_expression_type(self):
def __repr__(self):
return self.name
-class Set(BaseExpression):
+class Set(BaseExpression):
def __init__(self, initialize=None):
super().__init__("set", initialize)
def is_expression_type(self):
def test_beforeChild(self):
def before(node, child, child_idx):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, [child]
walker = StreamBasedExpressionVisitor(beforeChild=before)
def test_initializeWalker_beforeChild(self):
def before(node, child, child_idx):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, child
def initialize(expr):
def test_beforeChild_exitNode(self):
def before(node, child, child_idx):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, [child]
def exit(node, data):
data.insert(0, str(node))
return data
- walker = StreamBasedExpressionVisitor(beforeChild=before, exitNode=exit)
+ walker = StreamBasedExpressionVisitor(beforeChild=before,
+ exitNode=exit)
ans = self.walk(walker, self.e)
m = self.m
ref = [
i = [0]
def before(node, child, child_idx):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, [child]
def enter(node):
def test_old_beforeChild(self):
def before(node, child):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, [child]
os = StringIO()
def accept(node, data, child_result, child_idx):
return data + child_result
- walker = StreamBasedExpressionVisitor(enterNode=enter, acceptChildResult=accept)
+ walker = StreamBasedExpressionVisitor(enterNode=enter,
+ acceptChildResult=accept)
# 4 operators, 6 leaf nodes
self.assertEqual(self.walk(walker, self.e), 10)
def test_enterNode(self):
# This is an alternative way to implement the beforeChild test:
def enter(node):
- if type(node) in nonpyomo_leaf_types or not node.is_expression_type():
+ if type(node) in nonpyomo_leaf_types or \
+ not node.is_expression_type():
return (), [node]
return node.args, []
def test_enterNode_noLeafList(self):
# This is an alternative way to implement the beforeChild test:
def enter(node):
- if type(node) in nonpyomo_leaf_types or not node.is_expression_type():
+ if type(node) in nonpyomo_leaf_types or \
+ not node.is_expression_type():
return (), node
return node.args, []
def test_enterNode_withFinalize(self):
# This is an alternative way to implement the beforeChild test:
def enter(node):
- if type(node) in nonpyomo_leaf_types or not node.is_expression_type():
+ if type(node) in nonpyomo_leaf_types or \
+ not node.is_expression_type():
return (), node
return node.args, []
else:
return [result]
- walker = StreamBasedExpressionVisitor(enterNode=enter, finalizeResult=finalize)
+ walker = StreamBasedExpressionVisitor(enterNode=enter,
+ finalizeResult=finalize)
m = self.m
ans = self.walk(walker, self.e)
def before(node, child, child_idx):
counts[0] += 1
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, None
def accept(node, data, child_result, child_idx):
def before(node, child):
counts[0] += 1
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, None
def accept(node, data, child_result):
ans = []
def before(node, child, child_idx):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, child
def accept(node, data, child_result, child_idx):
ans = []
def before(node, child, child_idx):
- if type(child) in nonpyomo_leaf_types or not child.is_expression_type():
+ if type(child) in nonpyomo_leaf_types or \
+ not child.is_expression_type():
return False, child
def accept(node, data, child_result, child_idx):
self.ans.append("Exit %s" % (name(node)))
def beforeChild(self, node, child, child_idx):
- self.ans.append("Before %s (from %s)" % (name(child), name(node)))
+ self.ans.append("Before %s (from %s)" % (name(child),
+ name(node)))
def acceptChildResult(self, node, data, child_result, child_idx):
self.ans.append("Accept into %s" % (name(node)))
def afterChild(self, node, child, child_idx):
- self.ans.append("After %s (from %s)" % (name(child), name(node)))
+ self.ans.append("After %s (from %s)" % (name(child),
+ name(node)))
def finalizeResult(self, result):
self.ans.append("Finalize")
self.ans.append("Exit %s" % (name(node)))
def beforeChild(self, node, child):
- self.ans.append("Before %s (from %s)" % (name(child), name(node)))
+ self.ans.append("Before %s (from %s)" % (name(child),
+ name(node)))
def acceptChildResult(self, node, data, child_result):
self.ans.append("Accept into %s" % (name(node)))
def afterChild(self, node, child):
- self.ans.append("After %s (from %s)" % (name(child), name(node)))
+ self.ans.append("After %s (from %s)" % (name(child),
+ name(node)))
def finalizeResult(self, result):
self.ans.append("Finalize")
return data + 1
return StreamBasedExpressionVisitor(
- beforeChild=before, acceptChildResult=accept, enterNode=enter, exitNode=exit
+ beforeChild=before, acceptChildResult=accept,
+ enterNode=enter, exitNode=exit
)
def run_walker(self, walker):
# We have not yet determined how to trigger the
# RecursionError on PyPy
cases = [(0, "")]
- elif os.environ.get('GITHUB_ACTIONS', '') and sys.platform.startswith('win'):
+ elif os.environ.get('GITHUB_ACTIONS', '') and \
+ sys.platform.startswith('win'):
# The test for handling RecursionError appears to fail
# inexplicably on GHA/Windows under pytest: the
# RecursionError that is supposed to be raised is not