File: lexer_test.py

package info (click to toggle)
python-ansible-pygments 0.1.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 240 kB
  • sloc: python: 487; sh: 23; makefile: 3
file content (128 lines) | stat: -rw-r--r-- 5,401 bytes parent folder | download | duplicates (2)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Author: Felix Fontein <felix@fontein.de>
# License: BSD-2-Clause
# Copyright: Felix Fontein <felix@fontein.de>, 2021
"""Tests for Pygments lexers."""

from pygments import highlight
# pylint: disable=no-name-in-module
# Ref: https://github.com/PyCQA/pylint/issues/491
from pygments.formatters import HtmlFormatter

from ansible_pygments.lexers import AnsibleOutputLexer


def run_test(data, lexer):
    """Format the data snippet as HTML using a given lexer."""
    formatter = HtmlFormatter()
    result = highlight(data, lexer, formatter)
    return formatter.get_style_defs('.highlight'), result


def test_ansible_output_lexer():
    """Test that AnsibleOutputLexer produces expected HTML output."""
    data = R"""
ok: [windows] => {
    "account": {
        "account_name": "vagrant-domain",
        "type": "User"
    },
    "authentication_package": "Kerberos",
    "user_flags": []
}

TASK [paused] ************************************************************************************************************************************
Sunday 11 November 2018  20:16:48 +0100 (0:00:00.041)       0:07:59.637 *******
--- before
+++ after
@@ -1,5 +1,5 @@
 {
-  "exists": false,
-  "paused": false,
-  "running": false
+  "exists": true,
+  "paused": true,
+  "running": true
 }
\ No newline at end of file

changed: [localhost]

TASK [volumes (more volumes)] ********************************************************************************************************************
Sunday 11 November 2018  20:19:25 +0100 (0:00:00.607)       0:10:36.974 *******
--- before
+++ after
@@ -1,11 +1,11 @@
 {
   "expected_binds": [
-    "/tmp:/tmp:rw",
-    "/:/whatever:rw,z"
+    "/tmp:/somewhereelse:ro,Z",
+    "/tmp:/tmp:rw"
   ],
   "expected_volumes": {
-    "/tmp": {},
-    "/whatever": {}
+    "/somewhereelse": {},
+    "/tmp": {}
   },
   "running": true
 }
\ No newline at end of file

changed: [localhost]
"""
    _, result = run_test(data, AnsibleOutputLexer())
    print(result)

    # pylint: disable=line-too-long
    assert result == R"""<div class="highlight"><pre><span></span><span class="k">ok</span><span class="p">:</span> <span class="p">[</span><span class="nv">windows</span><span class="p">]</span> <span class="p">=&gt;</span> <span class="p">{</span>
    <span class="nt">&quot;account&quot;</span><span class="p">:</span> <span class="p">{</span>
        <span class="nt">&quot;account_name&quot;</span><span class="p">:</span> <span class="s">&quot;vagrant-domain&quot;</span><span class="p">,</span>
        <span class="nt">&quot;type&quot;</span><span class="p">:</span> <span class="s">&quot;User&quot;</span>
    <span class="p">},</span>
    <span class="nt">&quot;authentication_package&quot;</span><span class="p">:</span> <span class="s">&quot;Kerberos&quot;</span><span class="p">,</span>
    <span class="nt">&quot;user_flags&quot;</span><span class="p">:</span> <span class="p">[]</span>
<span class="p">}</span>

<span class="k">TASK</span> <span class="p">[</span><span class="l">paused</span><span class="p">]</span> <span class="nv">************************************************************************************************************************************</span>
<span class="w">Sunday 11 November 2018  20:16:48 +0100 (0:00:00.041)       0:07:59.637 *******</span>
<span class="gd">--- before</span>
<span class="gi">+++ after</span>
<span class="gu">@@ -1,5 +1,5 @@</span>
<span class="w"> </span>{
<span class="gd">-  &quot;exists&quot;: false,</span>
<span class="gd">-  &quot;paused&quot;: false,</span>
<span class="gd">-  &quot;running&quot;: false</span>
<span class="gi">+  &quot;exists&quot;: true,</span>
<span class="gi">+  &quot;paused&quot;: true,</span>
<span class="gi">+  &quot;running&quot;: true</span>
<span class="w"> </span>}
<span class="w">\ No newline at end of file</span>

<span class="k">changed</span><span class="p">:</span> <span class="p">[</span><span class="nv">localhost</span><span class="p">]</span>

<span class="k">TASK</span> <span class="p">[</span><span class="l">volumes (more volumes)</span><span class="p">]</span> <span class="nv">********************************************************************************************************************</span>
<span class="w">Sunday 11 November 2018  20:19:25 +0100 (0:00:00.607)       0:10:36.974 *******</span>
<span class="gd">--- before</span>
<span class="gi">+++ after</span>
<span class="gu">@@ -1,11 +1,11 @@</span>
<span class="w"> </span>{
<span class="w"> </span>  &quot;expected_binds&quot;: [
<span class="gd">-    &quot;/tmp:/tmp:rw&quot;,</span>
<span class="gd">-    &quot;/:/whatever:rw,z&quot;</span>
<span class="gi">+    &quot;/tmp:/somewhereelse:ro,Z&quot;,</span>
<span class="gi">+    &quot;/tmp:/tmp:rw&quot;</span>
<span class="w"> </span>  ],
<span class="w"> </span>  &quot;expected_volumes&quot;: {
<span class="gd">-    &quot;/tmp&quot;: {},</span>
<span class="gd">-    &quot;/whatever&quot;: {}</span>
<span class="gi">+    &quot;/somewhereelse&quot;: {},</span>
<span class="gi">+    &quot;/tmp&quot;: {}</span>
<span class="w"> </span>  },
<span class="w"> </span>  &quot;running&quot;: true
<span class="w"> </span>}
<span class="w">\ No newline at end of file</span>

<span class="k">changed</span><span class="p">:</span> <span class="p">[</span><span class="nv">localhost</span><span class="p">]</span>
</pre></div>
"""