-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanual_test.py
37 lines (32 loc) · 1.24 KB
/
manual_test.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
import sqlite3
import zlib
from email import message_from_bytes
import pkg_metadata
def match(d1, d2):
"""Match ignoring whitespace differences in values"""
assert d1.keys() == d2.keys(), f"{sorted(d1.keys())} vs {sorted(d2.keys())}"
for k in d1:
if isinstance(d1[k], list):
v1 = [v.replace("\n", "").replace(" ", "") for v in d1[k]]
v2 = [v.replace("\n", "").replace(" ", "") for v in d2[k]]
assert v1 == v2, f"{k}: {d1[k]} vs {d2[k]}"
else:
assert d1[k].replace("\n", "").replace(" ", "") == d2[k].replace(
"\n", ""
).replace(" ", ""), f"{k}: {d1[k]} vs {d2[k]}"
conn = sqlite3.connect(r"..\pypidata\Metadata.db")
for file, meta in conn.execute("select filename, metadata from project_metadata"):
meta = zlib.decompress(meta)
msg = message_from_bytes(meta)
try:
j = pkg_metadata.msg_to_dict(msg)
m = pkg_metadata.dict_to_bytes(j)
j2 = pkg_metadata.msg_to_dict(message_from_bytes(m))
if j.get("description", "xxx") == "" and "description" not in j2:
j2["description"] = ""
match(j, j2)
except Exception:
print(file)
print(meta)
print(msg.as_string())
raise