Exemplo n.º 1
0
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
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 def execute(self, context):
     prev = None
     for occ in FindOccurrences.execute(self, context):
         if isinstance(occ.item, KeywordNameController):
             continue
         if prev == occ:
             prev.count += 1
         else:
             if prev:
                 yield prev
             prev = occ
     if prev:
         yield prev
Exemplo n.º 4
0
 def execute(self, context):
     prev = None
     for occ in FindOccurrences.execute(self, context):
         if isinstance(occ.item, KeywordNameController):
             continue
         if prev == occ:
             prev.count += 1
         else:
             if prev:
                 yield prev
             prev = occ
     if prev:
         yield prev
Exemplo n.º 5
0
 def test_unknown_variable_occurrences(self):
     self.assertEqual(
         list(
             self.test_ctrl.execute(
                 FindOccurrences('${some unknown variable}'))), [])
Exemplo n.º 6
0
 def test_no_occurrences(self):
     find_occurrences = FindOccurrences('Keyword Name')
     occurrences = self.test_ctrl.execute(find_occurrences)
     assert_equal([i for i in occurrences], [])
Exemplo n.º 7
0
 def assert_occurrences(self, ctrl, kw_name, count):
     assert_equal(sum(1 for _ in ctrl.execute(FindOccurrences(kw_name))),
                  count)
Exemplo n.º 8
0
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)