File: compare_data.py

package info (click to toggle)
python-friendly-traceback 0.7.62%2Bgit20240811.d7dbff6-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,264 kB
  • sloc: python: 21,500; makefile: 4
file content (185 lines) | stat: -rw-r--r-- 5,372 bytes parent folder | download
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import data_3_6
import data_3_7
import data_3_8
import data_3_9
import data_3_10

info_36 = data_3_6.info
info_37 = data_3_7.info
info_38 = data_3_8.info
info_39 = data_3_9.info
info_310 = data_3_10.info

output = open("compare_data.html", "w", encoding="utf8")

output.write("<div>\n")
files = set([])


def print_different(filename, in_36, in_37, in_38, in_39, in_310, topic):
    # Just tracking changes going forward in time, from
    # one version to the next.
    if topic == "message":
        header = "<h5>Different messages - from Python</h5>\n"
    else:
        header = "<h5>Different explanation - by Friendly-traceback</h5>\n"
    header_added = False

    inputs = {in_36, in_37, in_38, in_39, in_310}

    if in_36 != in_37:
        if filename not in files:
            output.write("<div class='filename-header'>\n")
            files.add(filename)
            output.write(filename)
            output.write("</div>\n")
        if not header_added:
            output.write(header)
            header_added = True
        output.write("<pre class='highlight friendly-small-pre'>")
        output.write("<b>3.6: </b>" + in_36 + "\n")
        output.write("<b>3.7: </b>" + in_37 + "\n")
        output.write("</pre>\n")
        inputs.remove(in_36)
        inputs.remove(in_37)
    if in_37 != in_38:
        if filename not in files:
            output.write("<div class='filename-header'>\n")
            files.add(filename)
            output.write(filename)
            output.write("</div>\n")
        if not header_added:
            output.write(header)
            header_added = True
        output.write("<pre class='highlight friendly-small-pre'>")
        if in_37 in inputs:
            output.write("<b>3.7: </b>" + in_37 + "\n")
            inputs.remove(in_37)
        output.write("<b>3.8: </b>" + in_38 + "\n")
        output.write("</pre>\n")
        inputs.remove(in_38)
    if in_38 != in_39:
        if filename not in files:
            output.write("<div class='filename-header'>")
            files.add(filename)
            output.write(filename)
            output.write("</div>\n")
        if not header_added:
            output.write(header)
            header_added = True
        output.write("<pre class='highlight friendly-small-pre'>")
        if in_38 in inputs:
            output.write("<b>3.8: </b>" + in_38 + "\n")
            inputs.remove(in_38)
        output.write("<b>3.9: </b>" + in_39 + "\n")
        output.write("</pre>\n")
        try:
            inputs.remove(in_39)
        except KeyError:
            pass
    if in_39 != in_310:
        if filename not in files:
            output.write("<div class='filename-header'>")
            files.add(filename)
            output.write(filename)
            output.write("</div>\n")
        if not header_added:
            output.write(header)
        output.write("<pre class='highlight friendly-small-pre'>")
        if in_39 in inputs:
            output.write("<b>3.9: </b>" + in_39 + "\n")
            inputs.remove(in_39)
        output.write("<b>3.10: </b>" + in_310 + "\n")
        output.write("</pre>\n")
        try:
            inputs.remove(in_310)
        except KeyError:
            pass


all_names = (
    set(info_36.keys())
    | set(info_37.keys())
    | set(info_38.keys())
    | set(info_39.keys())
    | set(info_310.keys())
)

not_an_error = (
    "Either not a SyntaxError for this Python version,"
    " or case excluded for some other reason."
)


for filename in all_names:
    if filename in info_36:
        data_36 = info_36[filename]
    else:
        data_36 = {
            "message": not_an_error,
            "cause": not_an_error,
        }

    if filename in info_37:
        data_37 = info_37[filename]
    else:
        data_37 = {
            "message": not_an_error,
            "cause": not_an_error,
        }

    if filename in info_38:
        data_38 = info_38[filename]
    else:
        data_38 = {
            "message": not_an_error,
            "cause": not_an_error,
        }

    if filename in info_39:
        data_39 = info_39[filename]
    else:
        data_39 = {
            "message": not_an_error,
            "cause": not_an_error,
        }

    if filename in info_310:
        data_310 = info_310[filename]
    else:
        data_310 = {
            "message": not_an_error,
            "cause": not_an_error,
        }

    # attempt = "I will attempt to be give a bit more information."
    # guess = "guess what caused the problem, but I might be wrong."
    # for data in [data_36, data_37, data_38, data_39, data_310]:
    #     if "cause" in data and data["cause"]:
    #         if attempt in data["cause"]:
    #             data["cause"] = data["cause"].split(attempt)[1]
    #         if guess in data["cause"]:
    #             data["cause"] = data["cause"].split(guess)[1]
    #         data["cause"] = data["cause"].strip()

    print_different(
        filename,
        data_36["message"],
        data_37["message"],
        data_38["message"],
        data_39["message"],
        data_310["message"],
        "message",
    )
    print_different(
        filename,
        data_36["cause"],
        data_37["cause"],
        data_38["cause"],
        data_39["cause"],
        data_310["cause"],
        "explanation",
    )

output.write("</div>\n")
output.close()