def _first_occurrence(test_ctrl, kw_name): occurrences = test_ctrl.execute(FindOccurrences(kw_name)) if not occurrences: raise AssertionError('No occurrences found for "%s"' % kw_name) if PY2: return occurrences.next() # Python 2.7 return occurrences.__next__() # DEBUG .next() Python 3
def test_first_occurrences_are_from_the_same_file(self): occ = self.resu.execute(FindOccurrences('My Keyword')) # see https://stackoverflow.com/questions/21622193/ # python-3-2-coroutine-attributeerror-generator-object-has-no-attribute-next assert_true( self.resu.filename.endswith(occ.__next__().item.parent.source)) assert_equal(occ.__next__().source, self.ts2.source) assert_equal(occ.__next__().source, self.ts2.source)
def test_unknown_variable_occurrences(self): self.assertEqual( list( self.test_ctrl.execute( FindOccurrences('${some unknown variable}'))), [])
def test_no_occurrences(self): find_occurrences = FindOccurrences('Keyword Name') occurrences = self.test_ctrl.execute(find_occurrences) assert_equal([i for i in occurrences], [])
def assert_occurrences(self, ctrl, kw_name, count): assert_equal(sum(1 for _ in ctrl.execute(FindOccurrences(kw_name))), count)
def _first_occurrence(test_ctrl, kw_name): occurrences = test_ctrl.execute(FindOccurrences(kw_name)) if not occurrences: raise AssertionError('No occurrences found for "%s"' % kw_name) return next(occurrences)