forked from Blazemeter/taurus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_linter.py
83 lines (75 loc) · 2.87 KB
/
test_linter.py
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
import logging
from bzt.linter import ConfigurationLinter, ConfigWarning
from bzt.utils import BetterDict
from tests import BZTestCase
class TestLinter(BZTestCase):
def setUp(self):
super(TestLinter, self).setUp()
self.config = BetterDict()
self.ignored_warnings = []
self.linter = ConfigurationLinter(self.config, self.ignored_warnings, logging.getLogger(''))
self.linter.register_checkers()
def test_single_execution(self):
self.config.merge({
"execution": {
"scenario": {
"script": "foo",
}
}
})
self.linter.lint()
warnings = self.linter.get_warnings()
self.assertEqual(warnings[0].identifier, 'single-execution')
def test_execution_no_scenario(self):
self.config.merge({
"execution": [{
"concurrency": 10,
"hold-for": "30s",
}]
})
self.linter.lint()
warnings = self.linter.get_warnings()
self.assertEqual(warnings[0].identifier, 'no-scenario')
def test_execution_typos(self):
self.config.merge({
"execution": [{
"concurency": 10,
"hold-fro": "30s",
"scenario": {
"script": "foo",
}
}]
})
self.linter.lint()
warnings = self.linter.get_warnings()
ident_msg = sorted([(warning.identifier, warning.message) for warning in warnings])
self.assertEqual(ident_msg[0], ('possible-typo', "unfamiliar name 'concurency'. Did you mean 'concurrency'?"))
self.assertEqual(ident_msg[1], ('possible-typo', "unfamiliar name 'hold-fro'. Did you mean 'hold-for'?"))
def test_ignore_warnings(self):
self.config.merge({
"execution": [{
"concurency": 10, # typo
"scenario": {
"script": "foo",
}
}]
})
self.ignored_warnings.append('possible-typo')
self.linter.lint()
warnings = self.linter.get_warnings()
self.assertTrue(not any(w.identifier == 'possible-typo' for w in warnings))
def test_severity(self):
self.config.merge({
"execution": [{
"concurency": 10, # typo
"scenario": {
# no-script-nor-requests
}
}]
})
self.linter.lint()
messages = self.linter.get_warnings()
warnings = [(w.identifier, str(w.path)) for w in messages if w.severity == ConfigWarning.WARNING]
errors = [(w.identifier, str(w.path)) for w in messages if w.severity == ConfigWarning.ERROR]
self.assertEqual(warnings, [('possible-typo', 'execution.0.concurency')])
self.assertEqual(errors, [('no-script-or-requests', 'execution.0.scenario')])