Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cadquery/occ_impl/importers/assembly.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import cast
from path import Path
from pathlib import Path

from OCP.TopoDS import TopoDS_Shape
from OCP.TCollection import TCollection_ExtendedString
Expand Down Expand Up @@ -175,7 +175,8 @@ def importXbf(assy: AssemblyProtocol, path: str):
app = TDocStd_Application()
BinXCAFDrivers.DefineFormat_s(app)

dirname, fname = Path(path).absolute().splitpath()
p = Path(path).absolute()
dirname, fname = str(p.parent), p.name
doc = cast(
TDocStd_Document,
app.Retrieve(
Expand Down Expand Up @@ -204,7 +205,8 @@ def importXml(assy: AssemblyProtocol, path: str):
app = TDocStd_Application()
XmlXCAFDrivers.DefineFormat_s(app)

dirname, fname = Path(path).absolute().splitpath()
p = Path(path).absolute()
dirname, fname = str(p.parent), p.name
doc = cast(
TDocStd_Document,
app.Retrieve(
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies:
- ezdxf>=1.3.0
- typing_extensions
- nlopt
- path
- casadi
- runtype
- multimethod >=1.11,<2.0
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"nlopt>=2.9.0,<3.0",
"runtype",
"casadi",
"path",
"trame",
"trame-vtk",
"trame-components",
Expand Down
16 changes: 16 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
import os
from contextlib import contextmanager


def pytest_addoption(parser):
Expand All @@ -20,3 +22,17 @@ def pytest_collection_modifyitems(config, items):
for item in items:
if "gui" in item.keywords:
item.add_marker(skip_gui)


@pytest.fixture
def cwd():
@contextmanager
def _cwd(path):
oldpwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(oldpwd)

return _cwd
31 changes: 9 additions & 22 deletions tests/test_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from itertools import product
from math import degrees
import copy
from path import Path
from pathlib import Path
from pathlib import PurePath
import re
from pytest import approx
Expand Down Expand Up @@ -41,7 +41,7 @@

@pytest.fixture(scope="function")
def tmpdir(tmp_path_factory):
return Path(tmp_path_factory.mktemp("assembly"))
return tmp_path_factory.mktemp("assembly")


@pytest.fixture
Expand Down Expand Up @@ -557,18 +557,6 @@ def find_node(node_list, name_path):
:param name_path: list of node names (corresponding to path)
"""

def purepath_is_relative_to(p0, p1):
"""Alternative to PurePath.is_relative_to for Python 3.8
PurePath.is_relative_to is new in Python 3.9
"""
try:
if p0.relative_to(p1):
is_relative_to = True
except ValueError:
is_relative_to = False

return is_relative_to

def get_nodes(node_list, name, parents):
if parents:
nodes = []
Expand All @@ -577,8 +565,7 @@ def get_nodes(node_list, name, parents):
[
p
for p in node_list
# if p["path"].is_relative_to(parent["path"])
if purepath_is_relative_to(p["path"], parent["path"])
if p["path"].is_relative_to(parent["path"])
and len(p["path"].relative_to(parent["path"]).parents) == 1
and re.fullmatch(name, p["name"])
and p not in nodes
Expand Down Expand Up @@ -1376,18 +1363,18 @@ def test_save(extension, args, nested_assy, nested_assy_sphere):
("stl", ("STL",), {}),
],
)
def test_export(extension, args, kwargs, tmpdir, nested_assy):
def test_export(extension, args, kwargs, tmpdir, nested_assy, cwd):

filename = "nested." + extension

with tmpdir:
with cwd(tmpdir):
nested_assy.export(filename, *args, **kwargs)
assert os.path.exists(filename)


def test_export_vtkjs(tmpdir, nested_assy):
def test_export_vtkjs(tmpdir, nested_assy, cwd):

with tmpdir:
with cwd(tmpdir):
nested_assy.export("nested.vtkjs")
assert os.path.exists("nested.vtkjs.zip")

Expand Down Expand Up @@ -1553,7 +1540,7 @@ def test_colors_assy0(assy_fixture, request, tmpdir, kind):
"""

assy = request.getfixturevalue(assy_fixture)
stepfile = (Path(tmpdir) / assy_fixture).with_suffix(f".{kind}")
stepfile = str((Path(tmpdir) / assy_fixture).with_suffix(f".{kind}"))
assy.export(stepfile)

assy_i = assy.load(stepfile)
Expand Down Expand Up @@ -1585,7 +1572,7 @@ def test_colors_assy1(assy_fixture, request, tmpdir, kind):
"""

assy = request.getfixturevalue(assy_fixture)
stepfile = (Path(tmpdir) / assy_fixture).with_suffix(f".{kind}")
stepfile = str((Path(tmpdir) / assy_fixture).with_suffix(f".{kind}"))
assy.export(stepfile)

assy_i = assy.load(stepfile)
Expand Down
12 changes: 9 additions & 3 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from glob import glob
from itertools import chain, count

from path import Path
from pathlib import Path

from docutils.parsers.rst import directives
from docutils.core import publish_doctree
Expand All @@ -14,6 +14,11 @@
from cadquery.cq_directive import cq_directive


@pytest.fixture(scope="session")
def tmpdir(tmp_path_factory):
return tmp_path_factory.mktemp("examples")


def find_examples(pattern="examples/*.py", path=Path("examples")):

for p in glob(pattern):
Expand Down Expand Up @@ -56,10 +61,11 @@ def run(self):
@pytest.mark.parametrize(
"code, path", chain(find_examples(), find_examples_in_docs()), ids=count(0)
)
def test_example(code, path):
def test_example(code, path, tmpdir, cwd):

# build
with path:
with cwd(tmpdir):
# tmpdir is for future use; currently there are no examples that export files
res = cqgi.parse(code).build()

assert res.exception is None
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# core modules
import os
import io
from path import Path
from pathlib import Path
import re
import sys
import math
Expand Down
18 changes: 13 additions & 5 deletions tests/test_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
from vtkmodules.vtkRenderingAnnotation import vtkAnnotatedCubeActor
from vtkmodules.vtkIOImage import vtkPNGWriter

from pytest import fixture, raises
from path import Path
from pytest import fixture, raises, mark
import os
from pathlib import Path

from typing import List


@fixture(scope="module")
def tmpdir(tmp_path_factory):
return Path(tmp_path_factory.mktemp("screenshots"))
return tmp_path_factory.mktemp("screenshots")


@fixture
Expand Down Expand Up @@ -138,11 +139,18 @@ def test_show(wp, assy, sk, patch_vtk):
show(vtkAxesActor(), [vtkAnnotatedCubeActor()])


def test_screenshot(wp, tmpdir, patch_vtk):
def test_screenshot(wp, patch_vtk):

# smoke test for now
with tmpdir:
show(wp, interact=False, screenshot="img.png", trihedron=False, gradient=False)


@mark.skip(reason="running only smoke test for now")
def test_screenshot_no_patch(wp, tmpdir, cwd):

with cwd(tmpdir):
show(wp, interact=False, screenshot="img.png", trihedron=False, gradient=False)
assert (Path(tmpdir) / "img.png").exists()


def test_ctrlPts():
Expand Down