def test_good_boolean(Cls): circle1 = ast.Circle(5.5) circle2 = ast.Circle(2) try: result = Cls(items=[circle1, circle2]) except ValueError: pytest.fail() assert len(result.items) == 2 assert result.items[0] == circle1
def setup_class(cls): cls.shapes = [ ast.Circle(3), ast.Circle(8), ast.Circle(5), ] cls.union = ast.Union(items=[ ast.Translate(0, 0, 0, ast.Cylinder(10, 3, 8)), ast.Translate(0, 0, 10, ast.Cylinder(10, 8, 5)), ])
def test_good_linear_extrusion(): try: linear_extrusion = ast.LinearExtrusion(10, ast.Circle(3)) except ValueError: pytest.fail() assert linear_extrusion.height == 10 assert linear_extrusion.item.radius == 3
def test_good_rotate(): circle = ast.Circle(5.5) try: rotate = ast.Rotate(90, (1, 0, 0), item=circle) except ValueError: pytest.fail() assert rotate.degrees == 90 assert rotate.vector == (1, 0, 0)
def test_good_translate(): circle = ast.Circle(5.5) try: translate = ast.Translate(x=1, y=-0.5, z=0, item=circle) except ValueError: pytest.fail() assert translate.x == 1 assert translate.y == -0.5 assert translate.z == 0 assert translate.item == circle
def test_bad_circle(radius): with pytest.raises(ValueError): ast.Circle(radius)
def test_good_rotate_extrusion(): try: rotate_extrusion = ast.RotateExtrusion(ast.Circle(3)) except ValueError: pytest.fail() assert rotate_extrusion.item.radius == 3
def test_good_circle(): try: circle = ast.Circle(5.5) except ValueError: pytest.fail() assert circle.radius == 5.5
def test_equality(): """Equality should only compare attribute values, not identity.""" c1 = ast.Circle(42) c2 = ast.Circle(42) assert c1 == c2
def test_good_rotate(): circle = ast.Circle(5.5) try: rotate = ast.Rotate(90, (1, 0, 0), item=circle) except ValueError: pytest.fail() assert rotate.degrees == 90 assert rotate.vector == (1, 0, 0) @pytest.mark.parametrize( ('degrees', 'vector', 'item'), [ (30, (1, 0, 0), None), # no item (30, (1, 0, 0), 'item'), # non-AST item (30, '1, 0, 0', ast.Circle(1)), # invalid vector (30, (1, 0), ast.Circle(1)), # invalid vector (30, (0, 0, 0), ast.Circle(1)), # invalid vector (30, (2, 0, 0), ast.Circle(1)), # invalid vector (30, (0.5, 0, 0), ast.Circle(1)), # invalid vector ]) def test_bad_rotate(degrees, vector, item): with pytest.raises(ValueError): ast.Rotate(degrees, vector, item) def test_good_scale(): cylinder = ast.Cylinder(10, 2, 2) try: scale = ast.Scale(x=1, y=0.5, z=2, item=cylinder) except ValueError:
def test_connect_invalid_arguments(): """Test that arguments for ``connect_2d_shapes`` are validated.""" shapes = [ast.Circle(5), ast.Circle(2)] with pytest.raises(AssertionError): utils.connect_2d_shapes(shapes, 10, 'diagonal')
def test_connect_heterogenous_handling(): """Assert that heterogenous shapes cannot be merged.""" shapes = [ast.Circle(5), ast.Rectangle(2, 3)] with pytest.raises(NotImplementedError): utils.connect_2d_shapes(shapes, 10, 'vertical')