def serialize(self): from corejet.visualization import generateReportFromCatalogue generateReportFromCatalogue(self.catalogue, self.tmpdir)
def writeCoreJetReports(self, source, directory=None, filename='corejet.xml'): # corejet.robot registers CoreJet-adapters for Robot Framework tests # XXX: there should be a more dynamic way to configure plugin adapters try: import corejet.robot except ImportError: pass try: sourceType, sourceOptions = source.split(',', 1) except ValueError: # need more than 1 value to unpack sourceType = source.strip() sourceOptions = '' # Prepare output directory if directory is None: workingDir = os.getcwd() directory = os.path.join(workingDir, 'corejet') print "Writing CoreJet report to %s" % directory functionName = None for ep in pkg_resources.iter_entry_points('corejet.repositorysource'): if ep.name == sourceType and len(ep.attrs) > 0: functionName = "%s.%s" % (ep.module_name, ep.attrs[0],) break if not functionName: raise ValueError("Unknown CoreJet source type %s" % sourceType) sourceFunction = resolve(functionName) catalogue = sourceFunction(sourceOptions) # Set test time catalogue.testTime = datetime.datetime.now() # Find everything we've done so far testedStories = {} # story name -> {scenario name -> (scenario, info)} for suiteInfo in self._testSuites.values(): for caseInfo in suiteInfo.testCases: # look up the story for the test through adaptation: # - for @story-decorated test, the class implements IStory # - for others, the test case may have an adapter for IStory story = IStory(caseInfo.test, IStory(caseInfo.test.__class__, None)) if not story: continue scenarios = testedStories.setdefault(story.name.strip().lower(), {}) # XXX: Relying on _testMethodName here is not very good scenario = getattr(story, caseInfo.test._testMethodName).scenario scenarios[scenario.name.strip().lower()] = (scenario, caseInfo,) # Allocate a status to each scenario for epic in catalogue.epics: for story in epic.stories: testedStory = testedStories.get(story.name.strip().lower(), {}) for scenario in story.scenarios: scenario.status = "pending" testedScenario, info = testedStory.get(scenario.name.strip().lower(), (None, None,)) # Check for pass/fail if info is not None: if info.failure or info.error: scenario.status = "fail" else: scenario.status = "pass" # Init 'global' steps when they are missing setattr(story, "givens", getattr(story, "givens", [])) setattr(story, "thens", getattr(story, "thens", [])) setattr(story, "givens", getattr(story, "givens", [])) # Check for mismatch if ( len(story.givens + scenario.givens) != len(testedScenario.givens) or len(story.whens + scenario.whens) != len(testedScenario.whens) or len(story.thens + scenario.thens) != len(testedScenario.thens) ): scenario.status = "mismatch" if scenario.status != "mismatch": for left, right in zip(story.givens + scenario.givens, testedScenario.givens): if left.text.strip().lower() != right.text.strip().lower(): scenario.status = "mismatch" break if scenario.status != "mismatch": for left, right in zip(story.whens + scenario.whens, testedScenario.whens): if left.text.strip().lower() != right.text.strip().lower(): scenario.status = "mismatch" break if scenario.status != "mismatch": for left, right in zip(story.thens + scenario.thens, testedScenario.thens): if left.text.strip().lower() != right.text.strip().lower(): scenario.status = "mismatch" break # TODO: We don't handle superfluous tests yet if os.path.exists(directory): shutil.rmtree(directory) os.mkdir(directory) # Write CoreJet file with open(os.path.join(directory, filename), 'w') as output: catalogue.write(output) # Generate HTML report generateReportFromCatalogue(catalogue, directory)
def writeCoreJetReports(self, source, directory=None, filename='corejet.xml'): # corejet.robot registers CoreJet-adapters for Robot Framework tests # XXX: there should be a more dynamic way to configure plugin adapters try: import corejet.robot except ImportError: pass try: sourceType, sourceOptions = source.split(',', 1) except ValueError: # need more than 1 value to unpack sourceType = source.strip() sourceOptions = '' # Prepare output directory if directory is None: workingDir = os.getcwd() directory = os.path.join(workingDir, 'corejet') print "Writing CoreJet report to %s" % directory functionName = None for ep in pkg_resources.iter_entry_points('corejet.repositorysource'): if ep.name == sourceType and len(ep.attrs) > 0: functionName = "%s.%s" % ( ep.module_name, ep.attrs[0], ) break if not functionName: raise ValueError("Unknown CoreJet source type %s" % sourceType) sourceFunction = resolve(functionName) catalogue = sourceFunction(sourceOptions) # Set test time catalogue.testTime = datetime.datetime.now() # Find everything we've done so far testedStories = {} # story name -> {scenario name -> (scenario, info)} for suiteInfo in self._testSuites.values(): for caseInfo in suiteInfo.testCases: # look up the story for the test through adaptation: # - for @story-decorated test, the class implements IStory # - for others, the test case may have an adapter for IStory story = IStory(caseInfo.test, IStory(caseInfo.test.__class__, None)) if not story: continue scenarios = testedStories.setdefault( story.name.strip().lower(), {}) # XXX: Relying on _testMethodName here is not very good scenario = getattr(story, caseInfo.test._testMethodName).scenario scenarios[scenario.name.strip().lower()] = ( scenario, caseInfo, ) # Allocate a status to each scenario for epic in catalogue.epics: for story in epic.stories: testedStory = testedStories.get(story.name.strip().lower(), {}) for scenario in story.scenarios: scenario.status = "pending" testedScenario, info = testedStory.get( scenario.name.strip().lower(), ( None, None, )) # Check for pass/fail if info is not None: if info.failure or info.error: scenario.status = "fail" else: scenario.status = "pass" # Init 'global' steps when they are missing setattr(story, "givens", getattr(story, "givens", [])) setattr(story, "thens", getattr(story, "thens", [])) setattr(story, "givens", getattr(story, "givens", [])) # Check for mismatch if (len(story.givens + scenario.givens) != len( testedScenario.givens) or len(story.whens + scenario.whens) != len( testedScenario.whens) or len(story.thens + scenario.thens) != len( testedScenario.thens)): scenario.status = "mismatch" if scenario.status != "mismatch": for left, right in zip( story.givens + scenario.givens, testedScenario.givens): if left.text.strip().lower( ) != right.text.strip().lower(): scenario.status = "mismatch" break if scenario.status != "mismatch": for left, right in zip( story.whens + scenario.whens, testedScenario.whens): if left.text.strip().lower( ) != right.text.strip().lower(): scenario.status = "mismatch" break if scenario.status != "mismatch": for left, right in zip( story.thens + scenario.thens, testedScenario.thens): if left.text.strip().lower( ) != right.text.strip().lower(): scenario.status = "mismatch" break # TODO: We don't handle superfluous tests yet if os.path.exists(directory): shutil.rmtree(directory) os.mkdir(directory) # Write CoreJet file with open(os.path.join(directory, filename), 'w') as output: catalogue.write(output) # Generate HTML report generateReportFromCatalogue(catalogue, directory)