Skip to content

Commit

Permalink
Rename Serializable.register to register_subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
c-mita committed Jul 12, 2016
1 parent 497fc11 commit 67b9e07
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion malcolm/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Need to import these so that the register hooks are called
# Need to import these so that the register_subclass hooks are called
from malcolm.core.stringmeta import StringMeta # noqa
from malcolm.core.stringarraymeta import StringArrayMeta # noqa
from malcolm.core.numbermeta import NumberMeta # noqa
Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("epics:nt/NTAttribute:1.0")
@Serializable.register_subclass("epics:nt/NTAttribute:1.0")
class Attribute(Notifier):
"""Represents a value with type information that may be backed elsewhere"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __exit__(self, type, value, traceback):
self.lock.acquire()
return False

@Serializable.register("malcolm:core/Block:1.0")
@Serializable.register_subclass("malcolm:core/Block:1.0")
class Block(Notifier):
"""Object consisting of a number of Attributes and Methods"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/blockmeta.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from malcolm.core.meta import Meta
from malcolm.core.serializable import Serializable

@Serializable.register("malcolm:core/BlockMeta:1.0")
@Serializable.register_subclass("malcolm:core/BlockMeta:1.0")
class BlockMeta(Meta):
pass
2 changes: 1 addition & 1 deletion malcolm/core/booleanarraymeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("malcolm:core/BooleanArrayMeta:1.0")
@Serializable.register_subclass("malcolm:core/BooleanArrayMeta:1.0")
class BooleanArrayMeta(ScalarMeta):
"""Meta object containing information for a boolean array"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/booleanmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("malcolm:core/BooleanMeta:1.0")
@Serializable.register_subclass("malcolm:core/BooleanMeta:1.0")
class BooleanMeta(ScalarMeta):
"""Meta object containing information for a boolean"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/choicearraymeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("malcolm:core/ChoiceArrayMeta:1.0")
@Serializable.register_subclass("malcolm:core/ChoiceArrayMeta:1.0")
class ChoiceArrayMeta(ScalarMeta):
"""Meta object containing information for a choice array"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/choicemeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("malcolm:core/ChoiceMeta:1.0")
@Serializable.register_subclass("malcolm:core/ChoiceMeta:1.0")
class ChoiceMeta(ScalarMeta):
"""Meta object containing information for a enum"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/mapmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
REQUIRED = object()


@Serializable.register("malcolm:core/MapMeta:1.0")
@Serializable.register_subclass("malcolm:core/MapMeta:1.0")
class MapMeta(Notifier):
"""An object containing a set of ScalarMeta objects"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from malcolm.core.map import Map


@Serializable.register("malcolm:core/Method:1.0")
@Serializable.register_subclass("malcolm:core/Method:1.0")
class Method(Notifier):
"""Exposes a function with metadata for arguments and return values"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/numberarraymeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from malcolm.compat import base_string


@Serializable.register("malcolm:core/NumberArrayMeta:1.0")
@Serializable.register_subclass("malcolm:core/NumberArrayMeta:1.0")
class NumberArrayMeta(ScalarMeta):
"""Meta object containing information for an array of numerical values"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/numbermeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from malcolm.compat import base_string


@Serializable.register("malcolm:core/NumberMeta:1.0")
@Serializable.register_subclass("malcolm:core/NumberMeta:1.0")
class NumberMeta(ScalarMeta):
"""Meta object containing information for a numerical value"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/pointgeneratormeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from scanpointgenerator import CompoundGenerator


@Serializable.register("malcolm:core/PointGeneratorMeta:1.0")
@Serializable.register_subclass("malcolm:core/PointGeneratorMeta:1.0")
class PointGeneratorMeta(ScalarMeta):

def __init__(self, name, description):
Expand Down
4 changes: 2 additions & 2 deletions malcolm/core/serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Serializable(object):
"""Mixin class for serializable objects"""

# This will be set by subclasses calling cls.register()
# This will be set by subclasses calling cls.register_subclass()
typeid = None
endpoints = None
# dict mapping typeid name -> cls
Expand Down Expand Up @@ -63,7 +63,7 @@ def deserialize(cls, name, d):
return subcls.from_dict(name, d)

@classmethod
def register(cls, typeid):
def register_subclass(cls, typeid):
"""Register a subclass so from_dict() works
Args:
Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/stringarraymeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("malcolm:core/StringArrayMeta:1.0")
@Serializable.register_subclass("malcolm:core/StringArrayMeta:1.0")
class StringArrayMeta(ScalarMeta):
"""Meta object containing information for a string array"""

Expand Down
2 changes: 1 addition & 1 deletion malcolm/core/stringmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from malcolm.core.serializable import Serializable


@Serializable.register("malcolm:core/StringMeta:1.0")
@Serializable.register_subclass("malcolm:core/StringMeta:1.0")
class StringMeta(ScalarMeta):
"""Meta object containing information for a string"""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from malcolm.core.meta import Meta
from malcolm.core.serializable import Serializable

Serializable.register("meta:test")(Meta)
Serializable.register_subclass("meta:test")(Meta)

class TestMeta(unittest.TestCase):
def test_init(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from malcolm.core.serializable import Serializable


Serializable.register("notifier:test")(Notifier)
Serializable.register_subclass("notifier:test")(Notifier)

class TestInit(unittest.TestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/test_core/test_scalarmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Register ScalarMeta as a sublcass of itself so we
# can instantiate it for testing purposes.
ScalarMeta.register("scalarmeta:test")(ScalarMeta)
ScalarMeta.register_subclass("scalarmeta:test")(ScalarMeta)

class TestInit(unittest.TestCase):

Expand Down
10 changes: 5 additions & 5 deletions tests/test_core/test_serializable.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

# Register Serializable as a sublcass of itself so we
# can instantiate it for testing purposes.
Serializable.register("serializable:test")(Serializable)
Serializable.register_subclass("serializable:test")(Serializable)


class TestSerialization(unittest.TestCase):

def test_to_dict(self):

@Serializable.register("foo:1.0")
@Serializable.register_subclass("foo:1.0")
class DummySerializable(Serializable):
from_dict = Mock()

Expand All @@ -26,7 +26,7 @@ class DummySerializable(Serializable):

def test_base_deserialize_calls_from_dict(self):

@Serializable.register("foo:1.0")
@Serializable.register_subclass("foo:1.0")
class DummySerializable(Serializable):
from_dict = Mock()

Expand All @@ -39,7 +39,7 @@ class DummySerializable(Serializable):

def test_from_dict_calls_update(self):

@Serializable.register("foo:1.0")
@Serializable.register_subclass("foo:1.0")
class DummySerializable(Serializable):
update = Mock()

Expand All @@ -52,7 +52,7 @@ class DummySerializable(Serializable):

def test_update_calls_set(self):

@Serializable.register("foo:1.0")
@Serializable.register_subclass("foo:1.0")
class DummySerializable(Serializable):
set_value = Mock()

Expand Down

0 comments on commit 67b9e07

Please sign in to comment.