|
14 | 14 | here = os.path.dirname(os.path.abspath(__file__))
|
15 | 15 |
|
16 | 16 |
|
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 | + |
18 | 28 |
|
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): |
29 | 30 |
|
30 | 31 | @tempdir()
|
31 | 32 | def test_languagetool_server_fails(self, temp_dir):
|
32 | 33 | # Program doesn't exist
|
33 | 34 | with ShouldRaise(OSError):
|
34 |
| - self.subprocess_testing_helper( |
| 35 | + subprocess_helper( |
35 | 36 | temp_dir,
|
36 | 37 | ['not_existing_program', '/tmp'])
|
37 | 38 | # Program fails to work
|
38 | 39 | with ShouldRaise(IOError):
|
39 |
| - self.subprocess_testing_helper(temp_dir, ['python', '-c', '5/0']) |
| 40 | + subprocess_helper(temp_dir, ['python', '-c', '5/0']) |
40 | 41 | # Program segfaults
|
41 | 42 | with ShouldRaise(IOError):
|
42 |
| - self.subprocess_testing_helper( |
| 43 | + subprocess_helper( |
43 | 44 | temp_dir,
|
44 | 45 | ['python', '-c',
|
45 | 46 | 'import signal; import sys; sys.exit(signal.SIGSEGV)'])
|
46 | 47 | # Server started message don't appeared
|
47 | 48 | with ShouldRaise(IOError):
|
48 |
| - self.subprocess_testing_helper( |
| 49 | + subprocess_helper( |
49 | 50 | temp_dir,
|
50 | 51 | ['python', '-c', 'print "Something goes wrong"'])
|
51 |
| - self.subprocess_testing_helper( |
| 52 | + subprocess_helper( |
52 | 53 | temp_dir,
|
53 | 54 | ['python', '-c', 'print "Server started"'])
|
54 | 55 |
|
|
0 commit comments