Pepijn de Vos avatar Pepijn de Vos committed ce2f619

add suggested edits and test

Comments (0)

Files changed (3)

pygments/formatters/html.py

 try:
     from ctags import CTags, TagEntry
 except ImportError:
-    pass
+    CTags = None
 
 __all__ = ['HtmlFormatter']
 
         self.urlformat = self._decodeifneeded(options.get('urlformat', ''))
 
         if self.tagsfile:
-            try:
+            if CTags:
                 self.ct = CTags(self.tagsfile)
-            except NameError:
-                print >> sys.stderr, 'Hey! ctags doesn\'t seem to be installed. Try \'pip install python-ctags\'.'
+            else:
+                raise NameError('Hey! ctags doesn\'t seem to be installed. Try \'pip install python-ctags\'.')
 
         linenos = options.get('linenos', False)
         if linenos == 'inline':

tests/examplefiles/tags

+!_TAG_FILE_FORMAT	2	/extended format; --format=1 will not append ;" to lines/
+!_TAG_FILE_SORTED	1	/0=unsorted, 1=sorted, 2=foldcase/
+!_TAG_PROGRAM_AUTHOR	Darren Hiebert	/dhiebert@users.sourceforge.net/
+!_TAG_PROGRAM_NAME	Exuberant Ctags	//
+!_TAG_PROGRAM_URL	http://ctags.sourceforge.net	/official site/
+!_TAG_PROGRAM_VERSION	5.8	//
+HtmlFormatter	test_html_formatter.py	19;"	i
+HtmlFormatterTest	test_html_formatter.py	34;"	c
+NullFormatter	test_html_formatter.py	19;"	i
+PythonLexer	test_html_formatter.py	18;"	i
+StringIO	test_html_formatter.py	13;"	i
+dirname	test_html_formatter.py	16;"	i
+escape_html	test_html_formatter.py	20;"	i
+fp	test_html_formatter.py	27;"	v
+inspect	test_html_formatter.py	15;"	i
+isfile	test_html_formatter.py	16;"	i
+join	test_html_formatter.py	16;"	i
+os	test_html_formatter.py	10;"	i
+re	test_html_formatter.py	11;"	i
+subprocess	test_html_formatter.py	125;"	i
+support	test_html_formatter.py	23;"	i
+tempfile	test_html_formatter.py	14;"	i
+test_all_options	test_html_formatter.py	72;"	m	class:HtmlFormatterTest
+test_correct_output	test_html_formatter.py	35;"	m	class:HtmlFormatterTest
+test_ctags	test_html_formatter.py	165;"	m	class:HtmlFormatterTest
+test_external_css	test_html_formatter.py	48;"	m	class:HtmlFormatterTest
+test_get_style_defs	test_html_formatter.py	141;"	m	class:HtmlFormatterTest
+test_lineanchors	test_html_formatter.py	98;"	m	class:HtmlFormatterTest
+test_lineanchors_with_startnum	test_html_formatter.py	106;"	m	class:HtmlFormatterTest
+test_linenos	test_html_formatter.py	82;"	m	class:HtmlFormatterTest
+test_linenos_with_startnum	test_html_formatter.py	90;"	m	class:HtmlFormatterTest
+test_unicode_options	test_html_formatter.py	155;"	m	class:HtmlFormatterTest
+test_valid_output	test_html_formatter.py	114;"	m	class:HtmlFormatterTest
+tokensource	test_html_formatter.py	29;"	v
+uni_open	test_html_formatter.py	21;"	i
+unittest	test_html_formatter.py	12;"	i

tests/test_html_formatter.py

         tfile = os.fdopen(handle, 'w+b')
         fmt.format(tokensource, tfile)
         tfile.close()
+
+    def test_ctags(self): # make sure this is in fact line 165 and the tags file says so
+        fmt = HtmlFormatter(tagsfile='examplefiles/tags', lineanchors="L")
+        outfile = StringIO.StringIO()
+        fmt.format(tokensource, outfile)
+        self.assertTrue('<a href="#L-165">test_ctags</a>' in outfile.getvalue())
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.