Ejemplo n.º 1
0
    def test_hash_value_update(self):
        """tests that the hash_value of the shape is not updated until a new solid has been created"""

        test_shape = ExtrudeStraightShape(points=[(0, 0), (0, 20), (20, 20)],
                                          distance=20)
        test_shape.solid
        assert test_shape.hash_value is not None
        initial_hash_value = test_shape.hash_value

        test_shape.distance = 30

        assert test_shape.hash_value == initial_hash_value
        test_shape.solid
        assert test_shape.hash_value != initial_hash_value
Ejemplo n.º 2
0
    def test_conditional_solid_reconstruction(self):
        """tests that a new cadquery solid with a new unique hash is constructed when .solid is called again after changes have been made to the shape"""

        test_shape = ExtrudeStraightShape(points=[(0, 0), (0, 20), (20, 20)],
                                          distance=20)

        assert test_shape.solid is not None
        assert test_shape.hash_value is not None
        initial_hash_value = test_shape.hash_value

        test_shape.distance = 30

        assert test_shape.solid is not None
        assert test_shape.hash_value is not None
        assert initial_hash_value != test_shape.hash_value
Ejemplo n.º 3
0
    def test_conditional_solid_reconstruction_parameters(self):
        """tests that a new cadquery solid with a new unique hash is created when the shape properties of points, distance, workplane, name, color, material_tag, stp_filename, azimuth_placement_angle or cut are changed"""

        # points
        test_shape = ExtrudeStraightShape(points=[(0, 0), (0, 20), (20, 20)],
                                          distance=20)
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.points = [(0, 0), (10, 30), (15, 50), (25, 5), (15, 0)]
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # distance
        test_shape = ExtrudeStraightShape(points=[(0, 0), (0, 20), (20, 20)],
                                          distance=20)
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.distance = 30
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # workplane
        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
            workplane="XZ",
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.workplane = "YZ"
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # name
        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
            name='test_name',
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.name = 'new_name'
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # color
        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
            color=[0.5, 0.5, 0.5],
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.color = [0.1, 0.2, 0.8]
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # material_tag
        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
            material_tag='test_material',
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.material_tag = 'new_material'
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # stp_filename
        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
            stp_filename='test_filename.stp',
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.stp_filename = 'new_filename.stp'
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # azimuth_placement_angle
        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
            azimuth_placement_angle=0,
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.azimuth_placement_angle = 180
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value

        # cut
        cut_shape = ExtrudeStraightShape(points=[(5, 5), (5, 15), (15, 15)],
                                         distance=5)

        test_shape = ExtrudeStraightShape(
            points=[(0, 0), (0, 20), (20, 20)],
            distance=20,
        )
        test_shape.solid
        initial_hash_value = test_shape.hash_value
        test_shape.cut = cut_shape
        test_shape.solid
        assert test_shape.solid is not None
        assert test_shape.hash_value != initial_hash_value