209 lines
7.9 KiB
Diff
209 lines
7.9 KiB
Diff
|
--- a/tests/run.py
|
||
|
+++ b/tests/run.py
|
||
|
@@ -16,18 +16,13 @@ from __future__ import print_function
|
||
|
|
||
|
import os
|
||
|
import sys
|
||
|
+import unittest
|
||
|
|
||
|
# only find tests in this directory
|
||
|
if os.path.dirname(__file__):
|
||
|
os.chdir(os.path.dirname(__file__))
|
||
|
|
||
|
|
||
|
-try:
|
||
|
- import nose
|
||
|
-except ImportError:
|
||
|
- print('nose is required to run the Pygments test suite')
|
||
|
- sys.exit(1)
|
||
|
-
|
||
|
# make sure the current source is first on sys.path
|
||
|
sys.path.insert(0, '..')
|
||
|
|
||
|
@@ -47,4 +42,4 @@ else:
|
||
|
print('Pygments test suite running (Python %s)...' % sys.version.split()[0],
|
||
|
file=sys.stderr)
|
||
|
|
||
|
-nose.main()
|
||
|
+unittest.main()
|
||
|
--- a/tests/support.py
|
||
|
+++ b/tests/support.py
|
||
|
@@ -5,7 +5,7 @@ Support for Pygments tests
|
||
|
|
||
|
import os
|
||
|
|
||
|
-from nose import SkipTest
|
||
|
+from unittest import SkipTest
|
||
|
|
||
|
|
||
|
def location(mod_name):
|
||
|
--- a/tests/test_cmdline.py
|
||
|
+++ b/tests/test_cmdline.py
|
||
|
@@ -143,7 +143,7 @@ class CmdLineTest(unittest.TestCase):
|
||
|
|
||
|
def test_h_opt(self):
|
||
|
o = self.check_success('-h')
|
||
|
- self.assertTrue('Usage:' in o)
|
||
|
+ self.assertIn('Usage:', o)
|
||
|
|
||
|
def test_L_opt(self):
|
||
|
o = self.check_success('-L')
|
||
|
@@ -157,37 +157,37 @@ class CmdLineTest(unittest.TestCase):
|
||
|
filename = TESTFILE
|
||
|
o = self.check_success('-Ofull=1,linenos=true,foo=bar',
|
||
|
'-fhtml', filename)
|
||
|
- self.assertTrue('<html' in o)
|
||
|
- self.assertTrue('class="linenos"' in o)
|
||
|
+ self.assertIn('<html', o)
|
||
|
+ self.assertIn('class="linenos"', o)
|
||
|
|
||
|
# "foobar" is invalid for a bool option
|
||
|
e = self.check_failure('-Ostripnl=foobar', TESTFILE)
|
||
|
- self.assertTrue('Error: Invalid value' in e)
|
||
|
+ self.assertIn('Error: Invalid value', e)
|
||
|
e = self.check_failure('-Ostripnl=foobar', '-lpy')
|
||
|
- self.assertTrue('Error: Invalid value' in e)
|
||
|
+ self.assertIn('Error: Invalid value', e)
|
||
|
|
||
|
def test_P_opt(self):
|
||
|
filename = TESTFILE
|
||
|
o = self.check_success('-Pfull', '-Ptitle=foo, bar=baz=,',
|
||
|
'-fhtml', filename)
|
||
|
- self.assertTrue('<title>foo, bar=baz=,</title>' in o)
|
||
|
+ self.assertIn('<title>foo, bar=baz=,</title>', o)
|
||
|
|
||
|
def test_F_opt(self):
|
||
|
filename = TESTFILE
|
||
|
o = self.check_success('-Fhighlight:tokentype=Name.Blubb,'
|
||
|
'names=TESTFILE filename',
|
||
|
'-fhtml', filename)
|
||
|
- self.assertTrue('<span class="n n-Blubb' in o)
|
||
|
+ self.assertIn('<span class="n n-Blubb', o)
|
||
|
|
||
|
def test_H_opt(self):
|
||
|
o = self.check_success('-H', 'formatter', 'html')
|
||
|
- self.assertTrue('HTML' in o)
|
||
|
+ self.assertIn('HTML', o)
|
||
|
o = self.check_success('-H', 'lexer', 'python')
|
||
|
- self.assertTrue('Python' in o)
|
||
|
+ self.assertIn('Python', o)
|
||
|
o = self.check_success('-H', 'filter', 'raiseonerror')
|
||
|
- self.assertTrue('raiseonerror', o)
|
||
|
+ self.assertIn('raiseonerror', o)
|
||
|
e = self.check_failure('-H', 'lexer', 'foobar')
|
||
|
- self.assertTrue('not found' in e)
|
||
|
+ self.assertIn('not found', e)
|
||
|
|
||
|
def test_S_opt(self):
|
||
|
o = self.check_success('-S', 'default', '-f', 'html', '-O', 'linenos=1')
|
||
|
@@ -196,11 +196,11 @@ class CmdLineTest(unittest.TestCase):
|
||
|
# every line is for a token class
|
||
|
parts = line.split()
|
||
|
self.assertTrue(parts[0].startswith('.'))
|
||
|
- self.assertTrue(parts[1] == '{')
|
||
|
+ self.assertEqual(parts[1], '{')
|
||
|
if parts[0] != '.hll':
|
||
|
- self.assertTrue(parts[-4] == '}')
|
||
|
- self.assertTrue(parts[-3] == '/*')
|
||
|
- self.assertTrue(parts[-1] == '*/')
|
||
|
+ self.assertEqual(parts[-4], '}')
|
||
|
+ self.assertEqual(parts[-3], '/*')
|
||
|
+ self.assertEqual(parts[-1], '*/')
|
||
|
self.check_failure('-S', 'default', '-f', 'foobar')
|
||
|
|
||
|
def test_N_opt(self):
|
||
|
@@ -228,68 +228,69 @@ class CmdLineTest(unittest.TestCase):
|
||
|
self.check_failure(*opts, code=2)
|
||
|
|
||
|
def test_errors(self):
|
||
|
+ this_file_dir = os.path.dirname(os.path.realpath(__file__))
|
||
|
+ empty_file = os.path.join(this_file_dir, 'support/empty.py')
|
||
|
+
|
||
|
# input file not found
|
||
|
e = self.check_failure('-lpython', 'nonexistent.py')
|
||
|
- self.assertTrue('Error: cannot read infile' in e)
|
||
|
- self.assertTrue('nonexistent.py' in e)
|
||
|
+ self.assertIn('Error: cannot read infile', e)
|
||
|
+ self.assertIn('nonexistent.py', e)
|
||
|
|
||
|
# lexer not found
|
||
|
e = self.check_failure('-lfooo', TESTFILE)
|
||
|
- self.assertTrue('Error: no lexer for alias' in e)
|
||
|
+ self.assertIn('Error: no lexer for alias', e)
|
||
|
|
||
|
# cannot load .py file without load_from_file flag
|
||
|
e = self.check_failure('-l', 'nonexistent.py', TESTFILE)
|
||
|
- self.assertTrue('Error: no lexer for alias' in e)
|
||
|
+ self.assertIn('Error: no lexer for alias', e)
|
||
|
|
||
|
# lexer file is missing/unreadable
|
||
|
e = self.check_failure('-l', 'nonexistent.py',
|
||
|
'-x', TESTFILE)
|
||
|
- self.assertTrue('Error: cannot read' in e)
|
||
|
+ self.assertIn('Error: cannot read', e)
|
||
|
|
||
|
# lexer file is malformed
|
||
|
- e = self.check_failure('-l', 'support/empty.py',
|
||
|
- '-x', TESTFILE)
|
||
|
- self.assertTrue('Error: no valid CustomLexer class found' in e)
|
||
|
+ e = self.check_failure('-l', empty_file, '-x', TESTFILE)
|
||
|
+ self.assertIn('Error: no valid CustomLexer class found', e)
|
||
|
|
||
|
# formatter not found
|
||
|
e = self.check_failure('-lpython', '-ffoo', TESTFILE)
|
||
|
- self.assertTrue('Error: no formatter found for name' in e)
|
||
|
+ self.assertIn('Error: no formatter found for name', e)
|
||
|
|
||
|
# formatter for outfile not found
|
||
|
e = self.check_failure('-ofoo.foo', TESTFILE)
|
||
|
- self.assertTrue('Error: no formatter found for file name' in e)
|
||
|
+ self.assertIn('Error: no formatter found for file name', e)
|
||
|
|
||
|
# cannot load .py file without load_from_file flag
|
||
|
e = self.check_failure('-f', 'nonexistent.py', TESTFILE)
|
||
|
- self.assertTrue('Error: no formatter found for name' in e)
|
||
|
+ self.assertIn('Error: no formatter found for name', e)
|
||
|
|
||
|
# formatter file is missing/unreadable
|
||
|
e = self.check_failure('-f', 'nonexistent.py',
|
||
|
'-x', TESTFILE)
|
||
|
- self.assertTrue('Error: cannot read' in e)
|
||
|
+ self.assertIn('Error: cannot read', e)
|
||
|
|
||
|
# formatter file is malformed
|
||
|
- e = self.check_failure('-f', 'support/empty.py',
|
||
|
- '-x', TESTFILE)
|
||
|
- self.assertTrue('Error: no valid CustomFormatter class found' in e)
|
||
|
+ e = self.check_failure('-f', empty_file, '-x', TESTFILE)
|
||
|
+ self.assertIn('Error: no valid CustomFormatter class found', e)
|
||
|
|
||
|
# output file not writable
|
||
|
e = self.check_failure('-o', os.path.join('nonexistent', 'dir', 'out.html'),
|
||
|
'-lpython', TESTFILE)
|
||
|
- self.assertTrue('Error: cannot open outfile' in e)
|
||
|
- self.assertTrue('out.html' in e)
|
||
|
+ self.assertIn('Error: cannot open outfile', e)
|
||
|
+ self.assertIn('out.html', e)
|
||
|
|
||
|
# unknown filter
|
||
|
e = self.check_failure('-F', 'foo', TESTFILE)
|
||
|
- self.assertTrue('Error: filter \'foo\' not found' in e)
|
||
|
+ self.assertIn('Error: filter \'foo\' not found', e)
|
||
|
|
||
|
def test_exception(self):
|
||
|
cmdline.highlight = None # override callable to provoke TypeError
|
||
|
try:
|
||
|
# unexpected exception while highlighting
|
||
|
e = self.check_failure('-lpython', TESTFILE)
|
||
|
- self.assertTrue('*** Error while highlighting:' in e)
|
||
|
- self.assertTrue('TypeError' in e)
|
||
|
+ self.assertIn('*** Error while highlighting:', e)
|
||
|
+ self.assertIn('TypeError', e)
|
||
|
|
||
|
# same with -v: should reraise the exception
|
||
|
try:
|
||
|
--- /dev/null
|
||
|
+++ b/tests/__init__.py
|
||
|
@@ -0,0 +1 @@
|
||
|
+
|