Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)