Fix expectedFailure tests
This commit is contained in:
parent
e979aae85b
commit
620eef4ace
@ -4,6 +4,9 @@ from __future__ import print_function, unicode_literals
|
|||||||
import unittest
|
import unittest
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
import dotdot
|
import dotdot
|
||||||
import fake_env
|
import fake_env
|
||||||
@ -23,6 +26,15 @@ PRINT_OUTPUT=False
|
|||||||
CAPTURE_OUTPUT=True
|
CAPTURE_OUTPUT=True
|
||||||
|
|
||||||
|
|
||||||
|
class FakeSystemExit(Exception):
|
||||||
|
"""\
|
||||||
|
SystemExit exceptions are replaced by FakeSystemExit in the execute_cmds()
|
||||||
|
function, so they can be catched by ExpectedFailure tests in Python 2.x.
|
||||||
|
|
||||||
|
If a code is accepted to raise SystemExit, catch FakeSystemExit instead.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
# code for fake fs
|
# code for fake fs
|
||||||
|
|
||||||
class TestFakeInput(unittest.TestCase):
|
class TestFakeInput(unittest.TestCase):
|
||||||
@ -72,6 +84,7 @@ class CommandTestCase(unittest.TestCase):
|
|||||||
3. the expected output on stdout, verified with assertEqual.
|
3. the expected output on stdout, verified with assertEqual.
|
||||||
4. the expected output on stderr, verified with assertEqual.
|
4. the expected output on stderr, verified with assertEqual.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
outs = []
|
outs = []
|
||||||
for cmd in cmds:
|
for cmd in cmds:
|
||||||
inputs = []
|
inputs = []
|
||||||
@ -108,6 +121,13 @@ class CommandTestCase(unittest.TestCase):
|
|||||||
if PRINT_OUTPUT:
|
if PRINT_OUTPUT:
|
||||||
print(outs)
|
print(outs)
|
||||||
return outs
|
return outs
|
||||||
|
except SystemExit as exc:
|
||||||
|
exc_class, exc, tb = sys.exc_info()
|
||||||
|
if sys.version_info.major == 2:
|
||||||
|
# using six to avoid a SyntaxError in Python 3.x
|
||||||
|
six.reraise(FakeSystemExit, exc, tb)
|
||||||
|
else:
|
||||||
|
raise FakeSystemExit(exc).with_traceback(tb)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
fake_env.unset_fake_fs([content, filebroker, conf, init_cmd, import_cmd, configobj])
|
fake_env.unset_fake_fs([content, filebroker, conf, init_cmd, import_cmd, configobj])
|
||||||
@ -189,7 +209,7 @@ class TestAdd(DataCommandTestCase):
|
|||||||
cmds = ['pubs init',
|
cmds = ['pubs init',
|
||||||
('pubs add /bibexamples/utf8.bib', [], '', err),
|
('pubs add /bibexamples/utf8.bib', [], '', err),
|
||||||
]
|
]
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
def test_add_doc_nocopy_does_not_copy(self):
|
def test_add_doc_nocopy_does_not_copy(self):
|
||||||
@ -213,16 +233,17 @@ class TestAdd(DataCommandTestCase):
|
|||||||
'pubs add /data/pagerank.bib',
|
'pubs add /data/pagerank.bib',
|
||||||
'pubs add -k Page99 /data/turing1950.bib',
|
'pubs add -k Page99 /data/turing1950.bib',
|
||||||
]
|
]
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
# To be fixed
|
|
||||||
# def test_leading_citekey_space(self):
|
@unittest.expectedFailure
|
||||||
# cmds = ['pubs init',
|
def test_leading_citekey_space(self):
|
||||||
# 'pubs add /data/leadingspace.bib',
|
cmds = ['pubs init',
|
||||||
# 'pubs rename LeadingSpace NoLeadingSpace',
|
'pubs add /bibexamples/leadingspace.bib',
|
||||||
# ]
|
'pubs rename LeadingSpace NoLeadingSpace',
|
||||||
# self.execute_cmds(cmds)
|
]
|
||||||
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
|
|
||||||
class TestList(DataCommandTestCase):
|
class TestList(DataCommandTestCase):
|
||||||
@ -349,7 +370,7 @@ class TestTag(DataCommandTestCase):
|
|||||||
def test_wrong_citekey(self):
|
def test_wrong_citekey(self):
|
||||||
cmds = ['pubs tag Page999 a',
|
cmds = ['pubs tag Page999 a',
|
||||||
]
|
]
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
|
|
||||||
@ -428,7 +449,7 @@ class TestUsecase(DataCommandTestCase):
|
|||||||
self.assertEqual(clean(correct[4]), clean(out[4]))
|
self.assertEqual(clean(correct[4]), clean(out[4]))
|
||||||
|
|
||||||
def test_editor_abort(self):
|
def test_editor_abort(self):
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
cmds = ['pubs init',
|
cmds = ['pubs init',
|
||||||
('pubs add', ['abc', 'n']),
|
('pubs add', ['abc', 'n']),
|
||||||
('pubs add', ['abc', 'y', 'abc', 'n']),
|
('pubs add', ['abc', 'y', 'abc', 'n']),
|
||||||
@ -500,7 +521,7 @@ class TestUsecase(DataCommandTestCase):
|
|||||||
'pubs update'
|
'pubs update'
|
||||||
]
|
]
|
||||||
|
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
def test_add_with_tag(self):
|
def test_add_with_tag(self):
|
||||||
@ -516,9 +537,9 @@ class TestUsecase(DataCommandTestCase):
|
|||||||
'pubs add data/pagerank.bib',
|
'pubs add data/pagerank.bib',
|
||||||
'pubs doc open Page99'
|
'pubs doc open Page99'
|
||||||
]
|
]
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
with self.assertRaises(SystemExit):
|
with self.assertRaises(FakeSystemExit):
|
||||||
cmds[-1] == 'pubs doc open Page8'
|
cmds[-1] == 'pubs doc open Page8'
|
||||||
self.execute_cmds(cmds)
|
self.execute_cmds(cmds)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user