-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_slash_plugin.py
More file actions
91 lines (65 loc) · 2.64 KB
/
test_slash_plugin.py
File metadata and controls
91 lines (65 loc) · 2.64 KB
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
88
89
90
91
import pytest
from urlobject import URLObject
import slash
import slash.loader
from backslash.contrib.utils import distill_slash_traceback
# pylint: disable=redefined-outer-name
def test_importing_slash_plugin():
from backslash.contrib import slash_plugin # pylint: disable=unused-variable,unused-import,import-outside-toplevel
def test_exception_distilling(traceback):
assert isinstance(traceback, list)
assert traceback
for f in traceback:
assert f['code_line']
def test_exception_distilling_surrounding_code(traceback):
frame = traceback[-1]
assert 'def test_failing():' in [line.strip()
for line in frame['code_lines_before']]
assert '1 / 0' in frame['code_line']
assert frame['code_lines_before']
assert not any('1 / 0' in l for l in frame['code_lines_before'])
assert frame['code_lines_after']
assert not any('1 / 0' in l for l in frame['code_lines_after'])
def test_rest_url(installed_plugin, server_url):
installed_plugin.activate()
assert installed_plugin.rest_url == server_url.add_path('rest')
def test_webapp_url(installed_plugin, server_url):
installed_plugin.activate()
expected = server_url
if not expected.endswith('/'):
expected += '/'
expected += '#/'
assert installed_plugin.webapp_url == expected
def test_session_webapp_url_no_session(installed_plugin):
assert installed_plugin.session_webapp_url is None
def test_session_webapp_url_with_session(installed_plugin, server_url):
installed_plugin.activate()
with slash.Session() as s:
url = installed_plugin.session_webapp_url
assert url == f'{server_url}/#/sessions/{s.id}'
@pytest.fixture
def traceback(error_result):
[e] = error_result.get_errors()
return distill_slash_traceback(e)
@pytest.fixture
def error_result():
def test_failing():
1 / 0 # pylint: disable=pointless-statement
with slash.Session() as s:
with s.get_started_context():
slash.runner.run_tests(
slash.loader.Loader().get_runnables([test_failing]))
[res] = s.results.iter_test_results()
return res
@pytest.fixture
def installed_plugin(request, server_url):
from backslash.contrib import slash_plugin # pylint: disable=import-outside-toplevel
plugin = slash_plugin.BackslashPlugin(url=str(server_url), runtoken='blap')
@request.addfinalizer
def cleanup(): # pylint: disable=unused-variable
slash.plugins.manager.uninstall(plugin)
slash.plugins.manager.install(plugin)
return plugin
@pytest.fixture
def server_url():
return URLObject('http://some.backslash.server')