Skip to content

Commit

Permalink
Re-add ClampExistsError
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBangar committed Jun 4, 2024
1 parent 33fd3b4 commit 8f8e043
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/classy_blocks/modify/junction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from classy_blocks.modify.clamps.clamp import ClampBase


class ClampExistsError(Exception):
"""Raised when adding a clamp to a junction that already has one defined"""


class Junction:
"""A class that collects Cells/Blocks that
share the same Vertex"""
Expand All @@ -24,6 +28,9 @@ def add_cell(self, cell: Cell) -> None:
return

def add_clamp(self, clamp: ClampBase) -> None:
if self.clamp is not None:
raise ClampExistsError(f"Clamp already defined for junctoin {self.vertex.index}")

self.clamp = clamp

@property
Expand Down
7 changes: 7 additions & 0 deletions tests/test_optimize/test_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from classy_blocks.modify.clamps.links import TranslationLink
from classy_blocks.modify.find.geometric import GeometricFinder
from classy_blocks.modify.iteration import IterationDriver
from classy_blocks.modify.junction import ClampExistsError
from classy_blocks.modify.optimizer import Optimizer
from classy_blocks.util import functions as f
from classy_blocks.util.constants import VBIG
Expand Down Expand Up @@ -132,6 +133,12 @@ def setUp(self):

self.vertex = next(iter(self.finder.find_in_sphere([0, 0, 0])))

def test_add_junction_existing(self):
self.optimizer.release_vertex(FreeClamp(self.mesh.vertices[0]))

with self.assertRaises(ClampExistsError):
self.optimizer.release_vertex(FreeClamp(self.mesh.vertices[0]))

def test_optimize(self):
# move a point, then optimize it back to
# its initial-ish position
Expand Down

0 comments on commit 8f8e043

Please sign in to comment.