コード例 #1
0
def json_encode_decode(sp):
    """Take a strategy, encode it as json and build it back as a strategy."""
    __tracebackhide__ = True
    d = sp.to_jsonable()
    if not isinstance(d, dict):
        pytest.fail("to_jsonable does not return a dict. \n"
                    "Returned: {}".format(d))
    try:
        json_str = json.dumps(d)
    except TypeError as e:
        pytest.fail("The to_jsonable method returns a dictionnary that can "
                    "not be encoded as json string\n"
                    "Got error: {}".format(e))
    sp_new = TileScopePack.from_dict(json.loads(json_str))
    return sp_new
コード例 #2
0
 def from_uri(cls, URI: str) -> "GuidedSearcher":
     response = requests.get(URI)
     spec = CombinatorialSpecification.from_dict(
         response.json()["specification"])
     pack = TileScopePack.from_dict(response.json()["pack"]).make_tracked()
     return cls.from_spec(spec, pack)