def analyze(self, specification_path): if not specification_path: logging.error('Please provide a specification file!') return False if specification_path[specification_path.rindex('.'):].strip().lower( ) != '.spec': logging.error('Specification file needs to have .spec extension.') return False try: spec_file = open(specification_path) spec_name = self.get_specification_name(specification_path) logging.info('************ ' + spec_name + ' ***************') logging.info('Checking the syntax') spec_content = spec_file.readlines() stx_chkr = SyntaxChecker() message = stx_chkr.check(spec_name, spec_content) logging.info('Parsing the specification') parser = Parser() specification = parser.parse(spec_name, spec_content) logging.info('Checking the well-formedness of the specification') compliance_checker = ComplianceChecker() compliance_checker.check(specification) logging.info('Checking convergence') convergence_checker = ConvergenceChecker() convergence_checker.check(specification) logging.info('Checking safety') safety_checker = SafetyChecker() safe, failed = safety_checker.check(specification) if safe: logging.info('The specification is safe!!!') else: #generate tokens here raise Exception # else: # logging.info('starting token generation') # for failure in failed: # #failure is a pair of procedure names which failed stability check # token_generator = TokenGenerator() # tokens = token_generator.generate_tokens(specification, failed) # logging.info('The tokens are as follows ::\n' + token_generator.convert_to_text(tokens)) # if tokens: # logging.info('The possible token(s) for ensuring stability of ' + failure[0].name + ' and ' +failure[1].name +' ::\n' + str(tokens)+ '\n') # else: # logging.info('Not able to determine a token for the stability of ' + failure[0].name + ' and ' +failure[1].name) except Exception as e: logging.error(str(e) + '\n') return False return True
def test_check_check_invariant_called(self, mock): checker = ComplianceChecker() spec = self.get_compliant_spec() checker.check(spec) assert mock.called == True