|
1 | 1 | import os
|
2 |
| -import subprocess |
3 |
| -import sys |
4 |
| - |
5 |
| -try: |
6 |
| - from StringIO import StringIO |
7 |
| -except ImportError: |
8 |
| - from io import StringIO |
9 |
| -root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) |
10 |
| -sys.path.insert(0, root_dir) |
11 |
| - |
12 |
| -from fortls.jsonrpc import ( # noqa: E402 |
13 |
| - path_to_uri, |
14 |
| - read_rpc_messages, |
15 |
| - write_rpc_notification, |
| 2 | +from setup_tests import ( |
| 3 | + run_request, |
16 | 4 | write_rpc_request,
|
| 5 | + write_rpc_notification, |
| 6 | + path_to_uri, |
| 7 | + test_dir, |
17 | 8 | )
|
18 | 9 |
|
19 |
| -run_command = os.path.join( |
20 |
| - root_dir, "fortls.py --incremental_sync --use_signature_help" |
21 |
| -) |
22 |
| -test_dir = os.path.join(root_dir, "test", "test_source") |
23 |
| - |
24 |
| - |
25 |
| -def run_request(request, fortls_args=""): |
26 |
| - pid = subprocess.Popen( |
27 |
| - run_command + fortls_args, |
28 |
| - shell=True, |
29 |
| - stdin=subprocess.PIPE, |
30 |
| - stdout=subprocess.PIPE, |
31 |
| - stderr=subprocess.PIPE, |
32 |
| - ) |
33 |
| - results = pid.communicate(input=request.encode()) |
34 |
| - tmp_file = StringIO(results[0].decode()) |
35 |
| - results = read_rpc_messages(tmp_file) |
36 |
| - parsed_results = [] |
37 |
| - for result in results: |
38 |
| - try: |
39 |
| - parsed_results.append(result["result"]) |
40 |
| - except KeyError: |
41 |
| - try: |
42 |
| - # Present in `method`s |
43 |
| - parsed_results.append(result["params"]) |
44 |
| - except: |
45 |
| - raise RuntimeError( |
46 |
| - "Only 'result' and 'params' keys have been implemented for testing." |
47 |
| - " Please add the new key." |
48 |
| - ) |
49 |
| - except: |
50 |
| - raise RuntimeError( |
51 |
| - "Unexpected error encountered trying to extract server results" |
52 |
| - ) |
53 |
| - errcode = pid.poll() |
54 |
| - return errcode, parsed_results |
55 |
| - |
56 | 10 |
|
57 | 11 | def test_init():
|
58 | 12 | def check_return(result_dict):
|
|
0 commit comments