Exemplo n.º 1
0
 def test_nested_sets():
     a = dict(x={("bar", (1, 2)), 1, 2, 3})
     b = dict(x={("baz", (1, 2, 3)), 1, 2, 3})
     b1 = copy.deepcopy(b)
     c = dict(x={((1, 2, 3), "baz"), 1, 2, 3})
     assert not ut.compare_nested(a, b)
     assert not ut.compare_nested(b, a)
     assert ut.compare_nested(b, b1)
     assert not ut.compare_nested(b, c)
Exemplo n.º 2
0
    def test_copy(self, file, tmpdir):
        """Take a copy written to physical file, bytesio and check output."""
        if file == "physical":
            file = tempfile.mktemp(suffix=".wx", dir=tmpdir)

        wx_copy = self.fh.copy(filename_or_file_like=file)

        assert wx_copy.mode == self.fh.mode
        assert wx_copy.sync_upon_close == self.fh.sync_upon_close
        assert wx_copy.custom_schema == self.fh.custom_schema
        assert wx_copy.software_history_entry == self.fh.software_history_entry

        assert wx_copy._asdffile_kwargs == self.fh._asdffile_kwargs
        assert wx_copy._write_kwargs == self.fh._write_kwargs

        compare_nested(self.fh, wx_copy)
Exemplo n.º 3
0
    def test_coordinate_systems_modified(self):  # noqa: D102
        """Manipulate one CSM and check if it gets picked up by comparison."""
        csm_org = self.a["coordinate_systems"]
        csm_copy = self.b["coordinate_systems"]

        # first ensure, that the cs exists, as delete_cs won't tell us.
        assert csm_copy.get_cs("tcp_contact")
        csm_copy.delete_cs("tcp_contact")

        assert csm_copy != csm_org
        assert not ut.compare_nested(self.a, self.b)
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
 def test_key_added(_default_dicts):  # noqa: D102
     a, b = (dict(a=1), dict(a=1, b=1))
     assert not ut.compare_nested(a, b)
     assert not ut.compare_nested(b, a)
Exemplo n.º 6
0
 def test_equip_modified(self):  # noqa: D102
     self.b["equipment"][0].name = "broken device"
     assert not ut.compare_nested(self.a, self.b)
Exemplo n.º 7
0
 def test_measurements_modified(self):  # noqa: D102
     self.b["welding_current"].data[-1] = Q_(500, "A")
     assert not ut.compare_nested(self.a, self.b)
Exemplo n.º 8
0
 def test_metadata_modified(self):  # noqa: D102
     self.b[META_ATTR]["welder"] = "anonymous"
     assert not ut.compare_nested(self.a, self.b)
Exemplo n.º 9
0
 def test_equal(self):  # noqa: D102
     assert ut.compare_nested(self.a, self.b)
Exemplo n.º 10
0
 def test_eq_(_default_dicts):  # noqa: D102
     a, b = _default_dicts
     assert ut.compare_nested(a, b)
Exemplo n.º 11
0
 def test_compare_nested(a, b, expected):  # noqa: D102
     assert ut.compare_nested(a, b) == expected
