Ejemplo n.º 1
0
def test_write():
    nd = scp.read_omnic('irdata/nh4y-activation.spg')

    # API write methods needs an instance of a NDDataset as the first argument
    with pytest.raises(TypeError):
        scp.write()

    # the simplest way to save a dataset, is to use the function write with a filename as argument
    filename = nd.write('essai.scp')
    assert filename == cwd / 'essai.scp'

    nd2 = NDDataset.load(filename)
    testing.assert_dataset_equal(nd2, nd)
    filename.unlink()

    # if the filename is omitted, the a dialog is opened to select a name (and a protocol)
    filename = nd.write()
    assert filename is not None
    assert filename.stem == nd.name
    assert filename.suffix == '.scp'
    filename.unlink()

    # # a write protocole can be specified
    # filename = nd.write(protocole='json')
    # assert filename is not None
    # assert filename.stem == nd.name
    # assert filename.suffix == '.json'
    # filename.unlink()

    irdatadir = pathclean(prefs.datadir) / "irdata"
    for f in ['essai.scp', 'nh4y-activation.scp']:
        if (irdatadir / f).is_file():
            (irdatadir / f).unlink()
Ejemplo n.º 2
0
def test_generic_read():
    # filename + extension specified
    ds = scp.read('wodger.spg')
    assert ds.name == 'wodger'

    # save with no filename (should save wodger.scp)
    path = ds.save()

    assert isinstance(path, Path)
    assert path.stem == ds.name
    assert path.parent == ds.directory

    # read should be équivalent to load (but read is a more general function,
    dataset = NDDataset.load('wodger.scp')
    assert dataset.name == 'wodger'
Ejemplo n.º 3
0
def test_write():
    nd = scp.read_omnic("irdata/nh4y-activation.spg")

    # API write methods needs an instance of a NDDataset as the first argument
    with pytest.raises(TypeError):
        scp.write()

    # the simplest way to save a dataset, is to use the function write with a filename as argument
    if (cwd / "essai.scp").exists():
        (cwd / "essai.scp").unlink()

    filename = nd.write("essai.scp")  # should not open a DIALOG
    assert filename == cwd / "essai.scp"
    assert filename.exists()

    # try to write it again
    filename = nd.write("essai.scp")  # should open a DIALOG to confirm

    nd2 = NDDataset.load(filename)
    testing.assert_dataset_equal(nd2, nd)
    filename.unlink()

    # if the filename is omitted, a dialog is opened to select a name (and a protocol)
    filename = nd.write()
    assert filename is not None
    assert filename.stem == nd.name
    assert filename.suffix == ".scp"
    filename.unlink()

    # # a write protocole can be specified
    # filename = nd.write(protocole='json')
    # assert filename is not None
    # assert filename.stem == nd.name
    # assert filename.suffix == '.json'
    # filename.unlink()

    irdatadir = pathclean(prefs.datadir) / "irdata"
    for f in ["essai.scp", "nh4y-activation.scp"]:
        if (irdatadir / f).is_file():
            (irdatadir / f).unlink()