Exemple #1
0
def test_jsonext_load(tmp_path):
    c = _C(1, 'foo')
    c.x += 1
    c.y = 'foobar'
    c.z = _Z()
    c.z.a += 1
    c.z.b = 'barfoo'
    c.t = _T()
    c.t.t = 5

    json_dump = tmp_path / 'test.json'
    with open(json_dump, 'w') as fp:
        jsonext.dump(c, fp, indent=2)

    with open(json_dump, 'r') as fp:
        print(fp.read())

    with open(json_dump, 'r') as fp:
        c_restored = jsonext.load(fp)

    assert c == c_restored
    assert c is not c_restored

    # Do the same with dumps() and loads()
    c_restored = jsonext.loads(jsonext.dumps(c))
    assert c == c_restored
    assert c is not c_restored
Exemple #2
0
    def _do_restore(self, testcase):
        tc = self.case(*testcase)
        if tc is None:
            raise errors.ReframeError(
                f'could not restore testcase {testcase!r}: '
                f'not found in the report files')

        dump_file = os.path.join(tc['stagedir'], '.rfm_testcase.json')
        try:
            with open(dump_file) as fp:
                testcase._check = jsonext.load(fp)
        except (OSError, json.JSONDecodeError) as e:
            raise errors.ReframeError(
                f'could not restore testcase {testcase!r}') from e