Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_anonimowe_parse(files, snapshot):
snapshot.assert_match(jsons.dumps(anonimowe.parse(files["anonimowe.html"])))
def test_demotywatory_parse(files, snapshot, monkeypatch):
def fake_download(url):
f = "demot-{}.html".format(utils.get_last_part_url(url))
if f in files:
return files[f]
raise Exception()
monkeypatch.setattr("parsers.demoty.download", fake_download)
snapshot.assert_match(jsons.dumps(demoty.parse(files["demotywatory.html"])))
def test_mistrzowie_parse(files, snapshot):
snapshot.assert_match(jsons.dumps(mistrzowie.parse(files["mistrzowie.html"])))
def test_dumps(self):
class A:
def __init__(self):
self.name = 'A'
class B:
def __init__(self, a: A):
self.a = a
self.name = 'B'
sdumped = jsons.dumps(B(A()))
s = json.dumps({'a': {'name': 'A'}, 'name': 'B'})
self.assertDictEqual(eval(s), eval(sdumped))
def test_ninegag_parse(files, snapshot):
snapshot.assert_match(jsons.dumps(ninegag.parse(files["9gag.json"])))
def serialize(dataclass):
"""Serialize data class attributes."""
return jsons.loads(jsons.dumps(dataclass))
def to_response(page):
return jsons.dumps(page)
def from_dict(cls: T, d: Dict) -> T:
"""Serialize dictionary to dataclass of type T."""
return jsons.loads(jsons.dumps(d), cls)