Пример #1
0
 def test_end_to_end(self):
     ec = exuberant_ctags()
     tags = ec.generate_tags(tag_program=tag_program, files=test_writetags.file_lists['relpath'])
     tf = ctags_file(tags)
     tf2 = ctags_file(tag_lists['relpath']['head'] + tag_lists['relpath']['body'])
     i = 0
     for t in tf.tags:
         self.failUnless(t in tf2.tags)
         i += 1
Пример #2
0
 def test_init_list(self):
     tf = ctags_file(tag_lists['unextended']['body'])
     for line in tag_lists['unextended']['body']:
         e = ctags_entry(line)
         self.failIf(e not in tf.tags)
         
     tf = ctags_file(tag_lists['relpath']['body'])
     for line in tag_lists['relpath']['body']:
         e = ctags_entry(line)
         self.failIf(e not in tf.tags)
Пример #3
0
 def test_end_to_end(self):
     ec = exuberant_ctags()
     tags = ec.generate_tags(tag_program=tag_program,
                             files=test_writetags.file_lists['relpath'])
     tf = ctags_file(tags)
     tf2 = ctags_file(tag_lists['relpath']['head'] +
                      tag_lists['relpath']['body'])
     i = 0
     for t in tf.tags:
         self.failUnless(t in tf2.tags)
         i += 1
Пример #4
0
 def test_by_name_harvester(self):
     by_name_h = by_name_harvester()
     tf = ctags_file(tag_lists['extended']['body'], harvesters=[by_name_h])
     name_dict = by_name_h.get_data()
     self.failUnless('ctags_entry' in name_dict)
     self.failUnless(name_dict['ctags_entry'][0].name == 'ctags_entry')
     self.failUnless(name_dict['ctags_entry'][0].extensions['kind'] == 'c')
Пример #5
0
 def test_generate_object(self):
     ec = exuberant_ctags(tag_program=tag_program, files=file_lists['relpath'])
     tf = ec.generate_object()
     tf2 = ctags_file(tag_lists['relpath']['body'])
     
     self.failIfEqual(tf, None)
     self.failUnless(len(tf.tags))
     i = 0
     for tag in tf2.tags:
         self.failUnlessEqual(repr(tag), repr(tf.tags[i]))
         i += 1
Пример #6
0
    def test_name_lookup_harvester(self):
        lookup_harvest = name_lookup_harvester()
        tf = ctags_file(tag_lists['extended']['body'], harvesters=[lookup_harvest])
        ec = exuberant_ctags(tag_program=tag_program)
        
        # exuberant ctags 5.8 picks up 5 matches, because of copy.copy
        tags = lookup_harvest.starts_with('c', case_sensitive=True)
        if ec.version in ['5.7', '5.6b1']:
            self.failUnlessEqual(len(tags), 4)
        if ec.version in ['5.8']:
            self.failUnlessEqual(len(tags), 5)

        tags = lookup_harvest.starts_with('C', case_sensitive=True)
        self.failUnlessEqual(len(tags), 0)
        
        atags = lookup_harvest.starts_with('a')
        self.failUnlessEqual(len(atags), 0)

        tags = lookup_harvest.starts_with('c')
        if ec.version in ['5.7', '5.6b1']:
            self.failUnlessEqual(len(tags), 4)
        if ec.version in ['5.8']:
            self.failUnlessEqual(len(tags), 5)
        
        tag_tags = lookup_harvest.starts_with('ctags_')
        self.failUnlessEqual(len(tag_tags), 4)

        tags = lookup_harvest.starts_with('c', num_results=2)
        self.failUnlessEqual(len(tags), 2)

        tags = lookup_harvest.starts_with('C', num_results=2)
        self.failUnlessEqual(len(tags), 2)
    
        tags = lookup_harvest.starts_with('c', num_results=5)
        self.failUnless(len(tags) <= 5)

        tags = lookup_harvest.starts_with('c', num_results=3, case_sensitive=True)
        self.failUnlessEqual(len(tags), 3)

        tags = lookup_harvest.starts_with('C', num_results=2, case_sensitive=True)
        self.failUnlessEqual(len(tags), 0)
    
        tags = lookup_harvest.starts_with('c', num_results=2, case_sensitive=False)
        self.failUnlessEqual(len(tags), 2)

        tags = lookup_harvest.starts_with('C', num_results=2, case_sensitive=False)
        self.failUnlessEqual(len(tags), 2)
