def test_creation_from_string():
    """Test simplified datadict generation"""
    str_ok_1 = "z(x,y)"
    dd = str2dd(str_ok_1)
    assert dd.validate()
    assert set(list(dd.keys())) == {'x', 'y', 'z'}
    assert dd.axes('z') == ['x', 'y']
    assert dd.axes('x') == []

    str_ok_2 = "z1[V](x, y); z2[A](y, x); x[mT]"
    dd = str2dd(str_ok_2)
    assert dd.validate()
    assert set(dd.dependents()) == {'z1', 'z2'}
    assert dd['z1']['unit'] == 'V'
    assert dd['x']['unit'] == 'mT'

    # conflicting units -- should raise ValueError
    str_notok = "z[V](x[A], y[T]); x[mA]; y[T]"
    with pytest.raises(ValueError):
        dd = str2dd(str_notok)

    # cascaded dependency -- should raise ValueError
    str_notok = "z(x, y); x(y)"
    with pytest.raises(ValueError):
        dd = str2dd(str_notok)

    # no error raised, but x(a) is not recognized as valid dependency
    str_notok = "z(x(a))"
    dd = str2dd(str_notok)
    assert dd.validate()
    assert dd.dependents() == []
    assert dd.axes() == []
    assert 'z' in dd
Example #2
0
 def run(self):
     data = self.mkdata()
     with dds.DDH5Writer(dd.str2dd("x[W]; y[T](x)"),
                         filepath=self.filepath) as writer:
         self.filepath = writer.filepath
         for i in range(self.nreps):
             chunk = data[i * self.nrows_per_rep:(i + 1) *
                          self.nrows_per_rep, ...]
             writer.add_data(
                 x=chunk,
                 y=chunk**2,
             )
             time.sleep(self.delay)
Example #3
0
def test_writer():
    dataset = dd.str2dd("x[a.u.]; y[a.u.](x)")
    with dds.DDH5Writer(dataset, basedir='./TESTDATA') as writer:
        for i in range(10):
            x = _mkdatachunk(i, 1, 1)
            y = x**2
            writer.add_data(x=x, y=y)

    dataset_from_file = dds.datadict_from_hdf5(writer.filepath)
    assert '__last_change_time_sec__' in dataset_from_file
    assert '__last_change_time_str__' in dataset_from_file
    assert '__close_time_sec__' in dataset_from_file
    assert '__close_time_str__' in dataset_from_file
    assert _clean_from_file(dataset_from_file) == dataset

    rmtree('./TESTDATA')
def main(multi=False):
    def cb(value):
        print('Selection made:', value)

    data = str2dd("data1(x,y,z); data2(x,z);")

    if not multi:
        w = DimensionSelector()
        combo = w.combo
        combo.setDimensions(data.axes() + data.dependents())
        combo.dimensionSelected.connect(cb)
    else:
        w = MultiDimensionSelector()
        w.setDimensions(data.axes() + data.dependents())
        w.dimensionSelectionMade.connect(cb)

    return widgetDialog(w)