diff --git a/src/compas/datastructures/mesh/duality.py b/src/compas/datastructures/mesh/duality.py index 9c133a90cd2..985aebda0bc 100644 --- a/src/compas/datastructures/mesh/duality.py +++ b/src/compas/datastructures/mesh/duality.py @@ -4,7 +4,7 @@ from math import pi -from compas.utilities import flatten +from compas.itertools import flatten PI2 = 2.0 * pi diff --git a/src/compas/datastructures/mesh/mesh.py b/src/compas/datastructures/mesh/mesh.py index bb13df6c6f3..4074c7cef77 100644 --- a/src/compas/datastructures/mesh/mesh.py +++ b/src/compas/datastructures/mesh/mesh.py @@ -57,7 +57,7 @@ from compas.topology import breadth_first_traverse from compas.topology import connected_components from compas.topology import unify_cycles -from compas.utilities import window +from compas.itertools import window from .duality import mesh_dual from .operations.collapse import mesh_collapse_edge diff --git a/src/compas/datastructures/mesh/subdivision.py b/src/compas/datastructures/mesh/subdivision.py index 67dd54399b5..aede8aa49db 100644 --- a/src/compas/datastructures/mesh/subdivision.py +++ b/src/compas/datastructures/mesh/subdivision.py @@ -9,7 +9,7 @@ from compas.geometry import centroid_points from compas.geometry import offset_polygon from compas.itertools import pairwise -from compas.utilities import iterable_like +from compas.itertools import iterable_like def subd_factory(cls): diff --git a/src/compas/geometry/_core/predicates_3.py b/src/compas/geometry/_core/predicates_3.py index eedb2d6ae84..7f0c244bc1f 100644 --- a/src/compas/geometry/_core/predicates_3.py +++ b/src/compas/geometry/_core/predicates_3.py @@ -14,7 +14,7 @@ from compas.geometry import normal_polygon from compas.geometry import subtract_vectors from compas.tolerance import TOL -from compas.utilities import window +from compas.itertools import window # ============================================================================= # ============================================================================= diff --git a/src/compas/geometry/interpolation_coons.py b/src/compas/geometry/interpolation_coons.py index 537d1665155..3e69fab28f2 100644 --- a/src/compas/geometry/interpolation_coons.py +++ b/src/compas/geometry/interpolation_coons.py @@ -6,7 +6,7 @@ from compas.geometry import scale_vector from compas.geometry import subtract_vectors from compas.geometry import sum_vectors -from compas.utilities import normalize_values +from compas.itertools import normalize_values def discrete_coons_patch(ab, bc, dc, ad): diff --git a/src/compas/geometry/offset.py b/src/compas/geometry/offset.py index bd8c5ba4fb0..244ba55ee46 100644 --- a/src/compas/geometry/offset.py +++ b/src/compas/geometry/offset.py @@ -13,7 +13,7 @@ from compas.geometry import scale_vector from compas.geometry import subtract_vectors from compas.itertools import pairwise -from compas.utilities import iterable_like +from compas.itertools import iterable_like def intersect_lines(l1, l2, tol): diff --git a/src/compas/geometry/projection.py b/src/compas/geometry/projection.py index 36b68a5e6c4..041759c9cc2 100644 --- a/src/compas/geometry/projection.py +++ b/src/compas/geometry/projection.py @@ -18,7 +18,7 @@ from compas.geometry import matrix_from_perspective_entries from compas.geometry import matrix_from_perspective_projection from compas.tolerance import TOL -from compas.utilities import flatten +from compas.itertools import flatten class Projection(Transformation): diff --git a/src/compas/geometry/quadmesh_planarize_none.py b/src/compas/geometry/quadmesh_planarize_none.py index a1e9e893e47..92487087aa3 100644 --- a/src/compas/geometry/quadmesh_planarize_none.py +++ b/src/compas/geometry/quadmesh_planarize_none.py @@ -9,7 +9,7 @@ from compas.geometry import midpoint_point_point from compas.geometry import project_points_plane from compas.itertools import pairwise -from compas.utilities import window +from compas.itertools import window def mesh_flatness(mesh, maxdev=1.0): diff --git a/src/compas/geometry/reflection.py b/src/compas/geometry/reflection.py index 3ee71118547..c2f37d6a5ee 100644 --- a/src/compas/geometry/reflection.py +++ b/src/compas/geometry/reflection.py @@ -19,7 +19,7 @@ from compas.geometry import matrix_from_perspective_entries from compas.geometry import normalize_vector from compas.tolerance import TOL -from compas.utilities import flatten +from compas.itertools import flatten class Reflection(Transformation): diff --git a/src/compas/geometry/rotation.py b/src/compas/geometry/rotation.py index 55f39937a82..fe47af1040c 100644 --- a/src/compas/geometry/rotation.py +++ b/src/compas/geometry/rotation.py @@ -24,7 +24,7 @@ from compas.geometry import matrix_from_quaternion from compas.geometry import normalize_vector from compas.tolerance import TOL -from compas.utilities import flatten +from compas.itertools import flatten class Rotation(Transformation): diff --git a/src/compas/geometry/scale.py b/src/compas/geometry/scale.py index 2e65218ea59..7921056a278 100644 --- a/src/compas/geometry/scale.py +++ b/src/compas/geometry/scale.py @@ -18,7 +18,7 @@ from compas.geometry import matrix_inverse from compas.geometry import multiply_matrices from compas.tolerance import TOL -from compas.utilities import flatten +from compas.itertools import flatten class Scale(Transformation): diff --git a/src/compas/geometry/shear.py b/src/compas/geometry/shear.py index 29fb62e17a2..b6603085657 100644 --- a/src/compas/geometry/shear.py +++ b/src/compas/geometry/shear.py @@ -16,7 +16,7 @@ from compas.geometry import matrix_from_shear from compas.geometry import matrix_from_shear_entries from compas.tolerance import TOL -from compas.utilities import flatten +from compas.itertools import flatten class Shear(Transformation): diff --git a/src/compas/geometry/surfaces/nurbs.py b/src/compas/geometry/surfaces/nurbs.py index 601d220c54a..1784e66a536 100644 --- a/src/compas/geometry/surfaces/nurbs.py +++ b/src/compas/geometry/surfaces/nurbs.py @@ -6,7 +6,7 @@ from compas.itertools import linspace from compas.plugins import PluginNotInstalledError from compas.plugins import pluggable -from compas.utilities import meshgrid +from compas.itertools import meshgrid from .surface import Surface diff --git a/src/compas/geometry/translation.py b/src/compas/geometry/translation.py index 3830cbc7fbf..867fe6b1e02 100644 --- a/src/compas/geometry/translation.py +++ b/src/compas/geometry/translation.py @@ -15,7 +15,7 @@ from compas.geometry import matrix_from_translation from compas.geometry import translation_from_matrix from compas.tolerance import TOL -from compas.utilities import flatten +from compas.itertools import flatten class Translation(Transformation): diff --git a/src/compas/geometry/trimesh_curvature.py b/src/compas/geometry/trimesh_curvature.py index f5b2ed5b3cb..d3f5e7a077b 100644 --- a/src/compas/geometry/trimesh_curvature.py +++ b/src/compas/geometry/trimesh_curvature.py @@ -6,7 +6,7 @@ from compas.geometry import angle_points from compas.plugins import pluggable -from compas.utilities import window +from compas.itertools import window @pluggable(category="trimesh") diff --git a/src/compas/itertools.py b/src/compas/itertools.py index 17464c4fb57..756764679b7 100644 --- a/src/compas/itertools.py +++ b/src/compas/itertools.py @@ -123,7 +123,7 @@ def meshgrid(x, y, indexing="xy"): Examples -------- - >>> from compas.utilities import linspace, meshgrid + >>> from compas.itertools import linspace, meshgrid >>> x = list(linspace(0, 1, 3)) >>> y = list(linspace(0, 1, 2)) @@ -181,7 +181,7 @@ def linspace(start, stop, num=50): Examples -------- - >>> from compas.utilities import linspace + >>> from compas.itertools import linspace >>> list(linspace(0, 1, 3)) [0.0, 0.5, 1.0] diff --git a/src/compas_rhino/conduits/faces.py b/src/compas_rhino/conduits/faces.py index 8937a8bfe48..efe2f9b7dee 100644 --- a/src/compas_rhino/conduits/faces.py +++ b/src/compas_rhino/conduits/faces.py @@ -6,7 +6,7 @@ from System.Drawing.Color import FromArgb from compas.utilities import is_sequence_of_iterable -from compas.utilities import iterable_like +from compas.itertools import iterable_like from .base import BaseConduit diff --git a/src/compas_rhino/conduits/labels.py b/src/compas_rhino/conduits/labels.py index 2a1b8e74a88..773e77541d0 100644 --- a/src/compas_rhino/conduits/labels.py +++ b/src/compas_rhino/conduits/labels.py @@ -6,7 +6,7 @@ from System.Drawing.Color import FromArgb from compas.utilities import is_sequence_of_iterable -from compas.utilities import iterable_like +from compas.itertools import iterable_like from .base import BaseConduit diff --git a/src/compas_rhino/conduits/lines.py b/src/compas_rhino/conduits/lines.py index 7a9917324b0..9098ce39792 100644 --- a/src/compas_rhino/conduits/lines.py +++ b/src/compas_rhino/conduits/lines.py @@ -6,7 +6,7 @@ from System.Drawing.Color import FromArgb from compas.utilities import is_sequence_of_iterable -from compas.utilities import iterable_like +from compas.itertools import iterable_like from .base import BaseConduit diff --git a/src/compas_rhino/conduits/points.py b/src/compas_rhino/conduits/points.py index 3aa2da97121..db75ef1fbb7 100644 --- a/src/compas_rhino/conduits/points.py +++ b/src/compas_rhino/conduits/points.py @@ -7,7 +7,7 @@ from System.Drawing.Color import FromArgb from compas.utilities import color_to_rgb -from compas.utilities import iterable_like +from compas.itertools import iterable_like from compas.utilities.coercing import is_sequence_of_iterable from .base import BaseConduit diff --git a/src/compas_rhino/geometry/surfaces/nurbs.py b/src/compas_rhino/geometry/surfaces/nurbs.py index 8a144f0cdaa..037263cff99 100644 --- a/src/compas_rhino/geometry/surfaces/nurbs.py +++ b/src/compas_rhino/geometry/surfaces/nurbs.py @@ -9,7 +9,7 @@ from compas.geometry import NurbsSurface from compas.geometry import Point from compas.geometry import knots_and_mults_to_knotvector -from compas.utilities import flatten +from compas.itertools import flatten from compas_rhino.conversions import point_to_compas from compas_rhino.conversions import point_to_rhino diff --git a/tests/compas/utilities/test_itertools.py b/tests/compas/test_itertools.py similarity index 94% rename from tests/compas/utilities/test_itertools.py rename to tests/compas/test_itertools.py index 30f7e422da3..844dac3a2ec 100644 --- a/tests/compas/utilities/test_itertools.py +++ b/tests/compas/test_itertools.py @@ -2,9 +2,9 @@ import pytest from compas.datastructures import Mesh -from compas.utilities import iterable_like -from compas.utilities import reshape -from compas.utilities import flatten +from compas.itertools import iterable_like +from compas.itertools import reshape +from compas.itertools import flatten from compas.tolerance import TOL diff --git a/tests/compas/utilities/test_async_.py b/tests/compas/utilities/test_async_.py deleted file mode 100644 index d4abfebcba4..00000000000 --- a/tests/compas/utilities/test_async_.py +++ /dev/null @@ -1,112 +0,0 @@ -from threading import Thread - -from compas.utilities import await_callback - -import pytest - - -def test_void_return_callback(): - def async_fn(callback): - def runner(cb): - cb() - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result is None - - -def test_single_positional_arg_callback(): - def async_fn(callback): - def runner(cb): - cb("only_return_value") - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result == "only_return_value" - - -def test_many_positional_args_callback(): - def async_fn(callback): - def runner(cb): - cb(1, 2) - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result == ( - 1, - 2, - ) - - -def test_kwargs_callback(): - def async_fn(callback): - def runner(cb): - cb(name="Austin", last_name="Powers") - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn) - assert result["name"] == "Austin" - assert result["last_name"] == "Powers" - - -def test_one_positional_arg_and_kwargs_callback(): - def async_fn(callback): - def runner(cb): - cb(1, retries=5) - - Thread(target=runner, args=(callback,)).start() - - result, kwargs = await_callback(async_fn) - assert result == 1 - assert kwargs["retries"] == 5 - - -def test_many_positional_args_and_kwargs_callback(): - def async_fn(callback): - def runner(cb): - cb(4, 2, 3, retries=5) - - Thread(target=runner, args=(callback,)).start() - - a, b, c, kw = await_callback(async_fn) - assert a == 4 - assert b == 2 - assert c == 3 - assert kw["retries"] == 5 - - -def test_async_fn_with_more_params(): - def async_fn(values, other_stuff, callback): - def runner(cb): - cb(200) - - Thread(target=runner, args=(callback,)).start() - - result = await_callback(async_fn, values=[1, 2, 3], other_stuff=None) - assert result == 200 - - -def test_captured_exception_in_thread(): - def async_fn(callback): - def runner(cb): - raise ValueError("exception") - - Thread(target=runner, args=(callback,)).start() - - with pytest.raises(ValueError): - await_callback(async_fn) - - -def test_errback(): - def async_fn(callback, errback): - def runner(cb, eb): - eb(ValueError("exception via errback")) - - Thread(target=runner, args=(callback, errback)).start() - - with pytest.raises(ValueError): - await_callback(async_fn, errback_name="errback") diff --git a/tests/compas/utilities/test_itertools_.py b/tests/compas/utilities/test_itertools_.py deleted file mode 100644 index b5026a0d8ac..00000000000 --- a/tests/compas/utilities/test_itertools_.py +++ /dev/null @@ -1,39 +0,0 @@ -import compas -import pytest - -from compas.datastructures import Mesh -from compas.utilities import iterable_like - - -# ============================================================================== -# iterable_like -# ============================================================================== - - -@pytest.mark.parametrize(("target", "base", "fillvalue"), [("hello", [0.5], 0.5)]) -def test_iterable_like_string_and_float(target, base, fillvalue): - a = list(iterable_like(target, base, fillvalue)) - assert a == [0.5, 0.5, 0.5, 0.5, 0.5] - - -@pytest.mark.parametrize( - ("target", "base", "fillvalue"), - [(["foo", "bar", "baz"], {"key_1": "a", "key_2": "b"}, "key_3")], -) -def test_iterable_like_list_and_dict(target, base, fillvalue): - a = list(iterable_like(target, base, fillvalue)) - assert sorted(a) == ["key_1", "key_2", "key_3"] - - -@pytest.mark.parametrize(("target", "base", "fillvalue"), [(range(2), ["a", "b"], 0)]) -def test_iterable_like_generator_and_list(target, base, fillvalue): - a = list(iterable_like(target, base, fillvalue)) - assert a == ["a", "b"] - - -@pytest.mark.parametrize(("mesh_a", "mesh_b"), [("faces.obj", "hypar.obj"), ("hypar.obj", "faces.obj")]) -def test_iterable_cap_generator(mesh_a, mesh_b): - ma = Mesh.from_obj(compas.get(mesh_a)) - mb = Mesh.from_obj(compas.get(mesh_b)) - a = list(iterable_like(ma.faces(), mb.faces())) - assert len(a) == len(list(ma.faces()))