Пример #7
0
    def generate_object(self, **kwargs):
        """
        Parses source files into a ctags_file instance.
        This method exists to avoid storing ctags generated data in an intermediate form before parsing.
        
        According to python documentation, this mechanism could deadlock due to other OS pipe buffers filling and blocking the child process.
        U{http://docs.python.org/library/subprocess.html}
            - B{Keyword Arguments:}
                - B{tag_program:} (str) path to ctags executable, or name of a ctags program in path
                - B{files:} (sequence) files to process with ctags
                - B{generator_options:} (dict) options to pass to ctags program
                - B{harvesters:} (list) list of harvester data classes for ctags_file to use while parsing
        @returns: generated instance of ctags_file on success, None on failure
        @rtype: (ctags_file or None)
        @raise ValueError: ctags executable path not set
        """
        valid_kwargs = ["tag_program", "files", "generator_options", "harvesters"]
        validator.validate(kwargs.keys(), valid_kwargs)

        (gen_opts, file_list) = self._prepare_to_generate(kwargs)
        tag_args = self._dict_to_args(gen_opts)

        tagfile = ctags_file()

        harvesters = list()
        if "harvesters" in kwargs:
            harvesters = kwargs["harvesters"]

        tagfile.feed_init(harvesters=harvesters)

        self.command_line = self._executable_path + " " + tag_args
        p = subprocess.Popen(
            self.command_line, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
        )
        p.stdin.write(file_list.encode())

        # is this the cleanest way to do this?  it makes the program execute, but I haven't found another way
        p.stdin.close()

        if sys.platform == "win32":
            if self._executable_path.rfind("/") >= 0:
                shortname = self._executable_path[self._executable_path.rfind("/") :]
            elif self._executable_path.rfind("\\") >= 0:
                shortname = self._executable_path[self._executable_path.rfind("\\") :]
            else:
                shortname = self._executable_path

        while p.poll() is None:
            line = p.stdout.readline().decode("utf-8")
            if not len(line):
                continue
            if sys.platform == "win32" and line.find(shortname + self.__warning_str) == 0:
                self.warnings.append(line)
            else:
                tagfile.feed_line(line)

        # process the remaining buffer
        for line in p.stdout.read().decode("utf-8").splitlines():
            if not len(line):
                continue
            if sys.platform == "win32" and line.find(shortname + self.__warning_str) == 0:
                self.warnings.append(line)
            else:
                tagfile.feed_line(line)

        if sys.platform != "win32":
            self.warnings = p.stderr.read().decode("utf-8").splitlines()

        tagfile.feed_finish()

        if p.returncode == 0:
            return tagfile
        else:
            return None
Пример #8
0
 def do_kind_harvest(self, taglist):
     kh = kind_harvester()
     tf = ctags_file(taglist, harvesters=[kh])
     return (tf, kh.get_data())
Пример #9
0
    def generate_object(self, **kwargs):
        """
        Parses source files into a ctags_file instance.
        This method exists to avoid storing ctags generated data in an intermediate form before parsing.
        
        According to python documentation, this mechanism could deadlock due to other OS pipe buffers filling and blocking the child process.
        U{http://docs.python.org/library/subprocess.html}
            - B{Keyword Arguments:}
                - B{tag_program:} (str) path to ctags executable, or name of a ctags program in path
                - B{files:} (sequence) files to process with ctags
                - B{generator_options:} (dict) options to pass to ctags program
                - B{harvesters:} (list) list of harvester data classes for ctags_file to use while parsing
        @returns: generated instance of ctags_file on success, None on failure
        @rtype: (ctags_file or None)
        @raise ValueError: ctags executable path not set
        """
        valid_kwargs = [
            'tag_program', 'files', 'generator_options', 'harvesters'
        ]
        validator.validate(kwargs.keys(), valid_kwargs)

        (gen_opts, file_list) = self._prepare_to_generate(kwargs)
        tag_args = self._dict_to_args(gen_opts)

        tagfile = ctags_file()

        harvesters = list()
        if 'harvesters' in kwargs:
            harvesters = kwargs['harvesters']

        tagfile.feed_init(harvesters=harvesters)

        self.command_line = self._executable_path + ' ' + tag_args
        p = subprocess.Popen(self.command_line,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             shell=True)
        p.stdin.write(file_list.encode())

        # is this the cleanest way to do this?  it makes the program execute, but I haven't found another way
        p.stdin.close()

        if sys.platform == "win32":
            if self._executable_path.rfind("/") >= 0:
                shortname = self._executable_path[self._executable_path.
                                                  rfind("/"):]
            elif self._executable_path.rfind("\\") >= 0:
                shortname = self._executable_path[self._executable_path.
                                                  rfind("\\"):]
            else:
                shortname = self._executable_path

        while p.poll() is None:
            line = p.stdout.readline().decode("utf-8")
            if not len(line):
                continue
            if sys.platform == 'win32' and line.find(shortname +
                                                     self.__warning_str) == 0:
                self.warnings.append(line)
            else:
                tagfile.feed_line(line)

        # process the remaining buffer
        for line in p.stdout.read().decode("utf-8").splitlines():
            if not len(line):
                continue
            if sys.platform == 'win32' and line.find(shortname +
                                                     self.__warning_str) == 0:
                self.warnings.append(line)
            else:
                tagfile.feed_line(line)

        if sys.platform != 'win32':
            self.warnings = p.stderr.read().decode("utf-8").splitlines()

        tagfile.feed_finish()

        if p.returncode == 0:
            return tagfile
        else:
            return None
Пример #10
0
 def test_extended_kinds(self):
     tf = ctags_file(tag_lists['extended']['body'])
     tf2 = ctags_file(tag_lists['relpath']['body'])
     
     self.failUnlessEqual(tf.tags[0].extensions['kind'], tf2.tags[0].extensions['kind'])
Пример #11
0
 def test_parse_list(self):
     tf = ctags_file()
     tf.parse(tag_lists['unextended']['body'])
     
     tf = ctags_file()
     tf.parse(tag_lists['relpath']['body'])
Пример #12
0
 def test_init_noparams(self):
     tf = ctags_file()
     self.failIf(tf == None)