Skip to content

Commit e1a227c

Browse files
committed
fixed subprocess tests
1 parent 2f10a30 commit e1a227c

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ nosetests.xml
4040
*.sublime-workspace
4141

4242
src/slidelint/LanguageTool/
43+
*.lintrez

src/slidelint/tests/checkers/languagetool_grammar/TestCheckerLanguageTool.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,42 @@
1414
here = os.path.dirname(os.path.abspath(__file__))
1515

1616

17-
class Test_Languagetool_Checker(unittest.TestCase):
17+
def subprocess_helper(temp_dir, cmd):
18+
config_file = os.path.join(temp_dir.path, 'tmp_file')
19+
import subprocess
20+
origing_popen = subprocess.Popen
21+
with Replacer() as r:
22+
def not_existing_program(*args, **kwargs):
23+
return origing_popen(cmd, *args[1:], **kwargs)
24+
r.replace('subprocess.Popen', not_existing_program)
25+
language_tool_checker.start_languagetool_server(
26+
temp_dir.path, config_file)
27+
1828

19-
def subprocess_testing_helper(self, temp_dir, cmd):
20-
config_file = os.path.join(temp_dir.path, 'tmp_file')
21-
import subprocess
22-
origing_popen = subprocess.Popen
23-
with Replacer() as r:
24-
def not_existing_program(*args, **kwargs):
25-
return origing_popen(cmd, *args[1:], **kwargs)
26-
r.replace('subprocess.Popen', not_existing_program)
27-
language_tool_checker.start_languagetool_server(
28-
temp_dir.path, config_file)
29+
class Test_Languagetool_Checker(unittest.TestCase):
2930

3031
@tempdir()
3132
def test_languagetool_server_fails(self, temp_dir):
3233
# Program doesn't exist
3334
with ShouldRaise(OSError):
34-
self.subprocess_testing_helper(
35+
subprocess_helper(
3536
temp_dir,
3637
['not_existing_program', '/tmp'])
3738
# Program fails to work
3839
with ShouldRaise(IOError):
39-
self.subprocess_testing_helper(temp_dir, ['python', '-c', '5/0'])
40+
subprocess_helper(temp_dir, ['python', '-c', '5/0'])
4041
# Program segfaults
4142
with ShouldRaise(IOError):
42-
self.subprocess_testing_helper(
43+
subprocess_helper(
4344
temp_dir,
4445
['python', '-c',
4546
'import signal; import sys; sys.exit(signal.SIGSEGV)'])
4647
# Server started message don't appeared
4748
with ShouldRaise(IOError):
48-
self.subprocess_testing_helper(
49+
subprocess_helper(
4950
temp_dir,
5051
['python', '-c', 'print "Something goes wrong"'])
51-
self.subprocess_testing_helper(
52+
subprocess_helper(
5253
temp_dir,
5354
['python', '-c', 'print "Server started"'])
5455

src/slidelint/tests/checkers/low_contrast/TestCheckerTextReadability.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
class TestContentsChecker(unittest.TestCase):
3636

37-
def subprocess_testing_helper(self, temp_dir, cmd):
37+
def subprocess_helper(self, temp_dir, cmd):
3838
config_file = os.path.join(temp_dir.path, 'tmp_file')
3939
import subprocess
4040
origing_popen = subprocess.Popen
@@ -50,15 +50,15 @@ def not_existing_program(*args, **kwargs):
5050
def test_pdftohtml_fails(self, temp_dir):
5151
# Program doesn't exist
5252
with ShouldRaise(OSError):
53-
self.subprocess_testing_helper(
53+
self.subprocess_helper(
5454
temp_dir, ['not_existing_program', '/tmp'])
5555
# Program fails to work
5656
with ShouldRaise(IOError):
57-
self.subprocess_testing_helper(
57+
self.subprocess_helper(
5858
temp_dir, ['python', '-c', '5/0'])
5959
# Program segfaults
6060
with ShouldRaise(IOError):
61-
self.subprocess_testing_helper(
61+
self.subprocess_helper(
6262
temp_dir,
6363
['python', '-c',
6464
'import signal; import sys; sys.exit(signal.SIGSEGV)'])

0 commit comments

Comments
 (0)