Files
modeling-app/rust/kcl-python-bindings/tests/tests.py
Jess Frazelle d9fe78171f parallelized modules from kcl (#6206)
* wip

* sketch a bit more; going to pull this out of tests next

* wip

* lock start things

* this was a bad idea

* Revert "this was a bad idea"

This reverts commit a2092e7ed6.

* prepare prelude before spawning

* error

* poop

* yike

* :(

* ok

* Reapply "this was a bad idea"

This reverts commit fafdf41093.

* chip away more

* man this is bad

* fix rebase add feature flag

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* get rid of execution kind

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* clippy

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* logs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* no extra executes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* race w batch

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* cluppy

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* no printlns

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* no printlns

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix source ranges

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* batch shit

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix some bugs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix error

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* cut 1

* preserve mem

* re-ad deep_clone

the helper we were calling was pushing a new call, which was hanging
out. we can skip the middleman since we already have something properly
prepared, just without a stdlib in some cases.

* skip non-kcl

* clean up source range bug

* error message changed

the uuids also changed because the error is hit before execute even
starts.

* typo

* rensnapshot a few

* order things

* MAYBE REVERT LATER:

attempt at an ordering

* snapsnap

* Revert "snapsnap"

This reverts commit 7350b32c7d.

* Revert "MAYBE REVERT LATER:"

This reverts commit ab49f3e85f.

* ugh

* poop

* poop2

* lint

* tranche 1

* more

* more snaps

* snap

* more

* update

* MAYBE REVERT THIS

* cache multi-file

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* addd tests

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* set to false

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* add test outputs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* clippy

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* kcl-py-bindings uses carwheel

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* update snapshots

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: Paul R. Tagliamonte <paul@zoo.dev>
Co-authored-by: Paul Tagliamonte <paultag@gmail.com>
2025-04-16 11:52:14 -07:00

170 lines
4.7 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import kcl
import pytest
# Get the path to this script's parent directory.
files_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "files")
kcl_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "..", "kcl-lib"
)
tests_dir = os.path.join(kcl_dir, "tests")
lego_file = os.path.join(kcl_dir, "e2e", "executor", "inputs", "lego.kcl")
car_wheel_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"..",
"..",
"..",
"public",
"kcl-samples",
"car-wheel-assembly",
)
@pytest.mark.asyncio
async def test_kcl_execute_with_exception():
# Read from a file.
try:
await kcl.execute(os.path.join(files_dir, "parse_file_error"))
except Exception as e:
assert e is not None
assert len(str(e)) > 0
assert "lksjndflsskjfnak;jfna##" in str(e)
@pytest.mark.asyncio
async def test_kcl_execute():
# Read from a file.
await kcl.execute(lego_file)
@pytest.mark.asyncio
async def test_kcl_execute_code():
# Read from a file.
with open(lego_file, "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
await kcl.execute_code(code)
@pytest.mark.asyncio
async def test_kcl_execute_code_and_snapshot():
# Read from a file.
with open(lego_file, "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
image_bytes = await kcl.execute_code_and_snapshot(code, kcl.ImageFormat.Jpeg)
assert image_bytes is not None
assert len(image_bytes) > 0
@pytest.mark.asyncio
async def test_kcl_execute_code_and_export():
# Read from a file.
with open(lego_file, "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
files = await kcl.execute_code_and_export(code, kcl.FileExportFormat.Step)
assert files is not None
assert len(files) > 0
assert files[0] is not None
name = files[0].name
contents = files[0].contents
assert name is not None
assert len(name) > 0
assert contents is not None
assert len(contents) > 0
@pytest.mark.asyncio
async def test_kcl_execute_dir_assembly():
# Read from a file.
await kcl.execute(car_wheel_dir)
@pytest.mark.asyncio
async def test_kcl_execute_and_snapshot():
# Read from a file.
image_bytes = await kcl.execute_and_snapshot(lego_file, kcl.ImageFormat.Jpeg)
assert image_bytes is not None
assert len(image_bytes) > 0
@pytest.mark.asyncio
async def test_kcl_execute_and_snapshot_dir():
# Read from a file.
image_bytes = await kcl.execute_and_snapshot(
car_wheel_dir, kcl.ImageFormat.Jpeg
)
assert image_bytes is not None
assert len(image_bytes) > 0
@pytest.mark.asyncio
async def test_kcl_execute_and_export():
# Read from a file.
files = await kcl.execute_and_export(lego_file, kcl.FileExportFormat.Step)
assert files is not None
assert len(files) > 0
assert files[0] is not None
name = files[0].name
contents = files[0].contents
assert name is not None
assert len(name) > 0
assert contents is not None
assert len(contents) > 0
def test_kcl_format():
# Read from a file.
with open(lego_file, "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
formatted_code = kcl.format(code)
assert formatted_code is not None
assert len(formatted_code) > 0
@pytest.mark.asyncio
async def test_kcl_format_dir():
await kcl.format_dir(car_wheel_dir)
def test_kcl_lint():
# Read from a file.
with open(os.path.join(files_dir, "box_with_linter_errors.kcl"), "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
lints = kcl.lint(code)
assert lints is not None
assert len(lints) > 0
description = lints[0].description
assert description is not None
assert len(description) > 0
finding = lints[0].finding
assert finding is not None
finding_title = finding.title
assert finding_title is not None
assert len(finding_title) > 0
@pytest.mark.asyncio
async def test_kcl_execute_code_and_export_with_bad_units():
bad_units_file = os.path.join(tests_dir, "bad_units_in_annotation", "input.kcl")
# Read from a file.
with open(bad_units_file, "r") as f:
code = str(f.read())
assert code is not None
assert len(code) > 0
try:
await kcl.execute_code_and_export(code, kcl.FileExportFormat.Step)
except Exception as e:
assert e is not None
assert len(str(e)) > 0
print(e)
assert "[1:1]" in str(e)