Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_exp_result(self):
def print_exp_res():
res = "\n"
res += " cat < {}".format(exp_res_file) + "\n"
res += json.dumps(dic, indent=2) + "\n"
res += "EOF" + "\n"
res += "\n"
return res
self.maxDiff = None
parser = RPSLViaParser()
ast = parser.parse(line, rule_name="start")
dic = asjson(ast)
if exp_res:
self.assertDictEqual(dic, exp_res, "\n\nTo fix it:\n{}".format(print_exp_res()))
return
print(print_exp_res())
def _test_syntax(self, line):
parser = RPSLViaParser()
ast = parser.parse(line, rule_name="start")
# Build the reverse statement starting from the result of the parser
# and check that it matches the input line.
# Do this only when there are no actions in the original line, too
# much effort to rebuild the action list.
if "action" in line:
return
dic = asjson(ast)
from_to = "from" if dic["action"] == "import-via:" else "to"
accept_announce = "accept" if dic["action"] == "import-via:" else "announce"
s = "{action} {afi} {rules} {filter}".format(
action=dic["action"],
afi="afi {afi_list}".format(
afi_list=" ".join([afi for afi in dic["afi"]])
) if dic["afi"] else "",
rules=" ".join([
"{via} {from_to} {peers}".format(
from_to=from_to,
via="{intermediate_as} {router}".format(
intermediate_as=rule["via"]["intermediate_as"],
router="{peer} {at} {local}".format(
peer=rule["via"]["router"]["peer_router"]
with open(filename) as f:
text = f.read()
parser = CompositeModelExpressionParser()
return parser.parse(text, rule_name=start, filename=filename, **kwargs)
if __name__ == '__main__':
import json
from tatsu.util import asjson
ast = generic_main(main, CompositeModelExpressionParser, name='CompositeModelExpression')
print('AST:')
print(ast)
print()
print('JSON:')
print(json.dumps(asjson(ast), indent=2))
print()
with open(filename) as f:
text = f.read()
parser = CalcParser()
return parser.parse(text, startrule, filename=filename, **kwargs)
if __name__ == '__main__':
import json
from tatsu.util import asjson
ast = generic_main(main, CalcParser, name='Calc')
print('AST:')
print(ast)
print()
print('JSON:')
print(json.dumps(asjson(ast), indent=2))
print()
def asjson(self):
return asjson(self)
with open(filename) as f:
text = f.read()
parser = GameLogicParser()
return parser.parse(text, rule_name=start, filename=filename, **kwargs)
if __name__ == '__main__':
import json
from tatsu.util import asjson
ast = generic_main(main, GameLogicParser, name='GameLogic')
print('AST:')
print(ast)
print()
print('JSON:')
print(json.dumps(asjson(ast), indent=2))
print()
with open(filename) as f:
text = f.read()
parser = RegexParser()
return parser.parse(text, startrule, filename=filename, **kwargs)
if __name__ == '__main__':
import json
from tatsu.util import asjson
ast = generic_main(main, RegexParser, name='Regex')
print('AST:')
print(ast)
print()
print('JSON:')
print(json.dumps(asjson(ast), indent=2))
print()
with open(filename) as f:
text = f.read()
parser = CLDataTypeParser()
return parser.parse(text, rule_name=start, filename=filename, **kwargs)
if __name__ == '__main__':
import json
from tatsu.util import asjson
ast = generic_main(main, CLDataTypeParser, name='CLDataType')
print('AST:')
print(ast)
print()
print('JSON:')
print(json.dumps(asjson(ast), indent=2))
print()