7
7
8
8
DOC_URI = uris .from_fs_path (__file__ )
9
9
DOC = """
10
- files = listdir( )
11
- print(files )
10
+ time.sleep(10 )
11
+ print("test" )
12
12
"""
13
13
14
14
@@ -28,41 +28,41 @@ def test_importmagic_lint():
28
28
diags = importmagic_lint .pyls_lint (doc )
29
29
unres_symbol = [d for d in diags if d ['source' ] == 'importmagic' ][0 ]
30
30
31
- assert unres_symbol ['message' ] == "Unresolved import 'listdir '"
32
- assert unres_symbol ['range' ]['start' ] == {'line' : 1 , 'character' : 8 }
33
- assert unres_symbol ['range' ]['end' ] == {'line' : 1 , 'character' : 15 }
31
+ assert unres_symbol ['message' ] == "Unresolved import 'time.sleep '"
32
+ assert unres_symbol ['range' ]['start' ] == {'line' : 1 , 'character' : 0 }
33
+ assert unres_symbol ['range' ]['end' ] == {'line' : 1 , 'character' : 10 }
34
34
assert unres_symbol ['severity' ] == lsp .DiagnosticSeverity .Hint
35
35
36
36
finally :
37
37
os .remove (name )
38
38
39
39
40
- # def test_importmagic_actions(config):
41
- # context = {
42
- # 'diagnostics': [
43
- # {
44
- # 'range':
45
- # {
46
- # 'start': {'line': 1, 'character': 8 },
47
- # 'end': {'line': 1, 'character': 15 }
48
- # },
49
- # 'message': "Unresolved import 'listdir '",
50
- # 'severity': 4 ,
51
- # 'source': 'importmagic'
52
- # }
53
- # ]
54
- # }
40
+ def test_importmagic_actions (config ):
41
+ context = {
42
+ 'diagnostics' : [
43
+ {
44
+ 'range' :
45
+ {
46
+ 'start' : {'line' : 1 , 'character' : 0 },
47
+ 'end' : {'line' : 1 , 'character' : 10 }
48
+ },
49
+ 'message' : "Unresolved import 'time.sleep '" ,
50
+ 'severity' : lsp . DiagnosticSeverity . Hint ,
51
+ 'source' : importmagic_lint . SOURCE
52
+ }
53
+ ]
54
+ }
55
55
56
- # try:
57
- # name, doc = temp_document(DOC)
58
- # actions = importmagic_lint.pyls_code_actions(config, doc, context)
59
- # action = [a for a in actions if a['title'] == 'Import "listdir" from "os "'][0]
60
- # arguments = action['arguments']
56
+ try :
57
+ name , doc = temp_document (DOC )
58
+ actions = importmagic_lint .pyls_code_actions (config , doc , context )
59
+ action = [a for a in actions if a ['title' ] == 'Import "time "' ][0 ]
60
+ arguments = action ['arguments' ][ 0 ]
61
61
62
- # assert action['command'] == 'importmagic.addimport'
63
- # assert arguments['startLine'] == 1
64
- # assert arguments['endLine'] == 1
65
- # assert arguments['newText'] == 'from os import listdir \n\n\n'
62
+ assert action ['command' ] == importmagic_lint . ADD_IMPORT_COMMAND
63
+ assert arguments ['startLine' ] == 1
64
+ assert arguments ['endLine' ] == 1
65
+ assert arguments ['newText' ] == 'import time \n \n \n '
66
66
67
- # finally:
68
- # os.remove(name)
67
+ finally :
68
+ os .remove (name )
0 commit comments