Skip to content

Commit

Permalink
update test and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Licini committed Nov 13, 2023
1 parent 154a815 commit d737cb3
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 115 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `Frame.axes`
* Added `compas.datastructures.TreeNode` and `compas.datastructures.Tree` classes.
* Added `EllipseArtist` to `compas_rhino` and `compas_ghpython`.
* Added `compas.scene.Scene`.

### Changed

Expand All @@ -34,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Moved `compas.geometry.brep` to `compas.brep`.
* Changed `networkx` version to `>=3.0` to ensure support for `is_planar`.
* Moved `compas.geometry.curves.nurbs_.py` and `compas.geometry.surfaces.nurbs_.py` to `compas_nurbs`.
* ARTISTS ARE NOW SCENEOBJECTS (TO BE FURTHER DETAILED BEFORE MERGE).

### Removed

Expand Down
8 changes: 4 additions & 4 deletions src/compas/datastructures/tree/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,11 @@ def __repr__(self):
def print_hierarchy(self):
"""Print the spatial hierarchy of the tree."""

def _print(node, prefix='', last=True):
connector = '└── ' if last else '├── '
def _print(node, prefix="", last=True):
connector = "└── " if last else "├── "
print("{}{}{}".format(prefix, connector, node))
prefix += ' ' if last else ''
prefix += " " if last else ""
for i, child in enumerate(node.children):
_print(child, prefix, i == len(node.children) - 1)

_print(self.root)
_print(self.root)
2 changes: 1 addition & 1 deletion src/compas/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def redraw(self):

if sceneobject:
sceneobject.redraw()

return drawn_objects

def print_hierarchy(self):
Expand Down
110 changes: 0 additions & 110 deletions tests/compas/artists/test_artists.py

This file was deleted.

110 changes: 110 additions & 0 deletions tests/compas/scene/test_scene.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import pytest # noqa: F401

import compas
from compas.scene import SceneObject
from compas.scene import NoSceneObjectContextError


if not compas.IPY:

@pytest.fixture(autouse=True)
def reset_sceneobjects():
# before each test
yield
# after each test, reset sceneobjects
SceneObject.ITEM_SCENEOBJECT.clear()
SceneObject._SceneObject__SCENEOBJECTS_REGISTERED = False # type: ignore


def register_fake_context():
SceneObject.register(FakeItem, FakeSceneObject, context="fake")


class FakeSceneObject(SceneObject):
def draw(self):
pass


class FakeSubSceneObject(SceneObject):
def draw(self):
pass


class FakeItem(object):
pass


class FakeSubItem(FakeItem):
pass


def test_get_sceneobject_cls_with_orderly_registration():
SceneObject.register(FakeItem, FakeSceneObject, context="fake")
SceneObject.register(FakeSubItem, FakeSubSceneObject, context="fake")
item = FakeItem()
sceneobject = SceneObject(item, context="fake")
assert isinstance(sceneobject, FakeSceneObject)

item = FakeSubItem()
sceneobject = SceneObject(item, context="fake")
assert isinstance(sceneobject, FakeSubSceneObject)


def test_get_sceneobject_cls_with_out_of_order_registration():
SceneObject.register(FakeSubItem, FakeSubSceneObject, context="fake")
SceneObject.register(FakeItem, FakeSceneObject, context="fake")
item = FakeItem()
sceneobject = SceneObject(item, context="fake")
assert isinstance(sceneobject, FakeSceneObject)

item = FakeSubItem()
sceneobject = SceneObject(item, context="fake")
assert isinstance(sceneobject, FakeSubSceneObject)


if not compas.IPY:

def test_sceneobject_auto_context_discovery(mocker):
mocker.patch("compas.scene.SceneObject.register_sceneobjects")
SceneObject.register_sceneobjects.side_effect = register_fake_context
SceneObject._SceneObject__SCENEOBJECTS_REGISTERED = False # type: ignore

item = FakeItem()
sceneobject = SceneObject(item)

assert isinstance(sceneobject, FakeSceneObject)

def test_sceneobject_auto_context_discovery_viewer(mocker):
mocker.patch("compas.scene.sceneobject.is_viewer_open", return_value=True)
SceneObject.ITEM_SCENEOBJECT["Viewer"] = {FakeItem: FakeSceneObject}

item = FakeSubItem()
sceneobject = SceneObject(item)

assert isinstance(sceneobject, FakeSceneObject)

def test_sceneobject_auto_context_discovery_viewer_priority(mocker):
mocker.patch("compas.scene.sceneobject.is_viewer_open", return_value=True)

class FakeViewerSceneObject(FakeSceneObject):
pass

class FakePlotterSceneObject(FakeSceneObject):
pass

SceneObject.ITEM_SCENEOBJECT["Viewer"] = {FakeItem: FakeViewerSceneObject}
SceneObject.ITEM_SCENEOBJECT["Plotter"] = {FakeItem: FakePlotterSceneObject}

item = FakeSubItem()
sceneobject = SceneObject(item)

assert isinstance(sceneobject, FakeViewerSceneObject)

def test_sceneobject_auto_context_discovery_no_context(mocker):
mocker.patch("compas.scene.sceneobject.is_viewer_open", return_value=False)
mocker.patch("compas.scene.sceneobject.compas.is_grasshopper", return_value=False)
mocker.patch("compas.scene.sceneobject.compas.is_rhino", return_value=False)

with pytest.raises(NoSceneObjectContextError):
item = FakeSubItem()
_ = SceneObject(item)

0 comments on commit d737cb3

Please sign in to comment.