Skip to content

Commit

Permalink
Merge pull request #138 from wright-group/rename
Browse files Browse the repository at this point in the history
Add rename transition
  • Loading branch information
kameyer226 authored Jul 19, 2021
2 parents 8742046 + 17a876c commit 582f228
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions attune/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ._note import *
from ._offset import *
from ._open import *
from ._rename import *
from ._setpoint import *
from ._store import *
from ._tune import *
Expand Down
16 changes: 16 additions & 0 deletions attune/_rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__all__ = ["rename"]

from ._transition import Transition, TransitionType
from ._instrument import Instrument


def rename(instr: Instrument, name: str):
"""Rename an instrument.
Note: this tranistion breaks the history, as the primary key changes.
"""
trans = Transition(TransitionType.rename, metadata={"old_name": instr.name})
new_instr = instr.as_dict()
new_instr["transition"] = trans
new_instr["name"] = name
return Instrument(**new_instr)
1 change: 1 addition & 0 deletions attune/_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TransitionType(str, Enum):
create = "create"
read = "read"
restore = "restore"
rename = "rename"
offset_to = "offset_to"
offset_by = "offset_by"
map_limits = "map_limits"
Expand Down
27 changes: 0 additions & 27 deletions tests/Curve/rename.py

This file was deleted.

8 changes: 8 additions & 0 deletions tests/rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import attune


def test_rename():
i = attune.Instrument({}, name="old")
new = attune.rename(i, "new")
assert new.name == "new"
assert new.transition.metadata["old_name"] == "old"

0 comments on commit 582f228

Please sign in to comment.