コード例 #1
0
ファイル: test_asdf_time.py プロジェクト: CagtayFabry/weldx
def test_time_classes(inputs, time_ref):
    data = write_read_buffer({"root": inputs})
    assert np.all(data["root"] == inputs)

    if isinstance(inputs, pd.Index) and not inputs.is_monotonic:
        # this is not valid for the time class, hence cancel here
        return

    t1 = Time(inputs, time_ref)
    t2 = write_read_buffer({"root": t1})["root"]
    assert t1.equals(t2)
コード例 #2
0
ファイル: test_asdf_graph.py プロジェクト: CagtayFabry/weldx
    def test_graph_exceptions(self):
        self.graph.remove_edge("A", "C")  # two trees in graph
        with pytest.raises(ValueError):
            write_read_buffer(dict(graph=self.graph))
        self.graph.remove_nodes_from(("C", "D"))  # cleanup

        self.graph.add_edge("H", "A")  # create loop
        with pytest.raises(ValueError):
            write_read_buffer(dict(graph=self.graph))

        with pytest.raises(KeyError):
            self.graph_uuid._wx_keep_uuid_name = False
            g = self.graph_uuid
            self._assert_roundtrip(g)
コード例 #3
0
def test_dataset_children():
    da = xr.DataArray(np.arange(10),
                      name="arr1",
                      attrs={"name": "sample data"})
    ds = da.to_dataset()
    ds2 = write_read_buffer({"ds": ds})["ds"]
    assert ds2.identical(ds)
コード例 #4
0
ファイル: test_asdf_groove.py プロジェクト: CagtayFabry/weldx
def test_asdf_groove(groove: IsoBaseGroove, expected_dtype):
    """Test ASDF functionality for all grooves.

    Parameters
    ----------
    groove:
       Groove instance to be tested.

    expected_dtype:
       Expected type of the groove to be tested.

    """
    k = "groove"
    tree = {k: groove}

    data = write_read_buffer(tree)
    assert isinstance(
        data[k], expected_dtype
    ), f"Did not match expected type {expected_dtype} on item {data[k]}"
    # test content equality using dataclass built-in functions
    assert (groove == data[k]
            ), f"Could not correctly reconstruct groove of type {type(groove)}"
    # test to_profile
    assert isinstance(
        groove.to_profile(),
        Profile), f"Error calling plot function of {type(groove)} "

    # call plot function
    fig, ax = plt.subplots()
    groove.plot(ax=ax)
    plt.close(fig)
コード例 #5
0
def test_dataarray():
    da = xr.DataArray(np.random.randn(2, 3),
                      dims=("x", "y"),
                      coords={"x": [10, 20]})
    da.attrs["long_name"] = "random velocity"
    # add metadata to coordinate
    da.x.attrs["units"] = "x units"
    da2 = write_read_buffer({"da": da})["da"]
    assert da2.identical(da)
コード例 #6
0
def test_measurement_chain(copy_arrays, lazy_load, measurement_chain):
    """Test the asdf serialization of the measurement chain."""
    tree = {"m_chain": measurement_chain}
    data = write_read_buffer(tree,
                             open_kwargs={
                                 "copy_arrays": copy_arrays,
                                 "lazy_load": lazy_load
                             })
    mc_file = data["m_chain"]
    assert measurement_chain == mc_file
コード例 #7
0
ファイル: test_asdf_graph.py プロジェクト: CagtayFabry/weldx
    def _assert_roundtrip(g):
        data = write_read_buffer(dict(graph=g))
        g2 = data["graph"]

        for node in g:
            assert g.nodes[node] == g2.nodes[node]

        for edge in g.edges:
            assert g.edges[edge] == g2.edges[edge]

        assert set(g.nodes) == set(g2.nodes)
        assert set(g.edges) == set(g2.edges)
コード例 #8
0
ファイル: test_asdf_types.py プロジェクト: CagtayFabry/weldx
def test_meta_attr():
    e = Error(3.0)

    ts = pd.DatetimeIndex(["2020", "2021"])
    setattr(ts, META_ATTR, {"name": "reference years"})

    setattr(e, META_ATTR, {"ts": ts})
    setattr(e, USER_ATTR, {"description": "user info"})

    tree = {"Error": e}

    data = write_read_buffer(tree)

    e2 = data["Error"]

    assert e2 == e
    assert compare_nested(getattr(e2, META_ATTR), getattr(e, META_ATTR))
    assert compare_nested(getattr(e2, USER_ATTR), getattr(e, USER_ATTR))
    assert compare_nested(getattr(getattr(e2, META_ATTR)["ts"], META_ATTR),
                          getattr(ts, META_ATTR))
コード例 #9
0
def test_shape_validator(test_input):
    result = write_read_buffer({"root": test_input}, )["root"]
    assert compare_nested(test_input.__dict__, result.__dict__)
    assert compare_nested(result.__dict__, test_input.__dict__)
コード例 #10
0
def test_gmaw_process(inputs):
    data = write_read_buffer({"root": inputs})
    assert data["root"] == inputs