-
Notifications
You must be signed in to change notification settings - Fork 1
/
flycheck-pyre-tests.el
87 lines (78 loc) · 3.16 KB
/
flycheck-pyre-tests.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
;;; flycheck-pyre-tests.el --- Support Pyre in flycheck -*- lexical-binding: t -*-
;; Copyright (C) 2018 Vyacheslav Linnik <vyacheslav.linnik@gmail.com>
;; License: MIT
;;
;; Author: Vyacheslav Linnik <vyacheslav.linnik@gmail.com>
;;; Commentary:
;; Expected error format
;; {
;; "line": 76,
;; "column": 31,
;; "path": "module/example.py",
;; "code": 16,
;; "name": "Undefined attribute",
;; "description": "Undefined attribute [16]: Optional type has no attribute `__getitem__`.",
;; "inference": {},
;; "do_not_check": false,
;; "external_to_project_root": false,
;; "external_to_source_root": false
;; }
;;; Code:
(require 'flycheck-pyre)
(require 'json)
(ert-deftest test-pyre-parse-warning ()
"Test that the warning types are parsed correctly"
(let* ((json-array-type 'list)
(data (json-read-from-string "{\"path\":\"test_pyre_module.py\"}")))
(should (equal (flycheck-pyre-decode-filepath data) "test_pyre_module.py"))))
(ert-deftest test-filter-by-buffer-name()
"Test that we can filter out errors by buffer name
with an absolute path in it."
(let* ((checker nil) (buffer nil)
(buffer-name "/Users/author/workspace/myproject/module/example.py")
(parsed (flycheck-pyre-parse-error-data pyre-errors))
(filtered (flycheck-pyre-filter-by-filepath parsed buffer-name))
(decoded (flycheck-pyre-decode-error-data filtered checker buffer))
(item (car decoded)))
(should (= 2 (length parsed)))
(should (= 1 (length filtered)))
(should (string= (flycheck-error-filename item) "module/example.py"))))
(ert-deftest test-decoded-error-content()
"Test whether content of decoded error is matching our expectations."
(let* ((checker nil) (buffer nil)
(buffer-name "/Users/author/workspace/myproject/module/example.py")
(parsed (flycheck-pyre-parse-error-data pyre-errors))
(filtered (flycheck-pyre-filter-by-filepath parsed buffer-name))
(decoded (flycheck-pyre-decode-error-data filtered checker buffer))
(item (car decoded)))
(should (= 76 (flycheck-error-line item)))
(should (= 31 (flycheck-error-column item)))
(should (string= (flycheck-error-filename item) "module/example.py"))
(should (string= (flycheck-error-message item) "Undefined attribute [16]: Optional type has no attribute `__getitem__`."))))
(defconst pyre-errors "[\
{\
\"line\": 76,\
\"column\": 31,\
\"path\": \"module/example.py\",\
\"code\": 16,\
\"name\": \"Undefined attribute\",\
\"description\": \"Undefined attribute [16]: Optional type has no attribute `__getitem__`.\",\
\"inference\": {},\
\"do_not_check\": false,\
\"external_to_project_root\": false,\
\"external_to_source_root\": false\
},\
{\
\"line\": 5,\
\"column\": 0,\
\"path\": \"module/other.py\",\
\"code\": 21,\
\"name\": \"Undefined import\",\
\"description\": \"Undefined import [21]: Could not find a module corresponding to import `graphviz`.\",\
\"inference\": {},\
\"do_not_check\": false,\
\"external_to_project_root\": false,\
\"external_to_source_root\": false\
}\
]")
;;; flycheck-pyre-tests.el ends here