diff --git a/cadquery/occ_impl/importers/assembly.py b/cadquery/occ_impl/importers/assembly.py index 4126c0ad1..28de735d1 100644 --- a/cadquery/occ_impl/importers/assembly.py +++ b/cadquery/occ_impl/importers/assembly.py @@ -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 @@ -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( @@ -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( diff --git a/environment.yml b/environment.yml index 590179b13..e6941c852 100644 --- a/environment.yml +++ b/environment.yml @@ -16,7 +16,6 @@ dependencies: - ezdxf>=1.3.0 - typing_extensions - nlopt - - path - casadi - runtype - multimethod >=1.11,<2.0 diff --git a/setup.py b/setup.py index 2bcbf98fd..c9f082d64 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,6 @@ "nlopt>=2.9.0,<3.0", "runtype", "casadi", - "path", "trame", "trame-vtk", "trame-components", diff --git a/tests/conftest.py b/tests/conftest.py index d30b369de..705e6f106 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,6 @@ import pytest +import os +from contextlib import contextmanager def pytest_addoption(parser): @@ -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 diff --git a/tests/test_assembly.py b/tests/test_assembly.py index 2b0b3180d..2fd46421e 100644 --- a/tests/test_assembly.py +++ b/tests/test_assembly.py @@ -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 @@ -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 @@ -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 = [] @@ -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 @@ -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") @@ -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) @@ -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) diff --git a/tests/test_examples.py b/tests/test_examples.py index 6f022484e..13ede3213 100755 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -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 @@ -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): @@ -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 diff --git a/tests/test_exporters.py b/tests/test_exporters.py index c769d124b..055d7698a 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -4,7 +4,7 @@ # core modules import os import io -from path import Path +from pathlib import Path import re import sys import math diff --git a/tests/test_vis.py b/tests/test_vis.py index a29da7aaf..695e530de 100644 --- a/tests/test_vis.py +++ b/tests/test_vis.py @@ -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 @@ -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():