def test_JSON(): data = dict(one=1, two=2.0, three=[4, 5]) tmpf = tempfile.NamedTemporaryFile(suffix='.json', delete=False) tmpf.close() pobj = JSON(tmpf.name) try: pobj.save(data) databounced = pobj.read() for k in data: d = data[k] bd = databounced[k] assert d == bd assert type(d) == type(bd) finally: os.unlink(pobj.filename)
def test_parentdir(self): """Check whether the file reference can be made absolute after construction.""" data = dict(one=1, two=2.0, three=[4, 5]) testdir = path(tempfile.mkdtemp(dir='.')) try: pobj = JSON('test.json') pobj.set_parentdir(testdir) pobj.save(data) pobj.read() assert (testdir / 'test.json').exists() # Check auto subdirectory creation (FileBase._mkdir()) pobj = JSON('subdir/test.json') pobj.set_parentdir(testdir) pobj.save(data) pobj.read() assert (testdir / 'subdir' / 'test.json').exists() pobj = Pandas('subdir/test.h5') pobj.set_parentdir(testdir) pobj.save(pandas.DataFrame([data,])) pobj.read() assert (testdir / 'subdir' / 'test.h5').exists() finally: shutil.rmtree(testdir)
def test_parentdir(self): """Check whether the file reference can be made absolute after construction.""" data = dict(one=1, two=2.0, three=[4, 5]) testdir = Path(tempfile.mkdtemp(dir='.')) try: pobj = JSON('test.json') pobj.set_parentdir(testdir) pobj.save(data) pobj.read() assert (testdir / 'test.json').exists() # Check auto subdirectory creation (FileBase._mkdir()) pobj = JSON('subdir/test.json') pobj.set_parentdir(testdir) pobj.save(data) pobj.read() assert (testdir / 'subdir' / 'test.json').exists() pobj = Pandas('subdir/test.h5') pobj.set_parentdir(testdir) pobj.save(pandas.DataFrame([data,])) pobj.read() assert (testdir / 'subdir' / 'test.h5').exists() finally: shutil.rmtree(testdir)