Skip to content

Commit

Permalink
add test for --expression argument
Browse files Browse the repository at this point in the history
  • Loading branch information
justbuchanan committed Nov 23, 2023
1 parent 3f74867 commit a98b9a7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,53 @@ def test_exit_codes():

# Make sure that we got exit code 100 for a failed model build
assert exitcode == 100


def test_expression_argument():
"""
Tests the CLI with the the expression argument.
"""
test_file = helpers.get_test_file_location("no_toplevel_objects.py")

# Get a temporary output file location
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_test_10.step")

command = [
"python",
"src/cq_cli/main.py",
"--codec",
"step",
"--infile",
test_file,
"--outfile",
temp_file,
"--expression",
"cube()",
]
out, err, exitcode = helpers.cli_call(command)

# Read the STEP output back from the outfile
with open(temp_file, "r") as file:
step_str = file.read()

assert step_str.startswith("ISO-10303-21;")

# Run cq-cli on the same model file, but don't specify an --expression. This
# should fail because the file contains no top-level show_object() calls.
command = [
"python",
"src/cq_cli/main.py",
"--codec",
"step",
"--infile",
test_file,
"--outfile",
temp_file,
]
out, err, exitcode = helpers.cli_call(command)

print("err: %s" % err.decode())

# cq-cli invocation should fail
assert exitcode == 200
7 changes: 7 additions & 0 deletions tests/testdata/no_toplevel_objects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import cadquery as cq

# This test file contains a method for creating a shape, but does not contain
# any top-level `show_object()` calls.

def cube():
return cq.Workplane().box(1, 1, 1)

0 comments on commit a98b9a7

Please sign in to comment.