Exemplo n.º 12
0
def test_aws_example():
    """Test validity of current AWS Data Dictionary standard implementation."""
    # welding process -----------------------------------------------------------------
    gas_comp = [
        GasComponent("argon", Q_(82, "percent")),
        GasComponent("carbon dioxide", Q_(18, "percent")),
    ]
    gas_type = ShieldingGasType(gas_component=gas_comp, common_name="SG")

    gas_for_procedure = ShieldingGasForProcedure(
        use_torch_shielding_gas=True,
        torch_shielding_gas=gas_type,
        torch_shielding_gas_flowrate=Q_(20, "l / min"),
    )

    arc_welding_process = ArcWeldingProcess("GMAW")
    with pytest.raises(ValueError):  # test for non viable process string
        ArcWeldingProcess("NON_EXISTENT_PROCESS")

    process = {
        "arc_welding_process": arc_welding_process,
        "shielding_gas": gas_for_procedure,
    }

    # weld design -----------------------------------------------------------------
    v_groove = get_groove(
        groove_type="VGroove",
        workpiece_thickness=Q_(9, "mm"),
        groove_angle=Q_(50, "deg"),
        root_face=Q_(4, "mm"),
        root_gap=Q_(2, "mm"),
    )
    u_groove = get_groove(
        groove_type="UGroove",
        workpiece_thickness=Q_(15, "mm"),
        bevel_angle=Q_(9, "deg"),
        bevel_radius=Q_(6, "mm"),
        root_face=Q_(3, "mm"),
        root_gap=Q_(1, "mm"),
    )

    joint_penetration = JointPenetration(
        complete_or_partial="completePenetration",
        root_penetration=Q_(1.0, "mm"))
    weld_details = WeldDetails(joint_design=v_groove,
                               weld_sizes=Q_(320, "mm"),
                               number_of_passes=1)
    weld_details2 = WeldDetails(joint_design=u_groove,
                                weld_sizes=Q_(320, "mm"),
                                number_of_passes=1)
    connection1 = Connection(
        joint_type="butt_joint",
        weld_type="singleVGroove",
        joint_penetration=joint_penetration,
        weld_details=weld_details,
    )
    connection2 = Connection(
        joint_type="butt_joint",
        weld_type="singleUGroove",
        joint_penetration=joint_penetration,
        weld_details=weld_details2,
    )
    workpieces = [Workpiece(geometry="V-Groove")]
    sub_assembly = [
        SubAssembly(workpiece=workpieces, connection=connection1),
        SubAssembly(workpiece=workpieces, connection=connection2),
    ]

    weldment = Weldment(sub_assembly)

    base_metal = BaseMetal("steel", "plate", Q_(10.3, "mm"))

    tree = dict(process=process, weldment=weldment, base_metal=base_metal)

    data = write_read_buffer(tree)
    data.pop("asdf_library", None)
    data.pop("history", None)
    assert compare_nested(data, tree)
Exemplo n.º 13
0
 def test_key_changed2(_default_dicts):  # noqa: D102
     a, b = _default_dicts
     x = b.pop("x")
     b["y"] = x
     assert not ut.compare_nested(a, b)
Exemplo n.º 14
0
 def test_key_changed1(_default_dicts):  # noqa: D102
     a, b = _default_dicts
     del b["x"]
     assert not ut.compare_nested(a, b)
Exemplo n.º 15
0
 def test_value_changed(_default_dicts):  # noqa: D102
     a, b = _default_dicts
     b["bar"] = False
     assert not ut.compare_nested(a, b)
Exemplo n.º 16
0
 def test_added_value_left(_default_dicts):  # noqa: D102
     a, b = _default_dicts
     a["x"][0].append(4)
     assert not ut.compare_nested(a, b)
Exemplo n.º 17
0
 def test_missing_values(_default_dicts):  # noqa: D102
     a, b = _default_dicts
     b["x"][0].pop(-1)
     assert not ut.compare_nested(a, b)
Exemplo n.º 18
0
 def test_array_accessible_by_two_roots():  # noqa: D102
     a = {"l1": {"l2": np.arange(5)}}
     b = {"l1": {"l2": np.arange(5)}}
     assert ut.compare_nested(a, b)
Exemplo n.º 19
0
 def test_arrays_in_lists():  # noqa: D102
     a = {"l1": [np.arange(1), "foo"]}
     b = {"l1": [np.arange(2), "foo"]}
     assert not ut.compare_nested(a, b)
Exemplo n.º 20
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__)
Exemplo n.º 21
0
 def test_compare_nested_raise(a, b):  # noqa: D102
     """non-nested types should raise TypeError."""
     with pytest.raises(TypeError):
         ut.compare_nested(a, b)