def _do_test(self, test_name:str, spec:str, quantified_signal_names_expected:set, expected_result): print(test_name) result = yacc.parse(spec) section_name_to_data = dict(result) for (k, v) in result: print(k, v) for section_name, data in section_name_to_data.items(): actual = len(data) expected = expected_result[section_name] assert actual == expected, '{actual} != {expected}: {section}: {section_data}'.format( actual=actual, expected=expected, section=section_name, section_data=str(section_name_to_data[section_name])) quantified_signals_finder = QuantifiedSignalsFinderVisitor() all_properties = self._get_all_properties(section_name_to_data) [quantified_signals_finder.dispatch(p) for p in all_properties] quantified_signal_names = set(map(lambda qs: qs.name, quantified_signals_finder.quantified_signals)) assert quantified_signal_names_expected == quantified_signal_names, \ 'expected {0}, got {1}'.format(quantified_signal_names_expected, quantified_signal_names)
def _do_test(self, test_name: str, spec: str, quantified_signal_names_expected: set, expected_result): print(test_name) result = yacc.parse(spec) section_name_to_data = dict(result) for (k, v) in result: print(k, v) for section_name, data in section_name_to_data.items(): actual = len(data) expected = expected_result[section_name] assert actual == expected, '{actual} != {expected}: {section}: {section_data}'.format( actual=actual, expected=expected, section=section_name, section_data=str(section_name_to_data[section_name])) quantified_signals_finder = QuantifiedSignalsFinderVisitor() all_properties = self._get_all_properties(section_name_to_data) [quantified_signals_finder.dispatch(p) for p in all_properties] quantified_signal_names = set( map(lambda qs: qs.name, quantified_signals_finder.quantified_signals)) assert quantified_signal_names_expected == quantified_signal_names, \ 'expected {0}, got {1}'.format(quantified_signal_names_expected, quantified_signal_names)
def tests_all(self): result = yacc.parse(test_string) section_name_to_data = dict(result) for (k, v) in result: print(k, v) expected_results = {'INPUT_VARIABLES':9, 'OUTPUT_VARIABLES':18, 'SYS_FAIRNESS':5, 'SYS_TRANSITIONS':5, 'SYS_INITIAL':18, 'ENV_FAIRNESS':2, 'ENV_TRANSITIONS':3, 'ENV_INITIAL':9} for section_name, data in section_name_to_data.items(): actual = len(data) expected = expected_results[section_name] assert actual == expected, '{actual} != {expected}: {section}'.format( actual = actual, expected =expected, section = section_name)
def tests_all(self): result = yacc.parse(test_string) section_name_to_data = dict(result) for (k, v) in result: print(k, v) expected_results = { 'INPUT_VARIABLES': 9, 'OUTPUT_VARIABLES': 18, 'SYS_FAIRNESS': 5, 'SYS_TRANSITIONS': 5, 'SYS_INITIAL': 18, 'ENV_FAIRNESS': 2, 'ENV_TRANSITIONS': 3, 'ENV_INITIAL': 9 } for section_name, data in section_name_to_data.items(): actual = len(data) expected = expected_results[section_name] assert actual == expected, '{actual} != {expected}: {section}'.format( actual=actual, expected=expected, section=section_name)
t[0] = t[2] def p_expression_number(t): 'expression : NUMBER' t[0] = t[1] def p_expression_name(t): 'expression : NAME' try: t[0] = names[t[1]] except LookupError: print("Undefined name '%s'" % t[1]) t[0] = 0 def p_expression_ogo(p): '''expression : PI''' p[0] = 314 def p_error(t): print("Syntax error at '%s'" % t.value) import third_party.ply.yacc as yacc yacc.yacc() while 1: try: s = input('calc > ') # Use raw_input on Python 2 except EOFError: break yacc.parse(s)
def p_expression_name(t): 'expression : NAME' try: t[0] = names[t[1]] except LookupError: print("Undefined name '%s'" % t[1]) t[0] = 0 def p_expression_ogo(p): '''expression : PI''' p[0] = 314 def p_error(t): print("Syntax error at '%s'" % t.value) import third_party.ply.yacc as yacc yacc.yacc() while 1: try: s = input('calc > ') # Use raw_input on Python 2 except EOFError: break yacc.parse(s)